Lines Matching defs:tep

164 static int cmdline_init(struct tep_handle *tep)
166 struct cmdline_list *cmdlist = tep->cmdlist;
171 cmdlines = malloc(sizeof(*cmdlines) * tep->cmdline_count);
185 qsort(cmdlines, tep->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
187 tep->cmdlines = cmdlines;
188 tep->cmdlist = NULL;
193 static const char *find_cmdline(struct tep_handle *tep, int pid)
201 if (!tep->cmdlines && cmdline_init(tep))
206 comm = bsearch(&key, tep->cmdlines, tep->cmdline_count,
207 sizeof(*tep->cmdlines), cmdline_cmp);
216 * @tep: a handle to the trace event parser context
222 bool tep_is_pid_registered(struct tep_handle *tep, int pid)
230 if (!tep->cmdlines && cmdline_init(tep))
235 comm = bsearch(&key, tep->cmdlines, tep->cmdline_count,
236 sizeof(*tep->cmdlines), cmdline_cmp);
248 static int add_new_comm(struct tep_handle *tep,
251 struct tep_cmdline *cmdlines = tep->cmdlines;
263 cmdline = bsearch(&key, tep->cmdlines, tep->cmdline_count,
264 sizeof(*tep->cmdlines), cmdline_cmp);
281 cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (tep->cmdline_count + 1));
286 tep->cmdlines = cmdlines;
294 if (!tep->cmdline_count) {
296 tep->cmdlines[0] = key;
297 tep->cmdline_count++;
302 cmdline = bsearch(&key, tep->cmdlines, tep->cmdline_count - 1,
303 sizeof(*tep->cmdlines), cmdline_slot_cmp);
305 cnt = tep->cmdline_count;
309 cnt -= cmdline - tep->cmdlines;
313 if (key.pid > tep->cmdlines[tep->cmdline_count - 1].pid) {
314 tep->cmdlines[tep->cmdline_count++] = key;
317 cmdline = &tep->cmdlines[0];
322 tep->cmdline_count++;
327 static int _tep_register_comm(struct tep_handle *tep,
332 if (tep->cmdlines)
333 return add_new_comm(tep, comm, pid, override);
348 item->next = tep->cmdlist;
350 tep->cmdlist = item;
351 tep->cmdline_count++;
358 * @tep: a handle to the trace event parser context
366 int tep_register_comm(struct tep_handle *tep, const char *comm, int pid)
368 return _tep_register_comm(tep, comm, pid, false);
373 * @tep: a handle to the trace event parser context
381 int tep_override_comm(struct tep_handle *tep, const char *comm, int pid)
383 if (!tep->cmdlines && cmdline_init(tep)) {
387 return _tep_register_comm(tep, comm, pid, true);
437 static int func_map_init(struct tep_handle *tep)
444 func_map = malloc(sizeof(*func_map) * (tep->func_count + 1));
448 funclist = tep->funclist;
461 qsort(func_map, tep->func_count, sizeof(*func_map), func_cmp);
466 func_map[tep->func_count].func = NULL;
467 func_map[tep->func_count].addr = 0;
468 func_map[tep->func_count].mod = NULL;
470 tep->func_map = func_map;
471 tep->funclist = NULL;
477 __find_func(struct tep_handle *tep, unsigned long long addr)
482 if (!tep->func_map)
483 func_map_init(tep);
487 func = bsearch(&key, tep->func_map, tep->func_count,
488 sizeof(*tep->func_map), func_bcmp);
501 * @tep: a handle to the trace event parser context
506 * keep using it instead of duplicating all the entries inside tep->funclist.
508 int tep_set_function_resolver(struct tep_handle *tep,
519 free(tep->func_resolver);
520 tep->func_resolver = resolver;
527 * @tep: a handle to the trace event parser context
532 void tep_reset_function_resolver(struct tep_handle *tep)
534 free(tep->func_resolver);
535 tep->func_resolver = NULL;
539 find_func(struct tep_handle *tep, unsigned long long addr)
543 if (!tep->func_resolver)
544 return __find_func(tep, addr);
546 map = &tep->func_resolver->map;
549 map->func = tep->func_resolver->func(tep->func_resolver->priv,
559 * @tep: a handle to the trace event parser context
566 const char *tep_find_function(struct tep_handle *tep, unsigned long long addr)
570 map = find_func(tep, addr);
579 * @tep: a handle to the trace event parser context
587 tep_find_function_address(struct tep_handle *tep, unsigned long long addr)
591 map = find_func(tep, addr);
600 * @tep: a handle to the trace event parser context
608 int tep_register_function(struct tep_handle *tep, char *func,
616 item->next = tep->funclist;
629 tep->funclist = item;
630 tep->func_count++;
645 * @tep: a handle to the trace event parser context
649 void tep_print_funcs(struct tep_handle *tep)
653 if (!tep->func_map)
654 func_map_init(tep);
656 for (i = 0; i < (int)tep->func_count; i++) {
658 tep->func_map[i].addr,
659 tep->func_map[i].func);
660 if (tep->func_map[i].mod)
661 printf(" [%s]\n", tep->func_map[i].mod);
691 static int printk_map_init(struct tep_handle *tep)
698 printk_map = malloc(sizeof(*printk_map) * (tep->printk_count + 1));
702 printklist = tep->printklist;
714 qsort(printk_map, tep->printk_count, sizeof(*printk_map), printk_cmp);
716 tep->printk_map = printk_map;
717 tep->printklist = NULL;
723 find_printk(struct tep_handle *tep, unsigned long long addr)
728 if (!tep->printk_map && printk_map_init(tep))
733 printk = bsearch(&key, tep->printk_map, tep->printk_count,
734 sizeof(*tep->printk_map), printk_cmp);
741 * @tep: a handle to the trace event parser context
748 int tep_register_print_string(struct tep_handle *tep, const char *fmt,
757 item->next = tep->printklist;
775 tep->printklist = item;
776 tep->printk_count++;
788 * @tep: a handle to the trace event parser context
792 void tep_print_printk(struct tep_handle *tep)
796 if (!tep->printk_map)
797 printk_map_init(tep);
799 for (i = 0; i < (int)tep->printk_count; i++) {
801 tep->printk_map[i].addr,
802 tep->printk_map[i].printk);
811 static int add_event(struct tep_handle *tep, struct tep_event *event)
814 struct tep_event **events = realloc(tep->events, sizeof(event) *
815 (tep->nr_events + 1));
819 tep->events = events;
821 for (i = 0; i < tep->nr_events; i++) {
822 if (tep->events[i]->id > event->id)
825 if (i < tep->nr_events)
826 memmove(&tep->events[i + 1],
827 &tep->events[i],
828 sizeof(event) * (tep->nr_events - i));
830 tep->events[i] = event;
831 tep->nr_events++;
833 event->tep = tep;
1194 * read_token - access to utilities to use the tep parser
1695 field->elementsize = event->tep ?
1696 event->tep->long_size :
2978 find_func_handler(struct tep_handle *tep, char *func_name)
2982 if (!tep)
2985 for (func = tep->func_handlers; func; func = func->next) {
2993 static void remove_func_handler(struct tep_handle *tep, char *func_name)
2998 next = &tep->func_handlers;
3147 func = find_func_handler(event->tep, token);
3425 * @tep: a handle to the trace event parser context
3432 unsigned long long tep_read_number(struct tep_handle *tep,
3441 return data2host2(tep, *(unsigned short *)ptr);
3443 return data2host4(tep, *(unsigned int *)ptr);
3446 return data2host8(tep, val);
3474 *value = tep_read_number(field->event->tep,
3482 static int get_common_info(struct tep_handle *tep,
3492 if (!tep->events) {
3497 event = tep->events[0];
3508 static int __parse_common(struct tep_handle *tep, void *data,
3514 ret = get_common_info(tep, name, offset, size);
3518 return tep_read_number(tep, data + *offset, *size);
3521 static int trace_parse_common_type(struct tep_handle *tep, void *data)
3523 return __parse_common(tep, data,
3524 &tep->type_size, &tep->type_offset,
3528 static int parse_common_pid(struct tep_handle *tep, void *data)
3530 return __parse_common(tep, data,
3531 &tep->pid_size, &tep->pid_offset,
3535 static int parse_common_pc(struct tep_handle *tep, void *data)
3537 return __parse_common(tep, data,
3538 &tep->pc_size, &tep->pc_offset,
3542 static int parse_common_flags(struct tep_handle *tep, void *data)
3544 return __parse_common(tep, data,
3545 &tep->flags_size, &tep->flags_offset,
3549 static int parse_common_lock_depth(struct tep_handle *tep, void *data)
3551 return __parse_common(tep, data,
3552 &tep->ld_size, &tep->ld_offset,
3556 static int parse_common_migrate_disable(struct tep_handle *tep, void *data)
3558 return __parse_common(tep, data,
3559 &tep->ld_size, &tep->ld_offset,
3567 * @tep: a handle to the trace event parser context
3572 struct tep_event *tep_find_event(struct tep_handle *tep, int id)
3579 if (tep->last_event && tep->last_event->id == id)
3580 return tep->last_event;
3584 eventptr = bsearch(&pkey, tep->events, tep->nr_events,
3585 sizeof(*tep->events), events_id_cmp);
3588 tep->last_event = *eventptr;
3597 * @tep: a handle to the trace event parser context
3605 tep_find_event_by_name(struct tep_handle *tep,
3611 if (tep->last_event &&
3612 strcmp(tep->last_event->name, name) == 0 &&
3613 (!sys || strcmp(tep->last_event->system, sys) == 0))
3614 return tep->last_event;
3616 for (i = 0; i < tep->nr_events; i++) {
3617 event = tep->events[i];
3625 if (i == tep->nr_events)
3628 tep->last_event = event;
3635 struct tep_handle *tep = event->tep;
3657 val = tep_read_number(tep, data + arg->field.field->offset,
3697 field_size = tep->long_size;
3701 offset = tep_read_number(tep,
3730 val = tep_read_number(tep,
3831 offset = tep_read_number(tep,
3843 offset = tep_read_number(tep,
3918 static void print_bitmask_to_seq(struct tep_handle *tep,
3950 if (tep->file_bigendian)
3976 struct tep_handle *tep = event->tep;
4013 field->size == tep->long_size) {
4028 addr = (tep->long_size == 8) ?
4033 printk = find_printk(tep, addr);
4090 offset = tep_read_number(tep,
4121 offset = tep_read_number(tep,
4172 str_offset = data2host4(tep, *(unsigned int *)(data + arg->string.offset));
4190 bitmask_offset = data2host4(tep, *(unsigned int *)(data + arg->bitmask.offset));
4193 print_bitmask_to_seq(tep, s, format, len_arg,
4325 struct tep_handle *tep = event->tep;
4333 field = tep->bprint_buf_field;
4334 ip_field = tep->bprint_ip_field;
4347 tep->bprint_buf_field = field;
4348 tep->bprint_ip_field = ip_field;
4351 ip = tep_read_number(tep, data + ip_field->offset, ip_field->size);
4441 vsize = tep->long_size;
4458 val = tep_read_number(tep, bptr, vsize);
4515 struct tep_handle *tep = event->tep;
4521 field = tep->bprint_fmt_field;
4529 tep->bprint_fmt_field = field;
4532 addr = tep_read_number(tep, data + field->offset, field->size);
4534 printk = find_printk(tep, addr);
4601 static int parse_ip4_print_args(struct tep_handle *tep,
4611 if (tep->file_bigendian)
4762 ret = parse_ip4_print_args(event->tep, ptr, &reverse);
4870 ret = parse_ip4_print_args(event->tep, ptr, &reverse);
5068 offset = tep_read_number(event->tep,
5102 struct tep_handle *tep = field->event->tep;
5108 val = tep_read_number(tep, data + offset, len);
5128 val = tep_read_number(tep, data + field->offset,
5183 func = find_func(event->tep, val);
5189 if (event->tep->long_size == 4)
5549 if (event->tep->long_size == 8 && ls == 1 &&
5746 static void data_latency_format(struct tep_handle *tep, struct trace_seq *s,
5763 lat_flags = parse_common_flags(tep, data);
5764 pc = parse_common_pc(tep, data);
5767 lock_depth = parse_common_lock_depth(tep, data);
5769 lock_depth = parse_common_lock_depth(tep, data);
5778 migrate_disable = parse_common_migrate_disable(tep, data);
5780 migrate_disable = parse_common_migrate_disable(tep, data);
5831 * @tep: a handle to the trace event parser context
5836 int tep_data_type(struct tep_handle *tep, struct tep_record *rec)
5838 return trace_parse_common_type(tep, rec->data);
5843 * @tep: a handle to the trace event parser context
5848 int tep_data_pid(struct tep_handle *tep, struct tep_record *rec)
5850 return parse_common_pid(tep, rec->data);
5855 * @tep: a handle to the trace event parser context
5860 int tep_data_preempt_count(struct tep_handle *tep, struct tep_record *rec)
5862 return parse_common_pc(tep, rec->data);
5867 * @tep: a handle to the trace event parser context
5874 int tep_data_flags(struct tep_handle *tep, struct tep_record *rec)
5876 return parse_common_flags(tep, rec->data);
5881 * @tep: a handle to the trace event parser context
5887 const char *tep_data_comm_from_pid(struct tep_handle *tep, int pid)
5891 comm = find_cmdline(tep, pid);
5896 pid_from_cmdlist(struct tep_handle *tep, const char *comm, struct tep_cmdline *next)
5903 cmdlist = tep->cmdlist;
5913 * @tep: a handle to the trace event parser context
5924 struct tep_cmdline *tep_data_pid_from_comm(struct tep_handle *tep, const char *comm,
5933 if (!tep->cmdlines)
5934 return pid_from_cmdlist(tep, comm, next);
5941 if (next < tep->cmdlines ||
5942 next >= tep->cmdlines + tep->cmdline_count)
5949 cmdline = tep->cmdlines;
5951 while (cmdline < tep->cmdlines + tep->cmdline_count) {
5961 * @tep: a handle to the trace event parser context
5967 int tep_cmdline_pid(struct tep_handle *tep, struct tep_cmdline *cmdline)
5978 if (!tep->cmdlines ||
5979 cmdline < tep->cmdlines ||
5980 cmdline >= tep->cmdlines + tep->cmdline_count)
6012 * @tep: a handle to the trace event parser context
6019 tep_find_event_by_record(struct tep_handle *tep, struct tep_record *record)
6028 type = trace_parse_common_type(tep, record->data);
6030 return tep_find_event(tep, type);
6040 static void print_event_time(struct tep_handle *tep, struct trace_seq *s,
6079 static void print_string(struct tep_handle *tep, struct trace_seq *s,
6087 data_latency_format(tep, s, type->format, record);
6089 pid = parse_common_pid(tep, record->data);
6090 comm = find_cmdline(tep, pid);
6104 static void print_int(struct tep_handle *tep, struct trace_seq *s,
6115 param = parse_common_pid(tep, record->data);
6118 return print_event_time(tep, s, type->format, event, record);
6158 * @tep: a handle to the trace event parser context
6178 void tep_print_event(struct tep_handle *tep, struct trace_seq *s,
6192 event = tep_find_event_by_record(tep, record);
6207 print_string(tep, s, record, event,
6211 print_int(tep, s, record, event,
6274 static struct tep_event **list_events_copy(struct tep_handle *tep)
6278 if (!tep)
6281 events = malloc(sizeof(*events) * (tep->nr_events + 1));
6285 memcpy(events, tep->events, sizeof(*events) * tep->nr_events);
6286 events[tep->nr_events] = NULL;
6315 * @tep: a handle to the tep context
6323 struct tep_event **tep_list_events(struct tep_handle *tep,
6328 if (!tep)
6331 events = tep->sort_events;
6332 if (events && tep->last_type == sort_type)
6336 events = list_events_copy(tep);
6340 tep->sort_events = events;
6344 tep->last_type = sort_type;
6349 list_events_sort(events, tep->nr_events, sort_type);
6350 tep->last_type = sort_type;
6358 * @tep: a handle to the tep context
6365 struct tep_event **tep_list_events_copy(struct tep_handle *tep,
6370 if (!tep)
6373 events = list_events_copy(tep);
6381 list_events_sort(events, tep->nr_events, sort_type);
6640 * @tep: a handle to the trace event parser context
6650 int tep_parse_header_page(struct tep_handle *tep, char *buf, unsigned long size,
6660 tep->header_page_ts_size = sizeof(long long);
6661 tep->header_page_size_size = long_size;
6662 tep->header_page_data_offset = sizeof(long long) + long_size;
6663 tep->old_format = 1;
6668 parse_header_field("timestamp", &tep->header_page_ts_offset,
6669 &tep->header_page_ts_size, 1);
6670 parse_header_field("commit", &tep->header_page_size_offset,
6671 &tep->header_page_size_size, 1);
6672 parse_header_field("overwrite", &tep->header_page_overwrite,
6674 parse_header_field("data", &tep->header_page_data_offset,
6675 &tep->header_page_data_size, 1);
6703 static int find_event_handle(struct tep_handle *tep, struct tep_event *event)
6707 for (next = &tep->handlers; *next;
6745 struct tep_handle *tep, const char *buf,
6787 /* Add tep to event so that it can be referenced */
6788 event->tep = tep;
6800 if (tep && find_event_handle(tep, event))
6856 __parse_event(struct tep_handle *tep,
6861 int ret = parse_format(eventp, tep, buf, size, sys);
6867 if (tep && add_event(tep, event)) {
6885 * @tep: a handle to the trace event parser context
6898 enum tep_errno tep_parse_format(struct tep_handle *tep,
6903 return __parse_event(tep, eventp, buf, size, sys);
6908 * @tep: a handle to the trace event parser context
6920 enum tep_errno tep_parse_event(struct tep_handle *tep, const char *buf,
6924 return __parse_event(tep, &event, buf, size, sys);
6986 offset = tep_read_number(event->tep,
7121 struct tep_handle *tep = event->tep;
7132 func = find_func(tep, val);
7164 * @tep: a handle to the trace event parser context
7177 int tep_register_print_function(struct tep_handle *tep,
7189 func_handle = find_func_handler(tep, name);
7197 remove_func_handler(tep, name);
7244 func_handle->next = tep->func_handlers;
7245 tep->func_handlers = func_handle;
7256 * @tep: a handle to the trace event parser context
7264 int tep_unregister_print_function(struct tep_handle *tep,
7269 func_handle = find_func_handler(tep, name);
7271 remove_func_handler(tep, name);
7277 static struct tep_event *search_event(struct tep_handle *tep, int id,
7285 event = tep_find_event(tep, id);
7293 event = tep_find_event_by_name(tep, sys_name, event_name);
7302 * @tep: a handle to the trace event parser context
7323 int tep_register_event_handler(struct tep_handle *tep, int id,
7330 event = search_event(tep, id, sys_name, event_name);
7365 handle->next = tep->handlers;
7366 tep->handlers = handle;
7393 * @tep: a handle to the trace event parser context
7407 int tep_unregister_event_handler(struct tep_handle *tep, int id,
7415 event = search_event(tep, id, sys_name, event_name);
7429 for (next = &tep->handlers; *next; next = &(*next)->next) {
7446 * tep_alloc - create a tep handle
7450 struct tep_handle *tep = calloc(1, sizeof(*tep));
7452 if (tep) {
7453 tep->ref_count = 1;
7454 tep->host_bigendian = tep_is_bigendian();
7457 return tep;
7460 void tep_ref(struct tep_handle *tep)
7462 tep->ref_count++;
7465 int tep_get_ref(struct tep_handle *tep)
7467 if (tep)
7468 return tep->ref_count;
7512 * tep_free - free a tep handle
7513 * @tep: the tep handle to free
7515 void tep_free(struct tep_handle *tep)
7524 if (!tep)
7527 cmdlist = tep->cmdlist;
7528 funclist = tep->funclist;
7529 printklist = tep->printklist;
7531 tep->ref_count--;
7532 if (tep->ref_count)
7535 if (tep->cmdlines) {
7536 for (i = 0; i < tep->cmdline_count; i++)
7537 free(tep->cmdlines[i].comm);
7538 free(tep->cmdlines);
7548 if (tep->func_map) {
7549 for (i = 0; i < (int)tep->func_count; i++) {
7550 free(tep->func_map[i].func);
7551 free(tep->func_map[i].mod);
7553 free(tep->func_map);
7564 while (tep->func_handlers) {
7565 func_handler = tep->func_handlers;
7566 tep->func_handlers = func_handler->next;
7570 if (tep->printk_map) {
7571 for (i = 0; i < (int)tep->printk_count; i++)
7572 free(tep->printk_map[i].printk);
7573 free(tep->printk_map);
7583 for (i = 0; i < tep->nr_events; i++)
7584 free_tep_event(tep->events[i]);
7586 while (tep->handlers) {
7587 handle = tep->handlers;
7588 tep->handlers = handle->next;
7592 free(tep->events);
7593 free(tep->sort_events);
7594 free(tep->func_resolver);
7595 free_tep_plugin_paths(tep);
7597 free(tep);
7600 void tep_unref(struct tep_handle *tep)
7602 tep_free(tep);