diff options
Diffstat (limited to 'kernel/trace/trace_events.c')
-rw-r--r-- | kernel/trace/trace_events.c | 121 |
1 files changed, 120 insertions, 1 deletions
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 0d2e47370ee7..7da1dfeb322e 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c | |||
@@ -1704,6 +1704,125 @@ __register_event(struct ftrace_event_call *call, struct module *mod) | |||
1704 | return 0; | 1704 | return 0; |
1705 | } | 1705 | } |
1706 | 1706 | ||
1707 | static char *enum_replace(char *ptr, struct trace_enum_map *map, int len) | ||
1708 | { | ||
1709 | int rlen; | ||
1710 | int elen; | ||
1711 | |||
1712 | /* Find the length of the enum value as a string */ | ||
1713 | elen = snprintf(ptr, 0, "%ld", map->enum_value); | ||
1714 | /* Make sure there's enough room to replace the string with the value */ | ||
1715 | if (len < elen) | ||
1716 | return NULL; | ||
1717 | |||
1718 | snprintf(ptr, elen + 1, "%ld", map->enum_value); | ||
1719 | |||
1720 | /* Get the rest of the string of ptr */ | ||
1721 | rlen = strlen(ptr + len); | ||
1722 | memmove(ptr + elen, ptr + len, rlen); | ||
1723 | /* Make sure we end the new string */ | ||
1724 | ptr[elen + rlen] = 0; | ||
1725 | |||
1726 | return ptr + elen; | ||
1727 | } | ||
1728 | |||
1729 | static void update_event_printk(struct ftrace_event_call *call, | ||
1730 | struct trace_enum_map *map) | ||
1731 | { | ||
1732 | char *ptr; | ||
1733 | int quote = 0; | ||
1734 | int len = strlen(map->enum_string); | ||
1735 | |||
1736 | for (ptr = call->print_fmt; *ptr; ptr++) { | ||
1737 | if (*ptr == '\\') { | ||
1738 | ptr++; | ||
1739 | /* paranoid */ | ||
1740 | if (!*ptr) | ||
1741 | break; | ||
1742 | continue; | ||
1743 | } | ||
1744 | if (*ptr == '"') { | ||
1745 | quote ^= 1; | ||
1746 | continue; | ||
1747 | } | ||
1748 | if (quote) | ||
1749 | continue; | ||
1750 | if (isdigit(*ptr)) { | ||
1751 | /* skip numbers */ | ||
1752 | do { | ||
1753 | ptr++; | ||
1754 | /* Check for alpha chars like ULL */ | ||
1755 | } while (isalnum(*ptr)); | ||
1756 | /* | ||
1757 | * A number must have some kind of delimiter after | ||
1758 | * it, and we can ignore that too. | ||
1759 | */ | ||
1760 | continue; | ||
1761 | } | ||
1762 | if (isalpha(*ptr) || *ptr == '_') { | ||
1763 | if (strncmp(map->enum_string, ptr, len) == 0 && | ||
1764 | !isalnum(ptr[len]) && ptr[len] != '_') { | ||
1765 | ptr = enum_replace(ptr, map, len); | ||
1766 | /* Hmm, enum string smaller than value */ | ||
1767 | if (WARN_ON_ONCE(!ptr)) | ||
1768 | return; | ||
1769 | /* | ||
1770 | * No need to decrement here, as enum_replace() | ||
1771 | * returns the pointer to the character passed | ||
1772 | * the enum, and two enums can not be placed | ||
1773 | * back to back without something in between. | ||
1774 | * We can skip that something in between. | ||
1775 | */ | ||
1776 | continue; | ||
1777 | } | ||
1778 | skip_more: | ||
1779 | do { | ||
1780 | ptr++; | ||
1781 | } while (isalnum(*ptr) || *ptr == '_'); | ||
1782 | /* | ||
1783 | * If what comes after this variable is a '.' or | ||
1784 | * '->' then we can continue to ignore that string. | ||
1785 | */ | ||
1786 | if (*ptr == '.' || (ptr[0] == '-' && ptr[1] == '>')) { | ||
1787 | ptr += *ptr == '.' ? 1 : 2; | ||
1788 | goto skip_more; | ||
1789 | } | ||
1790 | /* | ||
1791 | * Once again, we can skip the delimiter that came | ||
1792 | * after the string. | ||
1793 | */ | ||
1794 | continue; | ||
1795 | } | ||
1796 | } | ||
1797 | } | ||
1798 | |||
1799 | void trace_event_enum_update(struct trace_enum_map **map, int len) | ||
1800 | { | ||
1801 | struct ftrace_event_call *call, *p; | ||
1802 | const char *last_system = NULL; | ||
1803 | int last_i; | ||
1804 | int i; | ||
1805 | |||
1806 | down_write(&trace_event_sem); | ||
1807 | list_for_each_entry_safe(call, p, &ftrace_events, list) { | ||
1808 | /* events are usually grouped together with systems */ | ||
1809 | if (!last_system || call->class->system != last_system) { | ||
1810 | last_i = 0; | ||
1811 | last_system = call->class->system; | ||
1812 | } | ||
1813 | |||
1814 | for (i = last_i; i < len; i++) { | ||
1815 | if (call->class->system == map[i]->system) { | ||
1816 | /* Save the first system if need be */ | ||
1817 | if (!last_i) | ||
1818 | last_i = i; | ||
1819 | update_event_printk(call, map[i]); | ||
1820 | } | ||
1821 | } | ||
1822 | } | ||
1823 | up_write(&trace_event_sem); | ||
1824 | } | ||
1825 | |||
1707 | static struct ftrace_event_file * | 1826 | static struct ftrace_event_file * |
1708 | trace_create_new_event(struct ftrace_event_call *call, | 1827 | trace_create_new_event(struct ftrace_event_call *call, |
1709 | struct trace_array *tr) | 1828 | struct trace_array *tr) |
@@ -1915,7 +2034,7 @@ static int trace_module_notify(struct notifier_block *self, | |||
1915 | 2034 | ||
1916 | static struct notifier_block trace_module_nb = { | 2035 | static struct notifier_block trace_module_nb = { |
1917 | .notifier_call = trace_module_notify, | 2036 | .notifier_call = trace_module_notify, |
1918 | .priority = 0, | 2037 | .priority = 1, /* higher than trace.c module notify */ |
1919 | }; | 2038 | }; |
1920 | #endif /* CONFIG_MODULES */ | 2039 | #endif /* CONFIG_MODULES */ |
1921 | 2040 | ||