From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755556AbcKJLjy (ORCPT ); Thu, 10 Nov 2016 06:39:54 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53425 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754806AbcKJLjt (ORCPT ); Thu, 10 Nov 2016 06:39:49 -0500 Subject: [PATCH 3/3] perf tool: add cgroup identifier entry in perf report From: Hari Bathini To: ast@fb.com, peterz@infradead.org, lkml , acme@kernel.org, alexander.shishkin@linux.intel.com, mingo@redhat.com Cc: daniel@iogearbox.net, rostedt@goodmis.org, Ananth N Mavinakayanahalli , ebiederm@xmission.com, sargun@sargun.me, Aravinda Prasad , brendan.d.gregg@gmail.com Date: Thu, 10 Nov 2016 17:09:33 +0530 In-Reply-To: <147877784354.29988.8570048236764105701.stgit@hbathini.in.ibm.com> References: <147877784354.29988.8570048236764105701.stgit@hbathini.in.ibm.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16111011-0040-0000-0000-000001FD1407 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16111011-0041-0000-0000-00000AE0D826 Message-Id: <147877792719.29988.10466158968869055362.stgit@hbathini.in.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-11-10_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611100219 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces a cgroup identifier entry field in perf report to identify or distinguish data of different cgroups. It uses the unique inode number of cgroup namespace, included in perf data with the new PERF_RECORD_NAMESPACES event, as cgroup identifier. With the assumption that each container is created with it's own cgroup namespace, this allows assessment/analysis of multiple containers at once. Shown below is the output of perf report, sorted based on cgroup id, on a system that was running three containers at the time of perf record and clearly showing one of the containers' considerable use of kernel memory in comparison with others: $ perf report -s cgroup_id,sample --stdio # # Total Lost Samples: 0 # # Samples: 1K of event 'kmem:kmalloc' # Event count (approx.): 1290 # # Overhead cgroup id Samples # ........ .......... ............ # 78.84% 4026532052 1017 12.87% 4026531835 166 5.58% 4026532053 72 2.71% 4026532054 35 Signed-off-by: Hari Bathini --- tools/perf/util/hist.c | 4 ++++ tools/perf/util/hist.h | 1 + tools/perf/util/sort.c | 22 ++++++++++++++++++++++ tools/perf/util/sort.h | 2 ++ 4 files changed, 29 insertions(+) diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index b02992e..76f2a91 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -2,6 +2,7 @@ #include "build-id.h" #include "hist.h" #include "session.h" +#include "namespaces.h" #include "sort.h" #include "evlist.h" #include "evsel.h" @@ -168,6 +169,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h) hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO); } + hists__new_col_len(hists, HISTC_CGROUP_ID, 10); hists__new_col_len(hists, HISTC_CPU, 3); hists__new_col_len(hists, HISTC_SOCKET, 6); hists__new_col_len(hists, HISTC_MEM_LOCKED, 6); @@ -573,9 +575,11 @@ __hists__add_entry(struct hists *hists, bool sample_self, struct hist_entry_ops *ops) { + struct namespaces *ns = thread__namespaces(al->thread); struct hist_entry entry = { .thread = al->thread, .comm = thread__comm(al->thread), + .cgroup_id = ns ? ns->cgroup_ns_inum : 0, .ms = { .map = al->map, .sym = al->sym, diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 9928fed..894c95d 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -29,6 +29,7 @@ enum hist_column { HISTC_DSO, HISTC_THREAD, HISTC_COMM, + HISTC_CGROUP_ID, HISTC_PARENT, HISTC_CPU, HISTC_SOCKET, diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 452e15a..b6152df 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -536,6 +536,27 @@ struct sort_entry sort_cpu = { .se_width_idx = HISTC_CPU, }; +/* --sort cgroup_id */ + +static int64_t +sort__cgroup_id_cmp(struct hist_entry *left, struct hist_entry *right) +{ + return (int64_t)right->cgroup_id - (int64_t)left->cgroup_id; +} + +static int hist_entry__cgroup_id_snprintf(struct hist_entry *he, char *bf, + size_t size, unsigned int width) +{ + return repsep_snprintf(bf, size, "%-*u", width, he->cgroup_id); +} + +struct sort_entry sort_cgroup_id = { + .se_header = "cgroup id", + .se_cmp = sort__cgroup_id_cmp, + .se_snprintf = hist_entry__cgroup_id_snprintf, + .se_width_idx = HISTC_CGROUP_ID, +}; + /* --sort socket */ static int64_t @@ -1418,6 +1439,7 @@ static struct sort_dimension common_sort_dimensions[] = { DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight), DIM(SORT_TRANSACTION, "transaction", sort_transaction), DIM(SORT_TRACE, "trace", sort_trace), + DIM(SORT_CGROUP_ID, "cgroup_id", sort_cgroup_id), }; #undef DIM diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index 099c975..e8058f6 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -95,6 +95,7 @@ struct hist_entry { u64 transaction; s32 socket; s32 cpu; + u32 cgroup_id; u8 cpumode; u8 depth; @@ -211,6 +212,7 @@ enum sort_type { SORT_GLOBAL_WEIGHT, SORT_TRANSACTION, SORT_TRACE, + SORT_CGROUP_ID, /* branch stack specific sort keys */ __SORT_BRANCH_STACK,