Skip to content

Commit b629f3e

Browse files
namhyungacmel
authored andcommitted
perf report: Add 'cgroup' sort key
The cgroup sort key is to show cgroup membership of each task. Currently it shows full path in the cgroupfs (not relative to the root of cgroup namespace) since it'd be more intuitive IMHO. Otherwise root cgroup in different namespaces will all show same name - "/". The cgroup sort key should come before cgroup_id otherwise sort_dimension__add() will match it to cgroup_id as it only matches with the given substring. For example it will look like following. Note that record patch adding --all-cgroups patch will come later. $ perf record -a --namespace --all-cgroups cgtest [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.208 MB perf.data (4090 samples) ] $ perf report -s cgroup_id,cgroup,pid ... # Overhead cgroup id (dev/inode) Cgroup Pid:Command # ........ ..................... .......... ............... # 93.96% 0/0x0 / 0:swapper 1.25% 3/0xeffffffb / 278:looper0 0.86% 3/0xf000015f /sub/cgrp1 280:cgtest 0.37% 3/0xf0000160 /sub/cgrp2 281:cgtest 0.34% 3/0xf0000163 /sub/cgrp3 282:cgtest 0.22% 3/0xeffffffb /sub 278:looper0 0.20% 3/0xeffffffb / 280:cgtest 0.15% 3/0xf0000163 /sub/cgrp3 285:looper3 Signed-off-by: Namhyung Kim <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d1277aa commit b629f3e

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

tools/perf/Documentation/perf-report.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ OPTIONS
9595
abort cost. This is the global weight.
9696
- local_weight: Local weight version of the weight above.
9797
- cgroup_id: ID derived from cgroup namespace device and inode numbers.
98+
- cgroup: cgroup pathname in the cgroupfs.
9899
- transaction: Transaction abort flags.
99100
- overhead: Overhead percentage of sample
100101
- overhead_sys: Overhead percentage of sample running in system mode

tools/perf/util/hist.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "mem-events.h"
1111
#include "session.h"
1212
#include "namespaces.h"
13+
#include "cgroup.h"
1314
#include "sort.h"
1415
#include "units.h"
1516
#include "evlist.h"
@@ -194,6 +195,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
194195
hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO);
195196
}
196197

198+
hists__new_col_len(hists, HISTC_CGROUP, 6);
197199
hists__new_col_len(hists, HISTC_CGROUP_ID, 20);
198200
hists__new_col_len(hists, HISTC_CPU, 3);
199201
hists__new_col_len(hists, HISTC_SOCKET, 6);
@@ -222,6 +224,16 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
222224

223225
if (h->trace_output)
224226
hists__new_col_len(hists, HISTC_TRACE, strlen(h->trace_output));
227+
228+
if (h->cgroup) {
229+
const char *cgrp_name = "unknown";
230+
struct cgroup *cgrp = cgroup__find(h->ms.maps->machine->env,
231+
h->cgroup);
232+
if (cgrp != NULL)
233+
cgrp_name = cgrp->name;
234+
235+
hists__new_col_len(hists, HISTC_CGROUP, strlen(cgrp_name));
236+
}
225237
}
226238

227239
void hists__output_recalc_col_len(struct hists *hists, int max_rows)
@@ -691,6 +703,7 @@ __hists__add_entry(struct hists *hists,
691703
.dev = ns ? ns->link_info[CGROUP_NS_INDEX].dev : 0,
692704
.ino = ns ? ns->link_info[CGROUP_NS_INDEX].ino : 0,
693705
},
706+
.cgroup = sample->cgroup,
694707
.ms = {
695708
.maps = al->maps,
696709
.map = al->map,

tools/perf/util/hist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum hist_column {
3838
HISTC_THREAD,
3939
HISTC_COMM,
4040
HISTC_CGROUP_ID,
41+
HISTC_CGROUP,
4142
HISTC_PARENT,
4243
HISTC_CPU,
4344
HISTC_SOCKET,

tools/perf/util/sort.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "cacheline.h"
1313
#include "comm.h"
1414
#include "map.h"
15+
#include "maps.h"
1516
#include "symbol.h"
1617
#include "map_symbol.h"
1718
#include "branch.h"
@@ -25,6 +26,8 @@
2526
#include "mem-events.h"
2627
#include "annotate.h"
2728
#include "time-utils.h"
29+
#include "cgroup.h"
30+
#include "machine.h"
2831
#include <linux/kernel.h>
2932
#include <linux/string.h>
3033

@@ -634,6 +637,39 @@ struct sort_entry sort_cgroup_id = {
634637
.se_width_idx = HISTC_CGROUP_ID,
635638
};
636639

640+
/* --sort cgroup */
641+
642+
static int64_t
643+
sort__cgroup_cmp(struct hist_entry *left, struct hist_entry *right)
644+
{
645+
return right->cgroup - left->cgroup;
646+
}
647+
648+
static int hist_entry__cgroup_snprintf(struct hist_entry *he,
649+
char *bf, size_t size,
650+
unsigned int width __maybe_unused)
651+
{
652+
const char *cgrp_name = "N/A";
653+
654+
if (he->cgroup) {
655+
struct cgroup *cgrp = cgroup__find(he->ms.maps->machine->env,
656+
he->cgroup);
657+
if (cgrp != NULL)
658+
cgrp_name = cgrp->name;
659+
else
660+
cgrp_name = "unknown";
661+
}
662+
663+
return repsep_snprintf(bf, size, "%s", cgrp_name);
664+
}
665+
666+
struct sort_entry sort_cgroup = {
667+
.se_header = "Cgroup",
668+
.se_cmp = sort__cgroup_cmp,
669+
.se_snprintf = hist_entry__cgroup_snprintf,
670+
.se_width_idx = HISTC_CGROUP,
671+
};
672+
637673
/* --sort socket */
638674

639675
static int64_t
@@ -1660,6 +1696,7 @@ static struct sort_dimension common_sort_dimensions[] = {
16601696
DIM(SORT_TRACE, "trace", sort_trace),
16611697
DIM(SORT_SYM_SIZE, "symbol_size", sort_sym_size),
16621698
DIM(SORT_DSO_SIZE, "dso_size", sort_dso_size),
1699+
DIM(SORT_CGROUP, "cgroup", sort_cgroup),
16631700
DIM(SORT_CGROUP_ID, "cgroup_id", sort_cgroup_id),
16641701
DIM(SORT_SYM_IPC_NULL, "ipc_null", sort_sym_ipc_null),
16651702
DIM(SORT_TIME, "time", sort_time),

tools/perf/util/sort.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct hist_entry {
101101
struct thread *thread;
102102
struct comm *comm;
103103
struct namespace_id cgroup_id;
104+
u64 cgroup;
104105
u64 ip;
105106
u64 transaction;
106107
s32 socket;
@@ -224,6 +225,7 @@ enum sort_type {
224225
SORT_TRACE,
225226
SORT_SYM_SIZE,
226227
SORT_DSO_SIZE,
228+
SORT_CGROUP,
227229
SORT_CGROUP_ID,
228230
SORT_SYM_IPC_NULL,
229231
SORT_TIME,

0 commit comments

Comments
 (0)