Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1099183ybt; Tue, 7 Jul 2020 07:48:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxL22hgIblRLqG+7W772A+aSiRyON3jN03LqALxtxmv0lCAczsNWQGGJRtbZAdToiKqSb5h X-Received: by 2002:a50:cd53:: with SMTP id d19mr62967806edj.300.1594133302638; Tue, 07 Jul 2020 07:48:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594133302; cv=none; d=google.com; s=arc-20160816; b=DtVVU+H/0c5rxfp0mZpJAE7B/AJaFglSVO34juu/BAaawgRXd32G6pmEUe8PFNmVkk Ie8VcpB/W+T4ZggciPx7q9bdamcVrJjHaRg6afkouLvOscbTyKDrP2VNYYDS5qf6t02D aQDBeAo42VAPNER/gMeqUwt3tvzKTP11ctV19hWZ8sqPsjypCajxXSF9QV6X67bn79aq Cunql97PfEAjl4earPodyvVZB/0VltDXi4Y7Ka1VgNUen4wXVfzmtv5XlyBb6fCRI5Lq /UFH1RbOTfZbeewsJWEFlzjZhoww3awB0e2PfrTZ+xrAJ/AMm9hzJuTeTpTDRfbhX4T+ /HGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:ironport-sdr:dkim-signature; bh=BksteOeehUikB4CSkBmzeSkm8yWL2e44sQDAz0bv2zk=; b=sDx/ImtDSmYrjaZ0dUMzRjSIPgzZrhiih/G4lveorosOIQhLEk7kU1bnUdtpDQtm4U llF5CGX8T8DYvbU05PMm172owdhygBqKy2dU9Uw8QxBXQlFA4wU1RM91CE6c18sraDof nH5tUzsriD2XvC+JecMwn3APu3SZvogY0jSqjFig2CyL7jxsyF6vD29I24C6uTvW2Irk outNOu/aJd+l5LJLDgqCjdRRo8srEWO1vWJje55veEe2yO4Ptkx36VlGozathANGjJSv T0AE/8DtIyyFgRbyPMQbSrQeORQAE/TBc7je2pxhpkdt5ZJqM80ZsfG1fVASq1TcV2yM ioGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=ZZSAuzPv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f3si15745901edy.2.2020.07.07.07.47.59; Tue, 07 Jul 2020 07:48:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=ZZSAuzPv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728183AbgGGOrW (ORCPT + 99 others); Tue, 7 Jul 2020 10:47:22 -0400 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:28213 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726805AbgGGOrV (ORCPT ); Tue, 7 Jul 2020 10:47:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1594133241; x=1625669241; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=BksteOeehUikB4CSkBmzeSkm8yWL2e44sQDAz0bv2zk=; b=ZZSAuzPv7ijuB4AqugwkPBlaq1MrjGWNHciO1/zc6Tgeq5tdsBzKvEld 76/jRlXV8UmimvLwW3XFgDgT+vWJa7YkNtY8LqX21USW7reeQepor2/b2 U+t/fKFNpdExc5baRoXqgRj6otSrI4tD96PNX43b5Uy6nA3bi808Fu6Gf g=; IronPort-SDR: WD7PaGLzyjNGhUgjLSZZRswy7K3xJlIUa8C7E+ZSBE59h3yZUZcMvS9LAKmv7GCutZD67Pp70w h0LqxGm6iHLg== X-IronPort-AV: E=Sophos;i="5.75,324,1589241600"; d="scan'208";a="49756137" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-2a-e7be2041.us-west-2.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP; 07 Jul 2020 14:47:20 +0000 Received: from EX13MTAUEA002.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-e7be2041.us-west-2.amazon.com (Postfix) with ESMTPS id DBFEFA195C; Tue, 7 Jul 2020 14:47:17 +0000 (UTC) Received: from EX13D31EUA004.ant.amazon.com (10.43.165.161) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 7 Jul 2020 14:47:17 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.161.214) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 7 Jul 2020 14:46:56 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC v5 02/11] tools/damon: Support init target regions specification Date: Tue, 7 Jul 2020 16:45:31 +0200 Message-ID: <20200707144540.21216-3-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200707144540.21216-1-sjpark@amazon.com> References: <20200707144540.21216-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.161.214] X-ClientProxiedBy: EX13D35UWC001.ant.amazon.com (10.43.162.197) To EX13D31EUA004.ant.amazon.com (10.43.165.161) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park This commit updates the damon user space tool to support the initial monitoring target regions specification. Signed-off-by: SeongJae Park --- tools/damon/_damon.py | 39 +++++++++++++++++++++++++++++++++++++++ tools/damon/record.py | 12 +++++++----- tools/damon/schemes.py | 12 +++++++----- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/tools/damon/_damon.py b/tools/damon/_damon.py index 3620ef12a5ea..ad476cc61421 100644 --- a/tools/damon/_damon.py +++ b/tools/damon/_damon.py @@ -12,12 +12,25 @@ debugfs_attrs = None debugfs_record = None debugfs_schemes = None debugfs_pids = None +debugfs_init_regions = None debugfs_monitor_on = None def set_target_pid(pid): return subprocess.call('echo %s > %s' % (pid, debugfs_pids), shell=True, executable='/bin/bash') +def set_target(pid, init_regions=[]): + rc = set_target_pid(pid) + if rc: + return rc + + if not os.path.exists(debugfs_init_regions): + return 0 + + string = ' '.join(['%s %d %d' % (pid, r[0], r[1]) for r in init_regions]) + return subprocess.call('echo "%s" > %s' % (string, debugfs_init_regions), + shell=True, executable='/bin/bash') + def turn_damon(on_off): return subprocess.call("echo %s > %s" % (on_off, debugfs_monitor_on), shell=True, executable="/bin/bash") @@ -97,6 +110,7 @@ def chk_update_debugfs(debugfs): global debugfs_record global debugfs_schemes global debugfs_pids + global debugfs_init_regions global debugfs_monitor_on debugfs_damon = os.path.join(debugfs, 'damon') @@ -104,6 +118,7 @@ def chk_update_debugfs(debugfs): debugfs_record = os.path.join(debugfs_damon, 'record') debugfs_schemes = os.path.join(debugfs_damon, 'schemes') debugfs_pids = os.path.join(debugfs_damon, 'pids') + debugfs_init_regions = os.path.join(debugfs_damon, 'init_regions') debugfs_monitor_on = os.path.join(debugfs_damon, 'monitor_on') if not os.path.isdir(debugfs_damon): @@ -131,6 +146,26 @@ def cmd_args_to_attrs(args): return Attrs(sample_interval, aggr_interval, regions_update_interval, min_nr_regions, max_nr_regions, rbuf_len, rfile_path, schemes) +def cmd_args_to_init_regions(args): + regions = [] + for arg in args.regions.split(): + addrs = arg.split('-') + try: + if len(addrs) != 2: + raise Exception('two addresses not given') + start = int(addrs[0]) + end = int(addrs[1]) + if start >= end: + raise Exception('start >= end') + if regions and regions[-1][1] > start: + raise Exception('regions overlap') + except Exception as e: + print('Wrong \'--regions\' argument (%s)' % e) + exit(1) + + regions.append([start, end]) + return regions + def set_attrs_argparser(parser): parser.add_argument('-d', '--debugfs', metavar='', type=str, default='/sys/kernel/debug', help='debugfs mounted path') @@ -144,3 +179,7 @@ def set_attrs_argparser(parser): default=10, help='minimal number of regions') parser.add_argument('-m', '--maxr', metavar='<# regions>', type=int, default=1000, help='maximum number of regions') + +def set_init_regions_argparser(parser): + parser.add_argument('-r', '--regions', metavar='"- ..."', + type=str, default='', help='monitoring target address regions') diff --git a/tools/damon/record.py b/tools/damon/record.py index 44fa3a12af35..6ce8721d782a 100644 --- a/tools/damon/record.py +++ b/tools/damon/record.py @@ -13,7 +13,7 @@ import time import _damon -def do_record(target, is_target_cmd, attrs, old_attrs): +def do_record(target, is_target_cmd, init_regions, attrs, old_attrs): if os.path.isfile(attrs.rfile_path): os.rename(attrs.rfile_path, attrs.rfile_path + '.old') @@ -24,8 +24,8 @@ def do_record(target, is_target_cmd, attrs, old_attrs): if is_target_cmd: p = subprocess.Popen(target, shell=True, executable='/bin/bash') target = p.pid - if _damon.set_target_pid(target): - print('pid setting (%s) failed' % target) + if _damon.set_target(target, init_regions): + print('target setting (%s, %s) failed' % (target, init_regions)) cleanup_exit(old_attrs, -2) if _damon.turn_damon('on'): print('could not turn on damon' % target) @@ -65,6 +65,7 @@ def chk_permission(): def set_argparser(parser): _damon.set_attrs_argparser(parser) + _damon.set_init_regions_argparser(parser) parser.add_argument('target', type=str, metavar='', help='the target command or the pid to record') parser.add_argument('-l', '--rbuf', metavar='', type=int, @@ -88,19 +89,20 @@ def main(args=None): args.schemes = '' new_attrs = _damon.cmd_args_to_attrs(args) + init_regions = _damon.cmd_args_to_init_regions(args) target = args.target target_fields = target.split() if not subprocess.call('which %s > /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): - do_record(target, True, new_attrs, orig_attrs) + do_record(target, True, init_regions, new_attrs, orig_attrs) else: try: pid = int(target) except: print('target \'%s\' is neither a command, nor a pid' % target) exit(1) - do_record(target, False, new_attrs, orig_attrs) + do_record(target, False, init_regions, new_attrs, orig_attrs) if __name__ == '__main__': main() diff --git a/tools/damon/schemes.py b/tools/damon/schemes.py index 9f369db7d12e..49968fb947f1 100644 --- a/tools/damon/schemes.py +++ b/tools/damon/schemes.py @@ -14,7 +14,7 @@ import time import _convert_damos import _damon -def run_damon(target, is_target_cmd, attrs, old_attrs): +def run_damon(target, is_target_cmd, init_regions, attrs, old_attrs): if os.path.isfile(attrs.rfile_path): os.rename(attrs.rfile_path, attrs.rfile_path + '.old') @@ -27,8 +27,8 @@ def run_damon(target, is_target_cmd, attrs, old_attrs): if is_target_cmd: p = subprocess.Popen(target, shell=True, executable='/bin/bash') target = p.pid - if _damon.set_target_pid(target): - print('pid setting (%s) failed' % target) + if _damon.set_target(target, init_regions): + print('target setting (%s, %s) failed' % (target, init_regions)) cleanup_exit(old_attrs, -2) if _damon.turn_damon('on'): print('could not turn on damon' % target) @@ -68,6 +68,7 @@ def chk_permission(): def set_argparser(parser): _damon.set_attrs_argparser(parser) + _damon.set_init_regions_argparser(parser) parser.add_argument('target', type=str, metavar='', help='the target command or the pid to record') parser.add_argument('-c', '--schemes', metavar='', type=str, @@ -92,19 +93,20 @@ def main(args=None): args.out = 'null' args.schemes = _convert_damos.convert(args.schemes, args.sample, args.aggr) new_attrs = _damon.cmd_args_to_attrs(args) + init_regions = _damon.cmd_args_to_init_regions(args) target = args.target target_fields = target.split() if not subprocess.call('which %s > /dev/null' % target_fields[0], shell=True, executable='/bin/bash'): - run_damon(target, True, new_attrs, orig_attrs) + run_damon(target, True, init_regions, new_attrs, orig_attrs) else: try: pid = int(target) except: print('target \'%s\' is neither a command, nor a pid' % target) exit(1) - run_damon(target, False, new_attrs, orig_attrs) + run_damon(target, False, init_regions, new_attrs, orig_attrs) if __name__ == '__main__': main() -- 2.17.1