diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2009-12-15 16:03:27 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-15 16:03:27 -0500 |
| commit | b93b6a19edae7735ea7b9adc8c9d496b28dadd8f (patch) | |
| tree | cee3ed53554938ed00919a15a321645268d7d989 | |
| parent | 81661489891908d64e1577c405cf2015de17d11d (diff) | |
Added comments to the parse-event library
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | parse-events.c | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/parse-events.c b/parse-events.c index 5f136a7..7112eb8 100644 --- a/parse-events.c +++ b/parse-events.c | |||
| @@ -119,6 +119,16 @@ static char *find_cmdline(struct pevent *pevent, int pid) | |||
| 119 | return "<...>"; | 119 | return "<...>"; |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | /** | ||
| 123 | * pevent_register_comm - register a pid / comm mapping | ||
| 124 | * @pevent: handle for the pevent | ||
| 125 | * @comm: the command line to register | ||
| 126 | * @pid: the pid to map the command line to | ||
| 127 | * | ||
| 128 | * This adds a mapping to search for command line names with | ||
| 129 | * a given pid. Note, the comm that is given is stored and | ||
| 130 | * a duplicate is not made. | ||
| 131 | */ | ||
| 122 | int pevent_register_comm(struct pevent *pevent, char *comm, int pid) | 132 | int pevent_register_comm(struct pevent *pevent, char *comm, int pid) |
| 123 | { | 133 | { |
| 124 | struct cmdline_list *item; | 134 | struct cmdline_list *item; |
| @@ -234,6 +244,15 @@ find_func(struct pevent *pevent, unsigned long long addr) | |||
| 234 | return func; | 244 | return func; |
| 235 | } | 245 | } |
| 236 | 246 | ||
| 247 | /** | ||
| 248 | * pevent_find_function - find a function by a given address | ||
| 249 | * @pevent: handle for the pevent | ||
| 250 | * @addr: the address to find the function with | ||
| 251 | * | ||
| 252 | * Returns a pointer to the function stored that has the given | ||
| 253 | * address. Note, the address does not have to be exact, it | ||
| 254 | * will select the function that would contain the address. | ||
| 255 | */ | ||
| 237 | const char *pevent_find_function(struct pevent *pevent, unsigned long long addr) | 256 | const char *pevent_find_function(struct pevent *pevent, unsigned long long addr) |
| 238 | { | 257 | { |
| 239 | struct func_map *map; | 258 | struct func_map *map; |
| @@ -245,6 +264,16 @@ const char *pevent_find_function(struct pevent *pevent, unsigned long long addr) | |||
| 245 | return map->func; | 264 | return map->func; |
| 246 | } | 265 | } |
| 247 | 266 | ||
| 267 | /** | ||
| 268 | * pevent_register_function - register a function with a given address | ||
| 269 | * @pevent: handle for the pevent | ||
| 270 | * @function: the function name to register | ||
| 271 | * @addr: the address the function starts at | ||
| 272 | * @mod: the kernel module the function may be in (NULL for none) | ||
| 273 | * | ||
| 274 | * This registers a function name with an address and module. | ||
| 275 | * The @func passed in is stored and a copy is not made. | ||
| 276 | */ | ||
| 248 | int pevent_register_function(struct pevent *pevent, char *func, | 277 | int pevent_register_function(struct pevent *pevent, char *func, |
| 249 | unsigned long long addr, char *mod) | 278 | unsigned long long addr, char *mod) |
| 250 | { | 279 | { |
| @@ -264,6 +293,12 @@ int pevent_register_function(struct pevent *pevent, char *func, | |||
| 264 | return 0; | 293 | return 0; |
| 265 | } | 294 | } |
| 266 | 295 | ||
| 296 | /** | ||
| 297 | * pevent_print_funcs - print out the stored functions | ||
| 298 | * @pevent: handle for the pevent | ||
| 299 | * | ||
| 300 | * This prints out the stored functions. | ||
| 301 | */ | ||
| 267 | void pevent_print_funcs(struct pevent *pevent) | 302 | void pevent_print_funcs(struct pevent *pevent) |
| 268 | { | 303 | { |
| 269 | int i; | 304 | int i; |
| @@ -350,6 +385,15 @@ find_printk(struct pevent *pevent, unsigned long long addr) | |||
| 350 | return printk; | 385 | return printk; |
| 351 | } | 386 | } |
| 352 | 387 | ||
| 388 | /** | ||
| 389 | * pevent_register_print_string - register a string by its address | ||
| 390 | * @pevent: handle for the pevent | ||
| 391 | * @fmt: the string format to register | ||
| 392 | * @addr: the address the string was located at | ||
| 393 | * | ||
| 394 | * This registers a string by the address it was stored in the kernel. | ||
| 395 | * The @fmt is used in storage and a duplicate is not made. | ||
| 396 | */ | ||
| 353 | int pevent_register_print_string(struct pevent *pevent, char *fmt, | 397 | int pevent_register_print_string(struct pevent *pevent, char *fmt, |
| 354 | unsigned long long addr) | 398 | unsigned long long addr) |
| 355 | { | 399 | { |
| @@ -367,6 +411,12 @@ int pevent_register_print_string(struct pevent *pevent, char *fmt, | |||
| 367 | return 0; | 411 | return 0; |
| 368 | } | 412 | } |
| 369 | 413 | ||
| 414 | /** | ||
| 415 | * pevent_print_printk - print out the stored strings | ||
| 416 | * @pevent: handle for the pevent | ||
| 417 | * | ||
| 418 | * This prints the string formats that were stored. | ||
| 419 | */ | ||
| 370 | void pevent_print_printk(struct pevent *pevent) | 420 | void pevent_print_printk(struct pevent *pevent) |
| 371 | { | 421 | { |
| 372 | int i; | 422 | int i; |
| @@ -2102,6 +2152,14 @@ static int event_read_print(struct event *event) | |||
| 2102 | return -1; | 2152 | return -1; |
| 2103 | } | 2153 | } |
| 2104 | 2154 | ||
| 2155 | /** | ||
| 2156 | * pevent_find_common_field - return a common field by event | ||
| 2157 | * @event: handle for the event | ||
| 2158 | * @name: the name of the common field to return | ||
| 2159 | * | ||
| 2160 | * Returns a common field from the event by the given @name. | ||
| 2161 | * This only searchs the common fields and not all field. | ||
| 2162 | */ | ||
| 2105 | struct format_field * | 2163 | struct format_field * |
| 2106 | pevent_find_common_field(struct event *event, const char *name) | 2164 | pevent_find_common_field(struct event *event, const char *name) |
| 2107 | { | 2165 | { |
| @@ -2116,6 +2174,14 @@ pevent_find_common_field(struct event *event, const char *name) | |||
| 2116 | return format; | 2174 | return format; |
| 2117 | } | 2175 | } |
| 2118 | 2176 | ||
| 2177 | /** | ||
| 2178 | * pevent_find_field - find a non-common field | ||
| 2179 | * @event: handle for the event | ||
| 2180 | * @name: the name of the non-common field | ||
| 2181 | * | ||
| 2182 | * Returns a non-common field by the given @name. | ||
| 2183 | * This does not search common fields. | ||
| 2184 | */ | ||
| 2119 | struct format_field * | 2185 | struct format_field * |
| 2120 | pevent_find_field(struct event *event, const char *name) | 2186 | pevent_find_field(struct event *event, const char *name) |
| 2121 | { | 2187 | { |
| @@ -2130,6 +2196,15 @@ pevent_find_field(struct event *event, const char *name) | |||
| 2130 | return format; | 2196 | return format; |
| 2131 | } | 2197 | } |
| 2132 | 2198 | ||
| 2199 | /** | ||
| 2200 | * pevent_find_any_field - find any field by name | ||
| 2201 | * @event: handle for the event | ||
| 2202 | * @name: the name of the field | ||
| 2203 | * | ||
| 2204 | * Returns a field by the given @name. | ||
| 2205 | * This searchs the common field names first, then | ||
| 2206 | * the non-common ones if a common one was not found. | ||
| 2207 | */ | ||
| 2133 | struct format_field * | 2208 | struct format_field * |
| 2134 | pevent_find_any_field(struct event *event, const char *name) | 2209 | pevent_find_any_field(struct event *event, const char *name) |
| 2135 | { | 2210 | { |
| @@ -2141,6 +2216,15 @@ pevent_find_any_field(struct event *event, const char *name) | |||
| 2141 | return pevent_find_field(event, name); | 2216 | return pevent_find_field(event, name); |
| 2142 | } | 2217 | } |
| 2143 | 2218 | ||
| 2219 | /** | ||
| 2220 | * pevent_read_number - read a number from data | ||
| 2221 | * @pevent: handle for the pevent | ||
| 2222 | * @ptr: the raw data | ||
| 2223 | * @size: the size of the data that holds the number | ||
| 2224 | * | ||
| 2225 | * Returns the number (converted to host) from the | ||
| 2226 | * raw data. | ||
| 2227 | */ | ||
| 2144 | unsigned long long pevent_read_number(struct pevent *pevent, | 2228 | unsigned long long pevent_read_number(struct pevent *pevent, |
| 2145 | const void *ptr, int size) | 2229 | const void *ptr, int size) |
| 2146 | { | 2230 | { |
| @@ -2159,6 +2243,17 @@ unsigned long long pevent_read_number(struct pevent *pevent, | |||
| 2159 | } | 2243 | } |
| 2160 | } | 2244 | } |
| 2161 | 2245 | ||
| 2246 | /** | ||
| 2247 | * pevent_read_number_field - read a number from data | ||
| 2248 | * @field: a handle to the field | ||
| 2249 | * @data: the raw data to read | ||
| 2250 | * @value: the value to place the number in | ||
| 2251 | * | ||
| 2252 | * Reads raw data according to a field offset and size, | ||
| 2253 | * and translates it into @value. | ||
| 2254 | * | ||
| 2255 | * Returns 0 on success, -1 otherwise. | ||
| 2256 | */ | ||
| 2162 | int pevent_read_number_field(struct format_field *field, const void *data, | 2257 | int pevent_read_number_field(struct format_field *field, const void *data, |
| 2163 | unsigned long long *value) | 2258 | unsigned long long *value) |
| 2164 | { | 2259 | { |
| @@ -2253,6 +2348,13 @@ static int parse_common_lock_depth(struct pevent *pevent, void *data) | |||
| 2253 | return ret; | 2348 | return ret; |
| 2254 | } | 2349 | } |
| 2255 | 2350 | ||
| 2351 | /** | ||
| 2352 | * pevent_find_event - find an event by given id | ||
| 2353 | * @pevent: a handle to the pevent | ||
| 2354 | * @id: the id of the event | ||
| 2355 | * | ||
| 2356 | * Returns an event that has a given @id. | ||
| 2357 | */ | ||
| 2256 | struct event *pevent_find_event(struct pevent *pevent, int id) | 2358 | struct event *pevent_find_event(struct pevent *pevent, int id) |
| 2257 | { | 2359 | { |
| 2258 | struct event *event; | 2360 | struct event *event; |
| @@ -2264,6 +2366,15 @@ struct event *pevent_find_event(struct pevent *pevent, int id) | |||
| 2264 | return event; | 2366 | return event; |
| 2265 | } | 2367 | } |
| 2266 | 2368 | ||
| 2369 | /** | ||
| 2370 | * pevent_find_event_by_name - find an event by given name | ||
| 2371 | * @pevent: a handle to the pevent | ||
| 2372 | * @sys: the system name to search for | ||
| 2373 | * @name: the name of the event to search for | ||
| 2374 | * | ||
| 2375 | * This returns an event with a given @name and under the system | ||
| 2376 | * @sys. If @sys is NULL the first event with @name is returned. | ||
| 2377 | */ | ||
| 2267 | struct event * | 2378 | struct event * |
| 2268 | pevent_find_event_by_name(struct pevent *pevent, | 2379 | pevent_find_event_by_name(struct pevent *pevent, |
| 2269 | const char *sys, const char *name) | 2380 | const char *sys, const char *name) |
| @@ -2918,6 +3029,17 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event | |||
| 2918 | } | 3029 | } |
| 2919 | } | 3030 | } |
| 2920 | 3031 | ||
| 3032 | /** | ||
| 3033 | * pevent_data_lat_fmt - parse the data for the latency format | ||
| 3034 | * @pevent: a handle to the pevent | ||
| 3035 | * @s: the trace_seq to write to | ||
| 3036 | * @data: the raw data to read from | ||
| 3037 | * @size: currently unused. | ||
| 3038 | * | ||
| 3039 | * This parses out the Latency format (interrupts disabled, | ||
| 3040 | * need rescheduling, in hard/soft interrupt, preempt count | ||
| 3041 | * and lock depth) and places it into the trace_seq. | ||
| 3042 | */ | ||
| 2921 | void pevent_data_lat_fmt(struct pevent *pevent, | 3043 | void pevent_data_lat_fmt(struct pevent *pevent, |
| 2922 | struct trace_seq *s, void *data, int size __unused) | 3044 | struct trace_seq *s, void *data, int size __unused) |
| 2923 | { | 3045 | { |
| @@ -2956,21 +3078,50 @@ void pevent_data_lat_fmt(struct pevent *pevent, | |||
| 2956 | trace_seq_terminate(s); | 3078 | trace_seq_terminate(s); |
| 2957 | } | 3079 | } |
| 2958 | 3080 | ||
| 3081 | /** | ||
| 3082 | * pevent_data_type - parse out the given event type | ||
| 3083 | * @pevent: a handle to the pevent | ||
| 3084 | * @data: the raw data to read from | ||
| 3085 | * | ||
| 3086 | * This returns the event id from the raw @data. | ||
| 3087 | */ | ||
| 2959 | int pevent_data_type(struct pevent *pevent, void *data) | 3088 | int pevent_data_type(struct pevent *pevent, void *data) |
| 2960 | { | 3089 | { |
| 2961 | return trace_parse_common_type(pevent, data); | 3090 | return trace_parse_common_type(pevent, data); |
| 2962 | } | 3091 | } |
| 2963 | 3092 | ||
| 3093 | /** | ||
| 3094 | * pevent_data_event_from_type - find the event by a given type | ||
| 3095 | * @pevent: a handle to the pevent | ||
| 3096 | * @type: the type of the event. | ||
| 3097 | * | ||
| 3098 | * This returns the event form a given @type; | ||
| 3099 | */ | ||
| 2964 | struct event *pevent_data_event_from_type(struct pevent *pevent, int type) | 3100 | struct event *pevent_data_event_from_type(struct pevent *pevent, int type) |
| 2965 | { | 3101 | { |
| 2966 | return pevent_find_event(pevent, type); | 3102 | return pevent_find_event(pevent, type); |
| 2967 | } | 3103 | } |
| 2968 | 3104 | ||
| 3105 | /** | ||
| 3106 | * pevent_data_pid - parse the PID from raw data | ||
| 3107 | * @pevent: a handle to the pevent | ||
| 3108 | * @data: the raw data to parse | ||
| 3109 | * | ||
| 3110 | * This returns the PID from a raw data. | ||
| 3111 | */ | ||
| 2969 | int pevent_data_pid(struct pevent *pevent, void *data) | 3112 | int pevent_data_pid(struct pevent *pevent, void *data) |
| 2970 | { | 3113 | { |
| 2971 | return parse_common_pid(pevent, data); | 3114 | return parse_common_pid(pevent, data); |
| 2972 | } | 3115 | } |
| 2973 | 3116 | ||
| 3117 | /** | ||
| 3118 | * pevent_data_comm_from_pid - return the command line from PID | ||
| 3119 | * @pevent: a handle to the pevent | ||
| 3120 | * @pid: the PID of the task to search for | ||
| 3121 | * | ||
| 3122 | * This returns a pointer to the command line that has the given | ||
| 3123 | * @pid. | ||
| 3124 | */ | ||
| 2974 | const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid) | 3125 | const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid) |
| 2975 | { | 3126 | { |
| 2976 | const char *comm; | 3127 | const char *comm; |
| @@ -2979,6 +3130,18 @@ const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid) | |||
| 2979 | return comm; | 3130 | return comm; |
| 2980 | } | 3131 | } |
| 2981 | 3132 | ||
| 3133 | /** | ||
| 3134 | * pevent_data_comm_from_pid - parse the data into the print format | ||
| 3135 | * @s: the trace_seq to write to | ||
| 3136 | * @event: the handle to the event | ||
| 3137 | * @cpu: the cpu the event was recorded on | ||
| 3138 | * @data: the raw data | ||
| 3139 | * @size: the size of the raw data | ||
| 3140 | * @nsecs: the timestamp of the event | ||
| 3141 | * | ||
| 3142 | * This parses the raw @data using the given @event information and | ||
| 3143 | * writes the print format into the trace_seq. | ||
| 3144 | */ | ||
| 2982 | void pevent_event_info(struct trace_seq *s, struct event *event, | 3145 | void pevent_event_info(struct trace_seq *s, struct event *event, |
| 2983 | int cpu, void *data, int size, unsigned long long nsecs) | 3146 | int cpu, void *data, int size, unsigned long long nsecs) |
| 2984 | { | 3147 | { |
| @@ -3276,6 +3439,17 @@ static void parse_header_field(const char *field, | |||
| 3276 | free_token(token); | 3439 | free_token(token); |
| 3277 | } | 3440 | } |
| 3278 | 3441 | ||
| 3442 | /** | ||
| 3443 | * pevent_parse_header_page - parse the data stored in the header page | ||
| 3444 | * @pevent: the handle to the pevent | ||
| 3445 | * @buf: the buffer storing the header page format string | ||
| 3446 | * @size: the size of @buf | ||
| 3447 | * | ||
| 3448 | * This parses the header page format for information on the | ||
| 3449 | * ring buffer used. The @buf should be copied from | ||
| 3450 | * | ||
| 3451 | * /sys/kernel/debug/tracing/events/header_page | ||
| 3452 | */ | ||
| 3279 | int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size) | 3453 | int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size) |
| 3280 | { | 3454 | { |
| 3281 | if (!size) { | 3455 | if (!size) { |
| @@ -3301,6 +3475,20 @@ int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long siz | |||
| 3301 | return 0; | 3475 | return 0; |
| 3302 | } | 3476 | } |
| 3303 | 3477 | ||
| 3478 | /** | ||
| 3479 | * pevent_parse_event - parse the event format | ||
| 3480 | * @pevent: the handle to the pevent | ||
| 3481 | * @buf: the buffer storing the event format string | ||
| 3482 | * @size: the size of @buf | ||
| 3483 | * @sys: the system the event belongs to | ||
| 3484 | * | ||
| 3485 | * This parses the event format and creates an event structure | ||
| 3486 | * to quickly parse raw data for a given event. | ||
| 3487 | * | ||
| 3488 | * These files currently come from: | ||
| 3489 | * | ||
| 3490 | * /sys/kernel/debug/tracing/events/.../.../format | ||
| 3491 | */ | ||
| 3304 | int pevent_parse_event(struct pevent *pevent, | 3492 | int pevent_parse_event(struct pevent *pevent, |
| 3305 | char *buf, unsigned long size, char *sys) | 3493 | char *buf, unsigned long size, char *sys) |
| 3306 | { | 3494 | { |
| @@ -3377,6 +3565,22 @@ int pevent_parse_event(struct pevent *pevent, | |||
| 3377 | return -1; | 3565 | return -1; |
| 3378 | } | 3566 | } |
| 3379 | 3567 | ||
| 3568 | /** | ||
| 3569 | * pevent_register_event_handle - register a way to parse an event | ||
| 3570 | * @pevent: the handle to the pevent | ||
| 3571 | * @id: the id of the event to register | ||
| 3572 | * @sys_name: the system name the event belongs to | ||
| 3573 | * @event_name: the name of the event | ||
| 3574 | * @func: the function to call to parse the event information | ||
| 3575 | * | ||
| 3576 | * This function allows a developer to override the parsing of | ||
| 3577 | * a given event. If for some reason the default print format | ||
| 3578 | * is not sufficient, this function will register a function | ||
| 3579 | * for an event to be used to parse the data instead. | ||
| 3580 | * | ||
| 3581 | * If @id is >= 0, then it is used to find the event. | ||
| 3582 | * else @sys_name and @event_name are used. | ||
| 3583 | */ | ||
| 3380 | int pevent_register_event_handler(struct pevent *pevent, | 3584 | int pevent_register_event_handler(struct pevent *pevent, |
| 3381 | int id, char *sys_name, char *event_name, | 3585 | int id, char *sys_name, char *event_name, |
| 3382 | pevent_event_handler_func func) | 3586 | pevent_event_handler_func func) |
| @@ -3405,6 +3609,9 @@ int pevent_register_event_handler(struct pevent *pevent, | |||
| 3405 | return 0; | 3609 | return 0; |
| 3406 | } | 3610 | } |
| 3407 | 3611 | ||
| 3612 | /** | ||
| 3613 | * pevent_alloc - create a pevent handle | ||
| 3614 | */ | ||
| 3408 | struct pevent *pevent_alloc(void) | 3615 | struct pevent *pevent_alloc(void) |
| 3409 | { | 3616 | { |
| 3410 | struct pevent *pevent; | 3617 | struct pevent *pevent; |
| @@ -3433,6 +3640,10 @@ static void free_event(struct event *event) | |||
| 3433 | free_args(event->print_fmt.args); | 3640 | free_args(event->print_fmt.args); |
| 3434 | } | 3641 | } |
| 3435 | 3642 | ||
| 3643 | /** | ||
| 3644 | * pevent_free - free a pevent handle | ||
| 3645 | * @pevent: the pevent handle to free | ||
| 3646 | */ | ||
| 3436 | void pevent_free(struct pevent *pevent) | 3647 | void pevent_free(struct pevent *pevent) |
| 3437 | { | 3648 | { |
| 3438 | struct event *event, *next_event; | 3649 | struct event *event, *next_event; |
