hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/tools/perf/builtin-timechart.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * builtin-timechart.c - make an svg timechart of system activity
34 *
....@@ -5,35 +6,27 @@
56 *
67 * Authors:
78 * Arjan van de Ven <arjan@linux.intel.com>
8
- *
9
- * This program is free software; you can redistribute it and/or
10
- * modify it under the terms of the GNU General Public License
11
- * as published by the Free Software Foundation; version 2
12
- * of the License.
139 */
1410
1511 #include <errno.h>
1612 #include <inttypes.h>
17
-#include <traceevent/event-parse.h>
1813
1914 #include "builtin.h"
20
-
21
-#include "util/util.h"
22
-
2315 #include "util/color.h"
2416 #include <linux/list.h>
25
-#include "util/cache.h"
26
-#include "util/evlist.h"
17
+#include "util/evlist.h" // for struct evsel_str_handler
2718 #include "util/evsel.h"
2819 #include <linux/kernel.h>
2920 #include <linux/rbtree.h>
3021 #include <linux/time64.h>
22
+#include <linux/zalloc.h>
3123 #include "util/symbol.h"
3224 #include "util/thread.h"
3325 #include "util/callchain.h"
3426
3527 #include "perf.h"
3628 #include "util/header.h"
29
+#include <subcmd/pager.h>
3730 #include <subcmd/parse-options.h>
3831 #include "util/parse-events.h"
3932 #include "util/event.h"
....@@ -42,6 +35,7 @@
4235 #include "util/tool.h"
4336 #include "util/data.h"
4437 #include "util/debug.h"
38
+#include <linux/err.h>
4539
4640 #ifdef LACKS_OPEN_MEMSTREAM_PROTOTYPE
4741 FILE *open_memstream(char **ptr, size_t *sizeloc);
....@@ -134,7 +128,7 @@
134128 struct sample_wrapper *next;
135129
136130 u64 timestamp;
137
- unsigned char data[0];
131
+ unsigned char data[];
138132 };
139133
140134 #define TYPE_NONE 0
....@@ -551,19 +545,19 @@
551545 }
552546
553547 typedef int (*tracepoint_handler)(struct timechart *tchart,
554
- struct perf_evsel *evsel,
548
+ struct evsel *evsel,
555549 struct perf_sample *sample,
556550 const char *backtrace);
557551
558552 static int process_sample_event(struct perf_tool *tool,
559553 union perf_event *event,
560554 struct perf_sample *sample,
561
- struct perf_evsel *evsel,
555
+ struct evsel *evsel,
562556 struct machine *machine)
563557 {
564558 struct timechart *tchart = container_of(tool, struct timechart, tool);
565559
566
- if (evsel->attr.sample_type & PERF_SAMPLE_TIME) {
560
+ if (evsel->core.attr.sample_type & PERF_SAMPLE_TIME) {
567561 if (!tchart->first_time || tchart->first_time > sample->time)
568562 tchart->first_time = sample->time;
569563 if (tchart->last_time < sample->time)
....@@ -581,12 +575,12 @@
581575
582576 static int
583577 process_sample_cpu_idle(struct timechart *tchart __maybe_unused,
584
- struct perf_evsel *evsel,
578
+ struct evsel *evsel,
585579 struct perf_sample *sample,
586580 const char *backtrace __maybe_unused)
587581 {
588
- u32 state = perf_evsel__intval(evsel, sample, "state");
589
- u32 cpu_id = perf_evsel__intval(evsel, sample, "cpu_id");
582
+ u32 state = evsel__intval(evsel, sample, "state");
583
+ u32 cpu_id = evsel__intval(evsel, sample, "cpu_id");
590584
591585 if (state == (u32)PWR_EVENT_EXIT)
592586 c_state_end(tchart, cpu_id, sample->time);
....@@ -597,12 +591,12 @@
597591
598592 static int
599593 process_sample_cpu_frequency(struct timechart *tchart,
600
- struct perf_evsel *evsel,
594
+ struct evsel *evsel,
601595 struct perf_sample *sample,
602596 const char *backtrace __maybe_unused)
603597 {
604
- u32 state = perf_evsel__intval(evsel, sample, "state");
605
- u32 cpu_id = perf_evsel__intval(evsel, sample, "cpu_id");
598
+ u32 state = evsel__intval(evsel, sample, "state");
599
+ u32 cpu_id = evsel__intval(evsel, sample, "cpu_id");
606600
607601 p_state_change(tchart, cpu_id, sample->time, state);
608602 return 0;
....@@ -610,13 +604,13 @@
610604
611605 static int
612606 process_sample_sched_wakeup(struct timechart *tchart,
613
- struct perf_evsel *evsel,
607
+ struct evsel *evsel,
614608 struct perf_sample *sample,
615609 const char *backtrace)
616610 {
617
- u8 flags = perf_evsel__intval(evsel, sample, "common_flags");
618
- int waker = perf_evsel__intval(evsel, sample, "common_pid");
619
- int wakee = perf_evsel__intval(evsel, sample, "pid");
611
+ u8 flags = evsel__intval(evsel, sample, "common_flags");
612
+ int waker = evsel__intval(evsel, sample, "common_pid");
613
+ int wakee = evsel__intval(evsel, sample, "pid");
620614
621615 sched_wakeup(tchart, sample->cpu, sample->time, waker, wakee, flags, backtrace);
622616 return 0;
....@@ -624,13 +618,13 @@
624618
625619 static int
626620 process_sample_sched_switch(struct timechart *tchart,
627
- struct perf_evsel *evsel,
621
+ struct evsel *evsel,
628622 struct perf_sample *sample,
629623 const char *backtrace)
630624 {
631
- int prev_pid = perf_evsel__intval(evsel, sample, "prev_pid");
632
- int next_pid = perf_evsel__intval(evsel, sample, "next_pid");
633
- u64 prev_state = perf_evsel__intval(evsel, sample, "prev_state");
625
+ int prev_pid = evsel__intval(evsel, sample, "prev_pid");
626
+ int next_pid = evsel__intval(evsel, sample, "next_pid");
627
+ u64 prev_state = evsel__intval(evsel, sample, "prev_state");
634628
635629 sched_switch(tchart, sample->cpu, sample->time, prev_pid, next_pid,
636630 prev_state, backtrace);
....@@ -640,12 +634,12 @@
640634 #ifdef SUPPORT_OLD_POWER_EVENTS
641635 static int
642636 process_sample_power_start(struct timechart *tchart __maybe_unused,
643
- struct perf_evsel *evsel,
637
+ struct evsel *evsel,
644638 struct perf_sample *sample,
645639 const char *backtrace __maybe_unused)
646640 {
647
- u64 cpu_id = perf_evsel__intval(evsel, sample, "cpu_id");
648
- u64 value = perf_evsel__intval(evsel, sample, "value");
641
+ u64 cpu_id = evsel__intval(evsel, sample, "cpu_id");
642
+ u64 value = evsel__intval(evsel, sample, "value");
649643
650644 c_state_start(cpu_id, sample->time, value);
651645 return 0;
....@@ -653,7 +647,7 @@
653647
654648 static int
655649 process_sample_power_end(struct timechart *tchart,
656
- struct perf_evsel *evsel __maybe_unused,
650
+ struct evsel *evsel __maybe_unused,
657651 struct perf_sample *sample,
658652 const char *backtrace __maybe_unused)
659653 {
....@@ -663,12 +657,12 @@
663657
664658 static int
665659 process_sample_power_frequency(struct timechart *tchart,
666
- struct perf_evsel *evsel,
660
+ struct evsel *evsel,
667661 struct perf_sample *sample,
668662 const char *backtrace __maybe_unused)
669663 {
670
- u64 cpu_id = perf_evsel__intval(evsel, sample, "cpu_id");
671
- u64 value = perf_evsel__intval(evsel, sample, "value");
664
+ u64 cpu_id = evsel__intval(evsel, sample, "cpu_id");
665
+ u64 value = evsel__intval(evsel, sample, "value");
672666
673667 p_state_change(tchart, cpu_id, sample->time, value);
674668 return 0;
....@@ -846,120 +840,120 @@
846840
847841 static int
848842 process_enter_read(struct timechart *tchart,
849
- struct perf_evsel *evsel,
843
+ struct evsel *evsel,
850844 struct perf_sample *sample)
851845 {
852
- long fd = perf_evsel__intval(evsel, sample, "fd");
846
+ long fd = evsel__intval(evsel, sample, "fd");
853847 return pid_begin_io_sample(tchart, sample->tid, IOTYPE_READ,
854848 sample->time, fd);
855849 }
856850
857851 static int
858852 process_exit_read(struct timechart *tchart,
859
- struct perf_evsel *evsel,
853
+ struct evsel *evsel,
860854 struct perf_sample *sample)
861855 {
862
- long ret = perf_evsel__intval(evsel, sample, "ret");
856
+ long ret = evsel__intval(evsel, sample, "ret");
863857 return pid_end_io_sample(tchart, sample->tid, IOTYPE_READ,
864858 sample->time, ret);
865859 }
866860
867861 static int
868862 process_enter_write(struct timechart *tchart,
869
- struct perf_evsel *evsel,
863
+ struct evsel *evsel,
870864 struct perf_sample *sample)
871865 {
872
- long fd = perf_evsel__intval(evsel, sample, "fd");
866
+ long fd = evsel__intval(evsel, sample, "fd");
873867 return pid_begin_io_sample(tchart, sample->tid, IOTYPE_WRITE,
874868 sample->time, fd);
875869 }
876870
877871 static int
878872 process_exit_write(struct timechart *tchart,
879
- struct perf_evsel *evsel,
873
+ struct evsel *evsel,
880874 struct perf_sample *sample)
881875 {
882
- long ret = perf_evsel__intval(evsel, sample, "ret");
876
+ long ret = evsel__intval(evsel, sample, "ret");
883877 return pid_end_io_sample(tchart, sample->tid, IOTYPE_WRITE,
884878 sample->time, ret);
885879 }
886880
887881 static int
888882 process_enter_sync(struct timechart *tchart,
889
- struct perf_evsel *evsel,
883
+ struct evsel *evsel,
890884 struct perf_sample *sample)
891885 {
892
- long fd = perf_evsel__intval(evsel, sample, "fd");
886
+ long fd = evsel__intval(evsel, sample, "fd");
893887 return pid_begin_io_sample(tchart, sample->tid, IOTYPE_SYNC,
894888 sample->time, fd);
895889 }
896890
897891 static int
898892 process_exit_sync(struct timechart *tchart,
899
- struct perf_evsel *evsel,
893
+ struct evsel *evsel,
900894 struct perf_sample *sample)
901895 {
902
- long ret = perf_evsel__intval(evsel, sample, "ret");
896
+ long ret = evsel__intval(evsel, sample, "ret");
903897 return pid_end_io_sample(tchart, sample->tid, IOTYPE_SYNC,
904898 sample->time, ret);
905899 }
906900
907901 static int
908902 process_enter_tx(struct timechart *tchart,
909
- struct perf_evsel *evsel,
903
+ struct evsel *evsel,
910904 struct perf_sample *sample)
911905 {
912
- long fd = perf_evsel__intval(evsel, sample, "fd");
906
+ long fd = evsel__intval(evsel, sample, "fd");
913907 return pid_begin_io_sample(tchart, sample->tid, IOTYPE_TX,
914908 sample->time, fd);
915909 }
916910
917911 static int
918912 process_exit_tx(struct timechart *tchart,
919
- struct perf_evsel *evsel,
913
+ struct evsel *evsel,
920914 struct perf_sample *sample)
921915 {
922
- long ret = perf_evsel__intval(evsel, sample, "ret");
916
+ long ret = evsel__intval(evsel, sample, "ret");
923917 return pid_end_io_sample(tchart, sample->tid, IOTYPE_TX,
924918 sample->time, ret);
925919 }
926920
927921 static int
928922 process_enter_rx(struct timechart *tchart,
929
- struct perf_evsel *evsel,
923
+ struct evsel *evsel,
930924 struct perf_sample *sample)
931925 {
932
- long fd = perf_evsel__intval(evsel, sample, "fd");
926
+ long fd = evsel__intval(evsel, sample, "fd");
933927 return pid_begin_io_sample(tchart, sample->tid, IOTYPE_RX,
934928 sample->time, fd);
935929 }
936930
937931 static int
938932 process_exit_rx(struct timechart *tchart,
939
- struct perf_evsel *evsel,
933
+ struct evsel *evsel,
940934 struct perf_sample *sample)
941935 {
942
- long ret = perf_evsel__intval(evsel, sample, "ret");
936
+ long ret = evsel__intval(evsel, sample, "ret");
943937 return pid_end_io_sample(tchart, sample->tid, IOTYPE_RX,
944938 sample->time, ret);
945939 }
946940
947941 static int
948942 process_enter_poll(struct timechart *tchart,
949
- struct perf_evsel *evsel,
943
+ struct evsel *evsel,
950944 struct perf_sample *sample)
951945 {
952
- long fd = perf_evsel__intval(evsel, sample, "fd");
946
+ long fd = evsel__intval(evsel, sample, "fd");
953947 return pid_begin_io_sample(tchart, sample->tid, IOTYPE_POLL,
954948 sample->time, fd);
955949 }
956950
957951 static int
958952 process_exit_poll(struct timechart *tchart,
959
- struct perf_evsel *evsel,
953
+ struct evsel *evsel,
960954 struct perf_sample *sample)
961955 {
962
- long ret = perf_evsel__intval(evsel, sample, "ret");
956
+ long ret = evsel__intval(evsel, sample, "ret");
963957 return pid_end_io_sample(tchart, sample->tid, IOTYPE_POLL,
964958 sample->time, ret);
965959 }
....@@ -1524,10 +1518,7 @@
15241518 if (!tchart->topology)
15251519 break;
15261520
1527
- if (svg_build_topology_map(ph->env.sibling_cores,
1528
- ph->env.nr_sibling_cores,
1529
- ph->env.sibling_threads,
1530
- ph->env.nr_sibling_threads))
1521
+ if (svg_build_topology_map(&ph->env))
15311522 fprintf(stderr, "problem building topology\n");
15321523 break;
15331524
....@@ -1540,7 +1531,7 @@
15401531
15411532 static int __cmd_timechart(struct timechart *tchart, const char *output_name)
15421533 {
1543
- const struct perf_evsel_str_handler power_tracepoints[] = {
1534
+ const struct evsel_str_handler power_tracepoints[] = {
15441535 { "power:cpu_idle", process_sample_cpu_idle },
15451536 { "power:cpu_frequency", process_sample_cpu_frequency },
15461537 { "sched:sched_wakeup", process_sample_sched_wakeup },
....@@ -1602,19 +1593,17 @@
16021593 { "syscalls:sys_exit_select", process_exit_poll },
16031594 };
16041595 struct perf_data data = {
1605
- .file = {
1606
- .path = input_name,
1607
- },
1608
- .mode = PERF_DATA_MODE_READ,
1609
- .force = tchart->force,
1596
+ .path = input_name,
1597
+ .mode = PERF_DATA_MODE_READ,
1598
+ .force = tchart->force,
16101599 };
16111600
16121601 struct perf_session *session = perf_session__new(&data, false,
16131602 &tchart->tool);
16141603 int ret = -EINVAL;
16151604
1616
- if (session == NULL)
1617
- return -1;
1605
+ if (IS_ERR(session))
1606
+ return PTR_ERR(session);
16181607
16191608 symbol__init(&session->header.env);
16201609