17 struct timeval start, now, diff, maxtime;
22 maxtime.tv_usec = 50000;
24 err = gettimeofday(&start, NULL);
30 for (i = 0; i < 1000; i++)
33 err = gettimeofday(&now, NULL);
37 timersub(&now, &start, &diff);
38 if (timercmp(&diff, &maxtime, > ))
42 ts.tv_nsec = 50 * 1000 * 1000;
46 err = nanosleep(&ts, NULL);
67 if (event->
header.type == PERF_RECORD_COMM &&
68 (pid_t)event->
comm.
pid == getpid() &&
69 (pid_t)event->
comm.
tid == getpid() &&
70 strcmp(event->
comm.
comm, comm) == 0) {
89 if (!switch_tracking->
tids) {
90 switch_tracking->
tids = calloc(nr,
sizeof(pid_t));
91 if (!switch_tracking->
tids)
93 for (i = 0; i < nr; i++)
94 switch_tracking->
tids[i] = -1;
99 if (cpu >= switch_tracking->
nr_tids) {
102 addr = realloc(switch_tracking->
tids, nr *
sizeof(pid_t));
105 switch_tracking->
tids = addr;
106 for (i = switch_tracking->
nr_tids; i < nr; i++)
107 switch_tracking->
tids[i] = -1;
121 pid_t next_tid, prev_tid;
125 pr_debug(
"perf_evlist__parse_sample failed\n");
134 pr_debug3(
"sched_switch: cpu: %d prev_tid %d next_tid %d\n",
135 cpu, prev_tid, next_tid);
143 if (switch_tracking->
tids[cpu] != -1 &&
144 switch_tracking->
tids[cpu] != prev_tid) {
145 pr_debug(
"Missing sched_switch events\n");
148 switch_tracking->
tids[cpu] = next_tid;
168 if (event->
header.type == PERF_RECORD_SAMPLE)
171 if (event->
header.type == PERF_RECORD_COMM) {
174 err =
check_comm(switch_tracking, event,
"Test COMM 1", 0);
178 err =
check_comm(switch_tracking, event,
"Test COMM 2", 1);
182 err =
check_comm(switch_tracking, event,
"Test COMM 3", 2);
186 err =
check_comm(switch_tracking, event,
"Test COMM 4", 3);
191 pr_debug(
"Unexpected comm event\n");
200 struct list_head list;
217 list_add(&node->
list, events);
220 pr_debug(
"perf_evlist__parse_sample failed\n");
238 while (!list_empty(events)) {
240 list_del(&node->
list);
245 static int compar(
const void *a,
const void *b)
258 unsigned pos, cnt = 0;
264 for (i = 0; i < evlist->
nr_mmaps; i++) {
265 md = &evlist->
mmap[i];
279 events_array = calloc(cnt,
sizeof(
struct event_node));
287 list_for_each_entry(node, &
events, list)
288 events_array[pos++] = *node;
292 for (pos = 0; pos < cnt; pos++) {
301 pr_debug(
"%u events recorded\n", cnt);
322 .user_freq = UINT_MAX,
323 .user_interval = ULLONG_MAX,
339 pr_debug(
"thread_map__new failed!\n");
351 pr_debug(
"perf_evlist__new failed!\n");
360 pr_debug(
"Failed to parse event dummy:u\n");
369 pr_debug(
"Failed to parse event cycles:u\n");
384 pr_debug(
"Failed to parse event %s\n", sched_switch);
399 pr_debug(
"cycles event already at front");
404 pr_debug(
"Failed to move cycles event to front");
414 pr_debug(
"Failed to parse event dummy:u\n");
422 tracking_evsel->
attr.freq = 0;
423 tracking_evsel->
attr.sample_period = 1;
432 pr_debug(
"Front event no longer at front");
437 if (!tracking_evsel->
attr.mmap || !tracking_evsel->
attr.comm) {
438 pr_debug(
"Tracking event not tracking\n");
444 if (evsel != tracking_evsel) {
445 if (evsel->
attr.mmap || evsel->
attr.comm) {
446 pr_debug(
"Non-tracking event is tracking\n");
460 pr_debug(
"perf_evlist__mmap failed!\n");
468 pr_debug(
"perf_evlist__disable_event failed!\n");
478 comm =
"Test COMM 1";
479 err = prctl(
PR_SET_NAME, (
unsigned long)comm, 0, 0, 0);
487 pr_debug(
"perf_evlist__disable_event failed!\n");
491 comm =
"Test COMM 2";
492 err = prctl(
PR_SET_NAME, (
unsigned long)comm, 0, 0, 0);
504 comm =
"Test COMM 3";
505 err = prctl(
PR_SET_NAME, (
unsigned long)comm, 0, 0, 0);
513 pr_debug(
"perf_evlist__disable_event failed!\n");
517 comm =
"Test COMM 4";
518 err = prctl(
PR_SET_NAME, (
unsigned long)comm, 0, 0, 0);
551 pr_debug(
"Missing cycles events\n");
557 pr_debug(
"cycles events even though event was disabled\n");
563 pr_debug(
"Missing cycles events\n");
void perf_evlist__set_maps(struct perf_evlist *evlist, struct cpu_map *cpus, struct thread_map *threads)
void perf_mmap__consume(struct perf_mmap *map)
struct perf_probe_event events[MAX_PROBES]
static void sched_switch(struct timechart *tchart, int cpu, u64 timestamp, int prev_pid, int next_pid, u64 prev_state, const char *backtrace)
static LIST_HEAD(page_alloc_sort_input)
void perf_evlist__enable(struct perf_evlist *evlist)
void perf_evlist__delete(struct perf_evlist *evlist)
#define perf_evsel__set_sample_bit(evsel, bit)
static int spin_sleep(void)
int perf_evsel__disable(struct perf_evsel *evsel)
int parse_events(struct perf_evlist *evlist, const char *str, struct parse_events_error *err)
struct perf_evsel * cycles_evsel
bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str)
void cpu_map__put(struct cpu_map *map)
void perf_evlist__set_tracking_event(struct perf_evlist *evlist, struct perf_evsel *tracking_evsel)
int perf_mmap__read_init(struct perf_mmap *map)
static int compar(const void *a, const void *b)
struct perf_evlist * evlist
#define pr_debug(fmt,...)
int perf_evlist__open(struct perf_evlist *evlist)
#define evlist__for_each_entry(evlist, evsel)
int perf_evlist__parse_sample(struct perf_evlist *evlist, union perf_event *event, struct perf_sample *sample)
static int check_cpu(struct switch_tracking *switch_tracking, int cpu)
struct perf_evsel * perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id)
static int process_events(struct perf_evlist *evlist, struct switch_tracking *switch_tracking)
void perf_evlist__to_front(struct perf_evlist *evlist, struct perf_evsel *move_evsel)
u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample, const char *name)
void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts, struct callchain_param *callchain)
int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages)
static int process_event(struct perf_evlist *evlist, union perf_event *event, struct switch_tracking *switch_tracking)
void perf_mmap__read_done(struct perf_mmap *map)
struct perf_event_header header
static struct perf_evsel * perf_evlist__first(struct perf_evlist *evlist)
union perf_event * perf_mmap__read_event(struct perf_mmap *map)
void perf_evlist__disable(struct perf_evlist *evlist)
int cycles_between_comm_2_and_comm_3
int perf_evsel__enable(struct perf_evsel *evsel)
static int check_comm(struct switch_tracking *switch_tracking, union perf_event *event, const char *comm, int nr)
static int process_sample_event(struct perf_evlist *evlist, union perf_event *event, struct switch_tracking *switch_tracking)
void thread_map__put(struct thread_map *map)
struct perf_evsel * switch_evsel
static void free_event_nodes(struct list_head *events)
static struct perf_evsel * perf_evlist__last(struct perf_evlist *evlist)
struct thread_map * thread_map__new(pid_t pid, pid_t tid, uid_t uid)
struct cpu_map * cpu_map__new(const char *cpu_list)
#define pr_debug3(fmt,...)
int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_unused)
struct perf_evlist * perf_evlist__new(void)
struct perf_event_attr attr
static int add_event(struct perf_evlist *evlist, struct list_head *events, union perf_event *event)