Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2817997ybz; Mon, 27 Apr 2020 05:12:38 -0700 (PDT) X-Google-Smtp-Source: APiQypK8/Kgt74yxdxB4tQ+eyGwqRNrV8KmWAH7hOzHGafbg9kAaDKW4UkA78TC6wGWN//xldQuv X-Received: by 2002:a17:906:5fd2:: with SMTP id k18mr18938139ejv.243.1587989557783; Mon, 27 Apr 2020 05:12:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587989557; cv=none; d=google.com; s=arc-20160816; b=nz5Kg9ckGpIhSwrLoejtBgUB3judURDVyzSwhq4RdBVFMJmc185KLdlfBlu8tTDpet QbDsrUz8QCz7mhW6jGpun0R+ti038dIwUy33/ngd4jsstWGpzegRtYdXGj9teYuMtzM8 Au8HOjTL1iZVwK1MtqdEqVaCO0aU1w5BjyxeoLMyZUI2z33ieEVk+2lD7T6oxnK2JzvL /ipIxJzt32ERCaPEn6d2fWXx2vqngInEGjaP1LJpHSf338e0qc+swVhuXyZh/qy5ynsb 7+Jc9K6eo2SQ6Z36KnWrQM9YkMv23WomQo1cKlG0B/LXu3W7YbkO+A+E0jMvbH7hm1DI 3s3A== 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=1nHLf6GF2DasMM8LcTB/6YcLhSGCeBDmjjbh8PNEsgo=; b=FSQeYUXoXtnxa9YcF4rVxnRmdjHWR9hvci1SRyWqwsmM/ClZMAnrY4CYk0ZH3S3ds2 HRDd/rf5ndYMSAEpF+WxEqxt1adOGjjFHIJJx+5YNrRp0nyMwawjIu4J6GByp0ZGomsb OEkXa+ds8+t6y4C7DX3N84AubQ+8v1srOC+cUX46lh2BWDEf5Oq6rFTEz+pA1wxpKi84 BHh0PImgDevBvb8bhrvL3zBs1dr/NT/fJiaLkbu0AUF89/2HQb9npyI4Po41l1kbVEe3 y5Qbj9ScvW+1EaIZwPhd8r3AWFLFexNlYeWMkcHRoUNgE4uFIpZuc8U4uPNw/1udrayE vkuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Yp5AoJO8; 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 s14si7497344edw.490.2020.04.27.05.12.11; Mon, 27 Apr 2020 05:12:37 -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=Yp5AoJO8; 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 S1727771AbgD0MKV (ORCPT + 99 others); Mon, 27 Apr 2020 08:10:21 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:63639 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726260AbgD0MKQ (ORCPT ); Mon, 27 Apr 2020 08:10:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1587989410; x=1619525410; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=1nHLf6GF2DasMM8LcTB/6YcLhSGCeBDmjjbh8PNEsgo=; b=Yp5AoJO8omjgF9hAp7ET/2DV2lbAT7wDLZQzwBogr7+XM96ZKfEDCJ9H n+UonwF/FH86cKpMwKU3qi9oihJqEbg+SlS88uyFheDw3grviirrjHeqO +VQhecB1ymIox0eOsT8377wLPAbF8nCGutxcMHIfCXxn7gAHM32vE78lV Q=; IronPort-SDR: u19epkjeI0AN0wU0uSMIXj37Hvz7YQqHeOGmhjJkY5pU7xTB8mgqBiiA6tO3UyEK4pm5Doxhd8 o6Iz+iMEj43Q== X-IronPort-AV: E=Sophos;i="5.73,324,1583193600"; d="scan'208";a="39684384" 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-9102.sea19.amazon.com with ESMTP; 27 Apr 2020 12:10:10 +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 DE7E6A05FB; Mon, 27 Apr 2020 12:10:07 +0000 (UTC) Received: from EX13D31EUA001.ant.amazon.com (10.43.165.15) by EX13MTAUEA002.ant.amazon.com (10.43.61.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 27 Apr 2020 12:10:07 +0000 Received: from u886c93fd17d25d.ant.amazon.com (10.43.162.53) by EX13D31EUA001.ant.amazon.com (10.43.165.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 27 Apr 2020 12:09:51 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v9 11/15] tools: Add a minimal user-space tool for DAMON Date: Mon, 27 Apr 2020 14:04:38 +0200 Message-ID: <20200427120442.24179-12-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200427120442.24179-1-sjpark@amazon.com> References: <20200427120442.24179-1-sjpark@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.43.162.53] X-ClientProxiedBy: EX13D34UWC004.ant.amazon.com (10.43.162.155) To EX13D31EUA001.ant.amazon.com (10.43.165.15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park This commit adds a shallow wrapper python script, ``/tools/damon/damo`` that provides more convenient interface. Note that it is only aimed to be used for minimal reference of the DAMON's debugfs interfaces and for debugging of the DAMON itself. Signed-off-by: SeongJae Park --- tools/damon/.gitignore | 1 + tools/damon/_dist.py | 36 ++++ tools/damon/_recfile.py | 23 +++ tools/damon/bin2txt.py | 67 +++++++ tools/damon/damo | 37 ++++ tools/damon/heats.py | 362 ++++++++++++++++++++++++++++++++++++++ tools/damon/nr_regions.py | 91 ++++++++++ tools/damon/record.py | 212 ++++++++++++++++++++++ tools/damon/report.py | 45 +++++ tools/damon/wss.py | 97 ++++++++++ 10 files changed, 971 insertions(+) create mode 100644 tools/damon/.gitignore create mode 100644 tools/damon/_dist.py create mode 100644 tools/damon/_recfile.py create mode 100644 tools/damon/bin2txt.py create mode 100755 tools/damon/damo create mode 100644 tools/damon/heats.py create mode 100644 tools/damon/nr_regions.py create mode 100644 tools/damon/record.py create mode 100644 tools/damon/report.py create mode 100644 tools/damon/wss.py diff --git a/tools/damon/.gitignore b/tools/damon/.gitignore new file mode 100644 index 000000000000..96403d36ff93 --- /dev/null +++ b/tools/damon/.gitignore @@ -0,0 +1 @@ +__pycache__/* diff --git a/tools/damon/_dist.py b/tools/damon/_dist.py new file mode 100644 index 000000000000..9851ec964e5c --- /dev/null +++ b/tools/damon/_dist.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import os +import struct +import subprocess + +def access_patterns(f): + nr_regions = struct.unpack('I', f.read(4))[0] + + patterns = [] + for r in range(nr_regions): + saddr = struct.unpack('L', f.read(8))[0] + eaddr = struct.unpack('L', f.read(8))[0] + nr_accesses = struct.unpack('I', f.read(4))[0] + patterns.append([eaddr - saddr, nr_accesses]) + return patterns + +def plot_dist(data_file, output_file, xlabel, ylabel): + terminal = output_file.split('.')[-1] + if not terminal in ['pdf', 'jpeg', 'png', 'svg']: + os.remove(data_file) + print("Unsupported plot output type.") + exit(-1) + + gnuplot_cmd = """ + set term %s; + set output '%s'; + set key off; + set xlabel '%s'; + set ylabel '%s'; + plot '%s' with linespoints;""" % (terminal, output_file, xlabel, ylabel, + data_file) + subprocess.call(['gnuplot', '-e', gnuplot_cmd]) + os.remove(data_file) + diff --git a/tools/damon/_recfile.py b/tools/damon/_recfile.py new file mode 100644 index 000000000000..331b4d8165d8 --- /dev/null +++ b/tools/damon/_recfile.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import struct + +fmt_version = 0 + +def set_fmt_version(f): + global fmt_version + + mark = f.read(16) + if mark == b'damon_recfmt_ver': + fmt_version = struct.unpack('i', f.read(4))[0] + else: + fmt_version = 0 + f.seek(0) + return fmt_version + +def pid(f): + if fmt_version == 0: + return struct.unpack('L', f.read(8))[0] + else: + return struct.unpack('i', f.read(4))[0] diff --git a/tools/damon/bin2txt.py b/tools/damon/bin2txt.py new file mode 100644 index 000000000000..8b9b57a0d727 --- /dev/null +++ b/tools/damon/bin2txt.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import argparse +import os +import struct +import sys + +import _recfile + +def parse_time(bindat): + "bindat should be 16 bytes" + sec = struct.unpack('l', bindat[0:8])[0] + nsec = struct.unpack('l', bindat[8:16])[0] + return sec * 1000000000 + nsec; + +def pr_region(f): + saddr = struct.unpack('L', f.read(8))[0] + eaddr = struct.unpack('L', f.read(8))[0] + nr_accesses = struct.unpack('I', f.read(4))[0] + print("%012x-%012x(%10d):\t%d" % + (saddr, eaddr, eaddr - saddr, nr_accesses)) + +def pr_task_info(f): + pid = _recfile.pid(f) + print("pid: ", pid) + nr_regions = struct.unpack('I', f.read(4))[0] + print("nr_regions: ", nr_regions) + for r in range(nr_regions): + pr_region(f) + +def set_argparser(parser): + parser.add_argument('--input', '-i', type=str, metavar='', + default='damon.data', help='input file name') + +def main(args=None): + if not args: + parser = argparse.ArgumentParser() + set_argparser(parser) + args = parser.parse_args() + + file_path = args.input + + if not os.path.isfile(file_path): + print('input file (%s) is not exist' % file_path) + exit(1) + + with open(file_path, 'rb') as f: + _recfile.set_fmt_version(f) + start_time = None + while True: + timebin = f.read(16) + if len(timebin) != 16: + break + time = parse_time(timebin) + if not start_time: + start_time = time + print("start_time: ", start_time) + print("rel time: %16d" % (time - start_time)) + nr_tasks = struct.unpack('I', f.read(4))[0] + print("nr_tasks: ", nr_tasks) + for t in range(nr_tasks): + pr_task_info(f) + print("") + +if __name__ == '__main__': + main() diff --git a/tools/damon/damo b/tools/damon/damo new file mode 100755 index 000000000000..58e1099ae5fc --- /dev/null +++ b/tools/damon/damo @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +import argparse + +import record +import report + +class SubCmdHelpFormatter(argparse.RawDescriptionHelpFormatter): + def _format_action(self, action): + parts = super(argparse.RawDescriptionHelpFormatter, + self)._format_action(action) + # skip sub parsers help + if action.nargs == argparse.PARSER: + parts = '\n'.join(parts.split('\n')[1:]) + return parts + +parser = argparse.ArgumentParser(formatter_class=SubCmdHelpFormatter) + +subparser = parser.add_subparsers(title='command', dest='command', + metavar='') +subparser.required = True + +parser_record = subparser.add_parser('record', + help='record data accesses of the given target processes') +record.set_argparser(parser_record) + +parser_report = subparser.add_parser('report', + help='report the recorded data accesses in the specified form') +report.set_argparser(parser_report) + +args = parser.parse_args() + +if args.command == 'record': + record.main(args) +elif args.command == 'report': + report.main(args) diff --git a/tools/damon/heats.py b/tools/damon/heats.py new file mode 100644 index 000000000000..99837083874e --- /dev/null +++ b/tools/damon/heats.py @@ -0,0 +1,362 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 + +""" +Transform binary trace data into human readable text that can be used for +heatmap drawing, or directly plot the data in a heatmap format. + +Format of the text is: + +