aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-timechart.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-timechart.c')
-rw-r--r--tools/perf/builtin-timechart.c119
1 files changed, 7 insertions, 112 deletions
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 0d4d8ff7914b..5a52ed9fc10b 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -21,7 +21,6 @@
21#include "util/cache.h" 21#include "util/cache.h"
22#include <linux/rbtree.h> 22#include <linux/rbtree.h>
23#include "util/symbol.h" 23#include "util/symbol.h"
24#include "util/string.h"
25#include "util/callchain.h" 24#include "util/callchain.h"
26#include "util/strlist.h" 25#include "util/strlist.h"
27 26
@@ -43,7 +42,7 @@ static u64 turbo_frequency;
43 42
44static u64 first_time, last_time; 43static u64 first_time, last_time;
45 44
46static int power_only; 45static bool power_only;
47 46
48 47
49struct per_pid; 48struct per_pid;
@@ -78,8 +77,6 @@ struct per_pid {
78 77
79 struct per_pidcomm *all; 78 struct per_pidcomm *all;
80 struct per_pidcomm *current; 79 struct per_pidcomm *current;
81
82 int painted;
83}; 80};
84 81
85 82
@@ -146,9 +143,6 @@ struct wake_event {
146static struct power_event *power_events; 143static struct power_event *power_events;
147static struct wake_event *wake_events; 144static struct wake_event *wake_events;
148 145
149struct sample_wrapper *all_samples;
150
151
152struct process_filter; 146struct process_filter;
153struct process_filter { 147struct process_filter {
154 char *name; 148 char *name;
@@ -569,88 +563,6 @@ static void end_sample_processing(void)
569 } 563 }
570} 564}
571 565
572static u64 sample_time(event_t *event, const struct perf_session *session)
573{
574 int cursor;
575
576 cursor = 0;
577 if (session->sample_type & PERF_SAMPLE_IP)
578 cursor++;
579 if (session->sample_type & PERF_SAMPLE_TID)
580 cursor++;
581 if (session->sample_type & PERF_SAMPLE_TIME)
582 return event->sample.array[cursor];
583 return 0;
584}
585
586
587/*
588 * We first queue all events, sorted backwards by insertion.
589 * The order will get flipped later.
590 */
591static int queue_sample_event(event_t *event, struct perf_session *session)
592{
593 struct sample_wrapper *copy, *prev;
594 int size;
595
596 size = event->sample.header.size + sizeof(struct sample_wrapper) + 8;
597
598 copy = malloc(size);
599 if (!copy)
600 return 1;
601
602 memset(copy, 0, size);
603
604 copy->next = NULL;
605 copy->timestamp = sample_time(event, session);
606
607 memcpy(&copy->data, event, event->sample.header.size);
608
609 /* insert in the right place in the list */
610
611 if (!all_samples) {
612 /* first sample ever */
613 all_samples = copy;
614 return 0;
615 }
616
617 if (all_samples->timestamp < copy->timestamp) {
618 /* insert at the head of the list */
619 copy->next = all_samples;
620 all_samples = copy;
621 return 0;
622 }
623
624 prev = all_samples;
625 while (prev->next) {
626 if (prev->next->timestamp < copy->timestamp) {
627 copy->next = prev->next;
628 prev->next = copy;
629 return 0;
630 }
631 prev = prev->next;
632 }
633 /* insert at the end of the list */
634 prev->next = copy;
635
636 return 0;
637}
638
639static void sort_queued_samples(void)
640{
641 struct sample_wrapper *cursor, *next;
642
643 cursor = all_samples;
644 all_samples = NULL;
645
646 while (cursor) {
647 next = cursor->next;
648 cursor->next = all_samples;
649 all_samples = cursor;
650 cursor = next;
651 }
652}
653
654/* 566/*
655 * Sort the pid datastructure 567 * Sort the pid datastructure
656 */ 568 */
@@ -1014,31 +926,17 @@ static void write_svg_file(const char *filename)
1014 svg_close(); 926 svg_close();
1015} 927}
1016 928
1017static void process_samples(struct perf_session *session)
1018{
1019 struct sample_wrapper *cursor;
1020 event_t *event;
1021
1022 sort_queued_samples();
1023
1024 cursor = all_samples;
1025 while (cursor) {
1026 event = (void *)&cursor->data;
1027 cursor = cursor->next;
1028 process_sample_event(event, session);
1029 }
1030}
1031
1032static struct perf_event_ops event_ops = { 929static struct perf_event_ops event_ops = {
1033 .comm = process_comm_event, 930 .comm = process_comm_event,
1034 .fork = process_fork_event, 931 .fork = process_fork_event,
1035 .exit = process_exit_event, 932 .exit = process_exit_event,
1036 .sample = queue_sample_event, 933 .sample = process_sample_event,
934 .ordered_samples = true,
1037}; 935};
1038 936
1039static int __cmd_timechart(void) 937static int __cmd_timechart(void)
1040{ 938{
1041 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0); 939 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
1042 int ret = -EINVAL; 940 int ret = -EINVAL;
1043 941
1044 if (session == NULL) 942 if (session == NULL)
@@ -1051,8 +949,6 @@ static int __cmd_timechart(void)
1051 if (ret) 949 if (ret)
1052 goto out_delete; 950 goto out_delete;
1053 951
1054 process_samples(session);
1055
1056 end_sample_processing(); 952 end_sample_processing();
1057 953
1058 sort_pids(); 954 sort_pids();
@@ -1075,7 +971,6 @@ static const char *record_args[] = {
1075 "record", 971 "record",
1076 "-a", 972 "-a",
1077 "-R", 973 "-R",
1078 "-M",
1079 "-f", 974 "-f",
1080 "-c", "1", 975 "-c", "1",
1081 "-e", "power:power_start", 976 "-e", "power:power_start",