probe-event.c (2f2fde927243bde5fd106da692efef34be12f81c) probe-event.c (4eced2347c447c9409877368fc52478c356b4767)
1/*
2 * probe-event.c : perf-probe definition to probe_events format converter
3 *
4 * Written by Masami Hiramatsu <mhiramat@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 259 unchanged lines hidden (view full) ---

268 free(tmp);
269
270 return ret;
271}
272
273/* Try to find perf_probe_event with debuginfo */
274static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
275 struct probe_trace_event **tevs,
1/*
2 * probe-event.c : perf-probe definition to probe_events format converter
3 *
4 * Written by Masami Hiramatsu <mhiramat@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 259 unchanged lines hidden (view full) ---

268 free(tmp);
269
270 return ret;
271}
272
273/* Try to find perf_probe_event with debuginfo */
274static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
275 struct probe_trace_event **tevs,
276 int max_tevs, const char *module)
276 int max_tevs, const char *target)
277{
278 bool need_dwarf = perf_probe_event_need_dwarf(pev);
277{
278 bool need_dwarf = perf_probe_event_need_dwarf(pev);
279 struct debuginfo *dinfo = open_debuginfo(module);
279 struct debuginfo *dinfo = open_debuginfo(target);
280 int ntevs, ret = 0;
281
282 if (!dinfo) {
283 if (need_dwarf) {
284 pr_warning("Failed to open debuginfo file.\n");
285 return -ENOENT;
286 }
287 pr_debug("Could not open debuginfo. Try to use symbols.\n");
288 return 0;
289 }
290
291 /* Searching trace events corresponding to a probe event */
292 ntevs = debuginfo__find_trace_events(dinfo, pev, tevs, max_tevs);
293
294 debuginfo__delete(dinfo);
295
296 if (ntevs > 0) { /* Succeeded to find trace events */
297 pr_debug("find %d probe_trace_events.\n", ntevs);
280 int ntevs, ret = 0;
281
282 if (!dinfo) {
283 if (need_dwarf) {
284 pr_warning("Failed to open debuginfo file.\n");
285 return -ENOENT;
286 }
287 pr_debug("Could not open debuginfo. Try to use symbols.\n");
288 return 0;
289 }
290
291 /* Searching trace events corresponding to a probe event */
292 ntevs = debuginfo__find_trace_events(dinfo, pev, tevs, max_tevs);
293
294 debuginfo__delete(dinfo);
295
296 if (ntevs > 0) { /* Succeeded to find trace events */
297 pr_debug("find %d probe_trace_events.\n", ntevs);
298 if (module)
298 if (target)
299 ret = add_module_to_probe_trace_events(*tevs, ntevs,
299 ret = add_module_to_probe_trace_events(*tevs, ntevs,
300 module);
300 target);
301 return ret < 0 ? ret : ntevs;
302 }
303
304 if (ntevs == 0) { /* No error but failed to find probe point. */
305 pr_warning("Probe point '%s' not found.\n",
306 synthesize_perf_probe_point(&pev->point));
307 return -ENOENT;
308 }

--- 1415 unchanged lines hidden (view full) ---

1724 /* Get current event names */
1725 namelist = get_probe_trace_event_names(fd, false);
1726 if (!namelist) {
1727 pr_debug("Failed to get current event list.\n");
1728 return -EIO;
1729 }
1730
1731 ret = 0;
301 return ret < 0 ? ret : ntevs;
302 }
303
304 if (ntevs == 0) { /* No error but failed to find probe point. */
305 pr_warning("Probe point '%s' not found.\n",
306 synthesize_perf_probe_point(&pev->point));
307 return -ENOENT;
308 }

--- 1415 unchanged lines hidden (view full) ---

1724 /* Get current event names */
1725 namelist = get_probe_trace_event_names(fd, false);
1726 if (!namelist) {
1727 pr_debug("Failed to get current event list.\n");
1728 return -EIO;
1729 }
1730
1731 ret = 0;
1732 printf("Add new event%s\n", (ntevs > 1) ? "s:" : ":");
1732 printf("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
1733 for (i = 0; i < ntevs; i++) {
1734 tev = &tevs[i];
1735 if (pev->event)
1736 event = pev->event;
1737 else
1738 if (pev->point.function)
1739 event = pev->point.function;
1740 else

--- 38 unchanged lines hidden (view full) ---

1779 * there might be several addresses corresponding to
1780 * one code line.
1781 */
1782 allow_suffix = true;
1783 }
1784
1785 if (ret >= 0) {
1786 /* Show how to use the event. */
1733 for (i = 0; i < ntevs; i++) {
1734 tev = &tevs[i];
1735 if (pev->event)
1736 event = pev->event;
1737 else
1738 if (pev->point.function)
1739 event = pev->point.function;
1740 else

--- 38 unchanged lines hidden (view full) ---

1779 * there might be several addresses corresponding to
1780 * one code line.
1781 */
1782 allow_suffix = true;
1783 }
1784
1785 if (ret >= 0) {
1786 /* Show how to use the event. */
1787 printf("\nYou can now use it on all perf tools, such as:\n\n");
1787 printf("\nYou can now use it in all perf tools, such as:\n\n");
1788 printf("\tperf record -e %s:%s -aR sleep 1\n\n", tev->group,
1789 tev->event);
1790 }
1791
1792 strlist__delete(namelist);
1793 close(fd);
1794 return ret;
1795}
1796
1797static int convert_to_probe_trace_events(struct perf_probe_event *pev,
1798 struct probe_trace_event **tevs,
1788 printf("\tperf record -e %s:%s -aR sleep 1\n\n", tev->group,
1789 tev->event);
1790 }
1791
1792 strlist__delete(namelist);
1793 close(fd);
1794 return ret;
1795}
1796
1797static int convert_to_probe_trace_events(struct perf_probe_event *pev,
1798 struct probe_trace_event **tevs,
1799 int max_tevs, const char *module)
1799 int max_tevs, const char *target)
1800{
1801 struct symbol *sym;
1802 int ret = 0, i;
1803 struct probe_trace_event *tev;
1804
1805 /* Convert perf_probe_event with debuginfo */
1800{
1801 struct symbol *sym;
1802 int ret = 0, i;
1803 struct probe_trace_event *tev;
1804
1805 /* Convert perf_probe_event with debuginfo */
1806 ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, module);
1806 ret = try_to_find_probe_trace_events(pev, tevs, max_tevs, target);
1807 if (ret != 0)
1808 return ret; /* Found in debuginfo or got an error */
1809
1810 /* Allocate trace event buffer */
1811 tev = *tevs = zalloc(sizeof(struct probe_trace_event));
1812 if (tev == NULL)
1813 return -ENOMEM;
1814
1815 /* Copy parameters */
1816 tev->point.symbol = strdup(pev->point.function);
1817 if (tev->point.symbol == NULL) {
1818 ret = -ENOMEM;
1819 goto error;
1820 }
1821
1807 if (ret != 0)
1808 return ret; /* Found in debuginfo or got an error */
1809
1810 /* Allocate trace event buffer */
1811 tev = *tevs = zalloc(sizeof(struct probe_trace_event));
1812 if (tev == NULL)
1813 return -ENOMEM;
1814
1815 /* Copy parameters */
1816 tev->point.symbol = strdup(pev->point.function);
1817 if (tev->point.symbol == NULL) {
1818 ret = -ENOMEM;
1819 goto error;
1820 }
1821
1822 if (module) {
1823 tev->point.module = strdup(module);
1822 if (target) {
1823 tev->point.module = strdup(target);
1824 if (tev->point.module == NULL) {
1825 ret = -ENOMEM;
1826 goto error;
1827 }
1828 }
1829
1830 tev->point.offset = pev->point.offset;
1831 tev->point.retprobe = pev->point.retprobe;

--- 47 unchanged lines hidden (view full) ---

1879
1880struct __event_package {
1881 struct perf_probe_event *pev;
1882 struct probe_trace_event *tevs;
1883 int ntevs;
1884};
1885
1886int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
1824 if (tev->point.module == NULL) {
1825 ret = -ENOMEM;
1826 goto error;
1827 }
1828 }
1829
1830 tev->point.offset = pev->point.offset;
1831 tev->point.retprobe = pev->point.retprobe;

--- 47 unchanged lines hidden (view full) ---

1879
1880struct __event_package {
1881 struct perf_probe_event *pev;
1882 struct probe_trace_event *tevs;
1883 int ntevs;
1884};
1885
1886int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
1887 int max_tevs, const char *module, bool force_add)
1887 int max_tevs, const char *target, bool force_add)
1888{
1889 int i, j, ret;
1890 struct __event_package *pkgs;
1891
1892 pkgs = zalloc(sizeof(struct __event_package) * npevs);
1893 if (pkgs == NULL)
1894 return -ENOMEM;
1895

--- 6 unchanged lines hidden (view full) ---

1902
1903 /* Loop 1: convert all events */
1904 for (i = 0; i < npevs; i++) {
1905 pkgs[i].pev = &pevs[i];
1906 /* Convert with or without debuginfo */
1907 ret = convert_to_probe_trace_events(pkgs[i].pev,
1908 &pkgs[i].tevs,
1909 max_tevs,
1888{
1889 int i, j, ret;
1890 struct __event_package *pkgs;
1891
1892 pkgs = zalloc(sizeof(struct __event_package) * npevs);
1893 if (pkgs == NULL)
1894 return -ENOMEM;
1895

--- 6 unchanged lines hidden (view full) ---

1902
1903 /* Loop 1: convert all events */
1904 for (i = 0; i < npevs; i++) {
1905 pkgs[i].pev = &pevs[i];
1906 /* Convert with or without debuginfo */
1907 ret = convert_to_probe_trace_events(pkgs[i].pev,
1908 &pkgs[i].tevs,
1909 max_tevs,
1910 module);
1910 target);
1911 if (ret < 0)
1912 goto end;
1913 pkgs[i].ntevs = ret;
1914 }
1915
1916 /* Loop 2: add all events */
1917 for (i = 0; i < npevs; i++) {
1918 ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,

--- 35 unchanged lines hidden (view full) ---

1954
1955 pr_debug("Writing event: %s\n", buf);
1956 ret = write(fd, buf, strlen(buf));
1957 if (ret < 0) {
1958 ret = -errno;
1959 goto error;
1960 }
1961
1911 if (ret < 0)
1912 goto end;
1913 pkgs[i].ntevs = ret;
1914 }
1915
1916 /* Loop 2: add all events */
1917 for (i = 0; i < npevs; i++) {
1918 ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,

--- 35 unchanged lines hidden (view full) ---

1954
1955 pr_debug("Writing event: %s\n", buf);
1956 ret = write(fd, buf, strlen(buf));
1957 if (ret < 0) {
1958 ret = -errno;
1959 goto error;
1960 }
1961
1962 printf("Remove event: %s\n", ent->s);
1962 printf("Removed event: %s\n", ent->s);
1963 return 0;
1964error:
1965 pr_warning("Failed to delete event: %s\n", strerror(-ret));
1966 return ret;
1967}
1968
1969static int del_trace_probe_event(int fd, const char *group,
1970 const char *event, struct strlist *namelist)

--- 87 unchanged lines hidden (view full) ---

2058 struct symbol *sym)
2059{
2060 if (sym->binding == STB_GLOBAL &&
2061 strfilter__compare(available_func_filter, sym->name))
2062 return 0;
2063 return 1;
2064}
2065
1963 return 0;
1964error:
1965 pr_warning("Failed to delete event: %s\n", strerror(-ret));
1966 return ret;
1967}
1968
1969static int del_trace_probe_event(int fd, const char *group,
1970 const char *event, struct strlist *namelist)

--- 87 unchanged lines hidden (view full) ---

2058 struct symbol *sym)
2059{
2060 if (sym->binding == STB_GLOBAL &&
2061 strfilter__compare(available_func_filter, sym->name))
2062 return 0;
2063 return 1;
2064}
2065
2066int show_available_funcs(const char *module, struct strfilter *_filter)
2066int show_available_funcs(const char *target, struct strfilter *_filter)
2067{
2068 struct map *map;
2069 int ret;
2070
2071 setup_pager();
2072
2073 ret = init_vmlinux();
2074 if (ret < 0)
2075 return ret;
2076
2067{
2068 struct map *map;
2069 int ret;
2070
2071 setup_pager();
2072
2073 ret = init_vmlinux();
2074 if (ret < 0)
2075 return ret;
2076
2077 map = kernel_get_module_map(module);
2077 map = kernel_get_module_map(target);
2078 if (!map) {
2078 if (!map) {
2079 pr_err("Failed to find %s map.\n", (module) ? : "kernel");
2079 pr_err("Failed to find %s map.\n", (target) ? : "kernel");
2080 return -EINVAL;
2081 }
2082 available_func_filter = _filter;
2083 if (map__load(map, filter_available_functions)) {
2084 pr_err("Failed to load map.\n");
2085 return -EINVAL;
2086 }
2087 if (!dso__sorted_by_name(map->dso, map->type))
2088 dso__sort_by_name(map->dso, map->type);
2089
2090 dso__fprintf_symbols_by_name(map->dso, map->type, stdout);
2091 return 0;
2092}
2080 return -EINVAL;
2081 }
2082 available_func_filter = _filter;
2083 if (map__load(map, filter_available_functions)) {
2084 pr_err("Failed to load map.\n");
2085 return -EINVAL;
2086 }
2087 if (!dso__sorted_by_name(map->dso, map->type))
2088 dso__sort_by_name(map->dso, map->type);
2089
2090 dso__fprintf_symbols_by_name(map->dso, map->type, stdout);
2091 return 0;
2092}