diff options
author | Changbin Du <changbin.du@intel.com> | 2018-03-05 22:37:36 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-03-07 08:22:26 -0500 |
commit | 8640da9f4fea88c8fbb44ff63fde4000203cb7d1 (patch) | |
tree | 31429a8e3ff5df89e82db079284e04497cd876f2 /tools/perf/builtin-sched.c | |
parent | 923a0fb332f8ee49b063df07129b2686f78ec9c3 (diff) |
perf sched: Move thread::shortname to thread_runtime
The thread::shortname only used by sched command, so move it to sched
private structure.
Signed-off-by: Changbin Du <changbin.du@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1520307457-23668-2-git-send-email-changbin.du@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-sched.c')
-rw-r--r-- | tools/perf/builtin-sched.c | 95 |
1 files changed, 55 insertions, 40 deletions
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 83283fedb00f..0a632a6b6228 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c | |||
@@ -254,6 +254,8 @@ struct thread_runtime { | |||
254 | u64 total_delay_time; | 254 | u64 total_delay_time; |
255 | 255 | ||
256 | int last_state; | 256 | int last_state; |
257 | |||
258 | char shortname[3]; | ||
257 | u64 migrations; | 259 | u64 migrations; |
258 | }; | 260 | }; |
259 | 261 | ||
@@ -897,6 +899,37 @@ struct sort_dimension { | |||
897 | struct list_head list; | 899 | struct list_head list; |
898 | }; | 900 | }; |
899 | 901 | ||
902 | /* | ||
903 | * handle runtime stats saved per thread | ||
904 | */ | ||
905 | static struct thread_runtime *thread__init_runtime(struct thread *thread) | ||
906 | { | ||
907 | struct thread_runtime *r; | ||
908 | |||
909 | r = zalloc(sizeof(struct thread_runtime)); | ||
910 | if (!r) | ||
911 | return NULL; | ||
912 | |||
913 | init_stats(&r->run_stats); | ||
914 | thread__set_priv(thread, r); | ||
915 | |||
916 | return r; | ||
917 | } | ||
918 | |||
919 | static struct thread_runtime *thread__get_runtime(struct thread *thread) | ||
920 | { | ||
921 | struct thread_runtime *tr; | ||
922 | |||
923 | tr = thread__priv(thread); | ||
924 | if (tr == NULL) { | ||
925 | tr = thread__init_runtime(thread); | ||
926 | if (tr == NULL) | ||
927 | pr_debug("Failed to malloc memory for runtime data.\n"); | ||
928 | } | ||
929 | |||
930 | return tr; | ||
931 | } | ||
932 | |||
900 | static int | 933 | static int |
901 | thread_lat_cmp(struct list_head *list, struct work_atoms *l, struct work_atoms *r) | 934 | thread_lat_cmp(struct list_head *list, struct work_atoms *l, struct work_atoms *r) |
902 | { | 935 | { |
@@ -1480,6 +1513,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, | |||
1480 | { | 1513 | { |
1481 | const u32 next_pid = perf_evsel__intval(evsel, sample, "next_pid"); | 1514 | const u32 next_pid = perf_evsel__intval(evsel, sample, "next_pid"); |
1482 | struct thread *sched_in; | 1515 | struct thread *sched_in; |
1516 | struct thread_runtime *tr; | ||
1483 | int new_shortname; | 1517 | int new_shortname; |
1484 | u64 timestamp0, timestamp = sample->time; | 1518 | u64 timestamp0, timestamp = sample->time; |
1485 | s64 delta; | 1519 | s64 delta; |
@@ -1519,22 +1553,28 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, | |||
1519 | if (sched_in == NULL) | 1553 | if (sched_in == NULL) |
1520 | return -1; | 1554 | return -1; |
1521 | 1555 | ||
1556 | tr = thread__get_runtime(sched_in); | ||
1557 | if (tr == NULL) { | ||
1558 | thread__put(sched_in); | ||
1559 | return -1; | ||
1560 | } | ||
1561 | |||
1522 | sched->curr_thread[this_cpu] = thread__get(sched_in); | 1562 | sched->curr_thread[this_cpu] = thread__get(sched_in); |
1523 | 1563 | ||
1524 | printf(" "); | 1564 | printf(" "); |
1525 | 1565 | ||
1526 | new_shortname = 0; | 1566 | new_shortname = 0; |
1527 | if (!sched_in->shortname[0]) { | 1567 | if (!tr->shortname[0]) { |
1528 | if (!strcmp(thread__comm_str(sched_in), "swapper")) { | 1568 | if (!strcmp(thread__comm_str(sched_in), "swapper")) { |
1529 | /* | 1569 | /* |
1530 | * Don't allocate a letter-number for swapper:0 | 1570 | * Don't allocate a letter-number for swapper:0 |
1531 | * as a shortname. Instead, we use '.' for it. | 1571 | * as a shortname. Instead, we use '.' for it. |
1532 | */ | 1572 | */ |
1533 | sched_in->shortname[0] = '.'; | 1573 | tr->shortname[0] = '.'; |
1534 | sched_in->shortname[1] = ' '; | 1574 | tr->shortname[1] = ' '; |
1535 | } else { | 1575 | } else { |
1536 | sched_in->shortname[0] = sched->next_shortname1; | 1576 | tr->shortname[0] = sched->next_shortname1; |
1537 | sched_in->shortname[1] = sched->next_shortname2; | 1577 | tr->shortname[1] = sched->next_shortname2; |
1538 | 1578 | ||
1539 | if (sched->next_shortname1 < 'Z') { | 1579 | if (sched->next_shortname1 < 'Z') { |
1540 | sched->next_shortname1++; | 1580 | sched->next_shortname1++; |
@@ -1552,6 +1592,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, | |||
1552 | for (i = 0; i < cpus_nr; i++) { | 1592 | for (i = 0; i < cpus_nr; i++) { |
1553 | int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i; | 1593 | int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i; |
1554 | struct thread *curr_thread = sched->curr_thread[cpu]; | 1594 | struct thread *curr_thread = sched->curr_thread[cpu]; |
1595 | struct thread_runtime *curr_tr; | ||
1555 | const char *pid_color = color; | 1596 | const char *pid_color = color; |
1556 | const char *cpu_color = color; | 1597 | const char *cpu_color = color; |
1557 | 1598 | ||
@@ -1569,9 +1610,14 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, | |||
1569 | else | 1610 | else |
1570 | color_fprintf(stdout, cpu_color, "*"); | 1611 | color_fprintf(stdout, cpu_color, "*"); |
1571 | 1612 | ||
1572 | if (sched->curr_thread[cpu]) | 1613 | if (sched->curr_thread[cpu]) { |
1573 | color_fprintf(stdout, pid_color, "%2s ", sched->curr_thread[cpu]->shortname); | 1614 | curr_tr = thread__get_runtime(sched->curr_thread[cpu]); |
1574 | else | 1615 | if (curr_tr == NULL) { |
1616 | thread__put(sched_in); | ||
1617 | return -1; | ||
1618 | } | ||
1619 | color_fprintf(stdout, pid_color, "%2s ", curr_tr->shortname); | ||
1620 | } else | ||
1575 | color_fprintf(stdout, color, " "); | 1621 | color_fprintf(stdout, color, " "); |
1576 | } | 1622 | } |
1577 | 1623 | ||
@@ -1587,7 +1633,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel, | |||
1587 | pid_color = COLOR_PIDS; | 1633 | pid_color = COLOR_PIDS; |
1588 | 1634 | ||
1589 | color_fprintf(stdout, pid_color, "%s => %s:%d", | 1635 | color_fprintf(stdout, pid_color, "%s => %s:%d", |
1590 | sched_in->shortname, thread__comm_str(sched_in), sched_in->tid); | 1636 | tr->shortname, thread__comm_str(sched_in), sched_in->tid); |
1591 | } | 1637 | } |
1592 | 1638 | ||
1593 | if (sched->map.comp && new_cpu) | 1639 | if (sched->map.comp && new_cpu) |
@@ -2200,37 +2246,6 @@ static void save_idle_callchain(struct idle_thread_runtime *itr, | |||
2200 | callchain_cursor__copy(&itr->cursor, &callchain_cursor); | 2246 | callchain_cursor__copy(&itr->cursor, &callchain_cursor); |
2201 | } | 2247 | } |
2202 | 2248 | ||
2203 | /* | ||
2204 | * handle runtime stats saved per thread | ||
2205 | */ | ||
2206 | static struct thread_runtime *thread__init_runtime(struct thread *thread) | ||
2207 | { | ||
2208 | struct thread_runtime *r; | ||
2209 | |||
2210 | r = zalloc(sizeof(struct thread_runtime)); | ||
2211 | if (!r) | ||
2212 | return NULL; | ||
2213 | |||
2214 | init_stats(&r->run_stats); | ||
2215 | thread__set_priv(thread, r); | ||
2216 | |||
2217 | return r; | ||
2218 | } | ||
2219 | |||
2220 | static struct thread_runtime *thread__get_runtime(struct thread *thread) | ||
2221 | { | ||
2222 | struct thread_runtime *tr; | ||
2223 | |||
2224 | tr = thread__priv(thread); | ||
2225 | if (tr == NULL) { | ||
2226 | tr = thread__init_runtime(thread); | ||
2227 | if (tr == NULL) | ||
2228 | pr_debug("Failed to malloc memory for runtime data.\n"); | ||
2229 | } | ||
2230 | |||
2231 | return tr; | ||
2232 | } | ||
2233 | |||
2234 | static struct thread *timehist_get_thread(struct perf_sched *sched, | 2249 | static struct thread *timehist_get_thread(struct perf_sched *sched, |
2235 | struct perf_sample *sample, | 2250 | struct perf_sample *sample, |
2236 | struct machine *machine, | 2251 | struct machine *machine, |