libperf.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. libperf(3)
  2. ==========
  3. NAME
  4. ----
  5. libperf - Linux kernel perf event library
  6. SYNOPSIS
  7. --------
  8. *Generic API:*
  9. [source,c]
  10. --
  11. #include <perf/core.h>
  12. enum libperf_print_level {
  13. LIBPERF_ERR,
  14. LIBPERF_WARN,
  15. LIBPERF_INFO,
  16. LIBPERF_DEBUG,
  17. LIBPERF_DEBUG2,
  18. LIBPERF_DEBUG3,
  19. };
  20. typedef int (*libperf_print_fn_t)(enum libperf_print_level level,
  21. const char *, va_list ap);
  22. void libperf_init(libperf_print_fn_t fn);
  23. --
  24. *API to handle CPU maps:*
  25. [source,c]
  26. --
  27. #include <perf/cpumap.h>
  28. struct perf_cpu_map;
  29. struct perf_cpu_map *perf_cpu_map__dummy_new(void);
  30. struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);
  31. struct perf_cpu_map *perf_cpu_map__read(FILE *file);
  32. struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map);
  33. struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig,
  34. struct perf_cpu_map *other);
  35. void perf_cpu_map__put(struct perf_cpu_map *map);
  36. int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx);
  37. int perf_cpu_map__nr(const struct perf_cpu_map *cpus);
  38. bool perf_cpu_map__empty(const struct perf_cpu_map *map);
  39. int perf_cpu_map__max(struct perf_cpu_map *map);
  40. bool perf_cpu_map__has(const struct perf_cpu_map *map, int cpu);
  41. #define perf_cpu_map__for_each_cpu(cpu, idx, cpus)
  42. --
  43. *API to handle thread maps:*
  44. [source,c]
  45. --
  46. #include <perf/threadmap.h>
  47. struct perf_thread_map;
  48. struct perf_thread_map *perf_thread_map__new_dummy(void);
  49. struct perf_thread_map *perf_thread_map__new_array(int nr_threads, pid_t *array);
  50. void perf_thread_map__set_pid(struct perf_thread_map *map, int idx, pid_t pid);
  51. char *perf_thread_map__comm(struct perf_thread_map *map, int idx);
  52. int perf_thread_map__nr(struct perf_thread_map *threads);
  53. pid_t perf_thread_map__pid(struct perf_thread_map *map, int idx);
  54. struct perf_thread_map *perf_thread_map__get(struct perf_thread_map *map);
  55. void perf_thread_map__put(struct perf_thread_map *map);
  56. --
  57. *API to handle event lists:*
  58. [source,c]
  59. --
  60. #include <perf/evlist.h>
  61. struct perf_evlist;
  62. void perf_evlist__add(struct perf_evlist *evlist,
  63. struct perf_evsel *evsel);
  64. void perf_evlist__remove(struct perf_evlist *evlist,
  65. struct perf_evsel *evsel);
  66. struct perf_evlist *perf_evlist__new(void);
  67. void perf_evlist__delete(struct perf_evlist *evlist);
  68. struct perf_evsel* perf_evlist__next(struct perf_evlist *evlist,
  69. struct perf_evsel *evsel);
  70. int perf_evlist__open(struct perf_evlist *evlist);
  71. void perf_evlist__close(struct perf_evlist *evlist);
  72. void perf_evlist__enable(struct perf_evlist *evlist);
  73. void perf_evlist__disable(struct perf_evlist *evlist);
  74. #define perf_evlist__for_each_evsel(evlist, pos)
  75. void perf_evlist__set_maps(struct perf_evlist *evlist,
  76. struct perf_cpu_map *cpus,
  77. struct perf_thread_map *threads);
  78. int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
  79. int perf_evlist__filter_pollfd(struct perf_evlist *evlist,
  80. short revents_and_mask);
  81. int perf_evlist__mmap(struct perf_evlist *evlist, int pages);
  82. void perf_evlist__munmap(struct perf_evlist *evlist);
  83. struct perf_mmap *perf_evlist__next_mmap(struct perf_evlist *evlist,
  84. struct perf_mmap *map,
  85. bool overwrite);
  86. #define perf_evlist__for_each_mmap(evlist, pos, overwrite)
  87. --
  88. *API to handle events:*
  89. [source,c]
  90. --
  91. #include <perf/evsel.h>*
  92. struct perf_evsel;
  93. struct perf_counts_values {
  94. union {
  95. struct {
  96. uint64_t val;
  97. uint64_t ena;
  98. uint64_t run;
  99. };
  100. uint64_t values[3];
  101. };
  102. };
  103. struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr);
  104. void perf_evsel__delete(struct perf_evsel *evsel);
  105. int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
  106. struct perf_thread_map *threads);
  107. void perf_evsel__close(struct perf_evsel *evsel);
  108. void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu_map_idx);
  109. int perf_evsel__mmap(struct perf_evsel *evsel, int pages);
  110. void perf_evsel__munmap(struct perf_evsel *evsel);
  111. void *perf_evsel__mmap_base(struct perf_evsel *evsel, int cpu_map_idx, int thread);
  112. int perf_evsel__read(struct perf_evsel *evsel, int cpu_map_idx, int thread,
  113. struct perf_counts_values *count);
  114. int perf_evsel__enable(struct perf_evsel *evsel);
  115. int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx);
  116. int perf_evsel__disable(struct perf_evsel *evsel);
  117. int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx);
  118. struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel);
  119. struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel);
  120. struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);
  121. --
  122. *API to handle maps (perf ring buffers):*
  123. [source,c]
  124. --
  125. #include <perf/mmap.h>
  126. struct perf_mmap;
  127. void perf_mmap__consume(struct perf_mmap *map);
  128. int perf_mmap__read_init(struct perf_mmap *map);
  129. void perf_mmap__read_done(struct perf_mmap *map);
  130. union perf_event *perf_mmap__read_event(struct perf_mmap *map);
  131. --
  132. *Structures to access perf API events:*
  133. [source,c]
  134. --
  135. #include <perf/event.h>
  136. struct perf_record_mmap;
  137. struct perf_record_mmap2;
  138. struct perf_record_comm;
  139. struct perf_record_namespaces;
  140. struct perf_record_fork;
  141. struct perf_record_lost;
  142. struct perf_record_lost_samples;
  143. struct perf_record_read;
  144. struct perf_record_throttle;
  145. struct perf_record_ksymbol;
  146. struct perf_record_bpf_event;
  147. struct perf_record_sample;
  148. struct perf_record_switch;
  149. struct perf_record_header_attr;
  150. struct perf_record_record_cpu_map;
  151. struct perf_record_cpu_map_data;
  152. struct perf_record_cpu_map;
  153. struct perf_record_event_update_cpus;
  154. struct perf_record_event_update_scale;
  155. struct perf_record_event_update;
  156. struct perf_trace_event_type;
  157. struct perf_record_header_event_type;
  158. struct perf_record_header_tracing_data;
  159. struct perf_record_header_build_id;
  160. struct perf_record_id_index;
  161. struct perf_record_auxtrace_info;
  162. struct perf_record_auxtrace;
  163. struct perf_record_auxtrace_error;
  164. struct perf_record_aux;
  165. struct perf_record_itrace_start;
  166. struct perf_record_thread_map_entry;
  167. struct perf_record_thread_map;
  168. struct perf_record_stat_config_entry;
  169. struct perf_record_stat_config;
  170. struct perf_record_stat;
  171. struct perf_record_stat_round;
  172. struct perf_record_time_conv;
  173. struct perf_record_header_feature;
  174. struct perf_record_compressed;
  175. --
  176. DESCRIPTION
  177. -----------
  178. The libperf library provides an API to access the linux kernel perf
  179. events subsystem.
  180. Following objects are key to the libperf interface:
  181. [horizontal]
  182. struct perf_cpu_map:: Provides a CPU list abstraction.
  183. struct perf_thread_map:: Provides a thread list abstraction.
  184. struct perf_evsel:: Provides an abstraction for single a perf event.
  185. struct perf_evlist:: Gathers several struct perf_evsel object and performs functions on all of them.
  186. struct perf_mmap:: Provides an abstraction for accessing perf ring buffer.
  187. The exported API functions bind these objects together.
  188. REPORTING BUGS
  189. --------------
  190. Report bugs to <[email protected]>.
  191. LICENSE
  192. -------
  193. libperf is Free Software licensed under the GNU LGPL 2.1
  194. RESOURCES
  195. ---------
  196. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
  197. SEE ALSO
  198. --------
  199. libperf-sampling(7), libperf-counting(7)