Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754097AbcLLSU0 (ORCPT ); Mon, 12 Dec 2016 13:20:26 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55701 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750696AbcLLSUY (ORCPT ); Mon, 12 Dec 2016 13:20:24 -0500 Subject: [PATCH v3 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: Mon, 12 Dec 2016 23:50:08 +0530 In-Reply-To: <148156671980.4651.13017595439842763683.stgit@hbathini.in.ibm.com> References: <148156671980.4651.13017595439842763683.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: 16121218-0012-0000-0000-000001F6459E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16121218-0013-0000-0000-0000069E1FAD Message-Id: <148156680219.4651.12310355352884515738.stgit@hbathini.in.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-12-12_12:,, 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-1612120274 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4287 Lines: 141 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.): 1828 # # Overhead cgroup id Samples # ........ .......... ............ # 84.74% 4026532048 1549 7.93% 4026531835 145 3.67% 4026532047 67 2.68% 4026532046 49 0.98% 0 18 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 a69f027..a6650d7 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->inode_num[CGROUP_NS_INDEX] : 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,