From patchwork Sat Aug 17 17:18:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yann E. MORIN" X-Patchwork-Id: 1148743 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=free.fr Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UmYXtZ7W"; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 469n3G3xn8z9sDQ for ; Sun, 18 Aug 2019 03:18:49 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 1844787A2E; Sat, 17 Aug 2019 17:18:48 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GI5H5wc0eVoy; Sat, 17 Aug 2019 17:18:47 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 6513687994; Sat, 17 Aug 2019 17:18:47 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 4A2CA1BF402 for ; Sat, 17 Aug 2019 17:18:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 441DB87934 for ; Sat, 17 Aug 2019 17:18:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0KcmTgzXYRU6 for ; Sat, 17 Aug 2019 17:18:45 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by hemlock.osuosl.org (Postfix) with ESMTPS id 62A7E878AC for ; Sat, 17 Aug 2019 17:18:45 +0000 (UTC) Received: by mail-wm1-f54.google.com with SMTP id i63so6531034wmg.4 for ; Sat, 17 Aug 2019 10:18:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TS5udvl9UremdoH9y/xFmrvPEM9vc4q6jv5IMVM4ZHo=; b=UmYXtZ7WbDyYobcuCa/1L5nNN0c6gQSSFvGnHBahsNW+VvmXlOv5SjM/DcjUuXFuVq NiOQSb7KfqgBPtrV2z99OdKtjkfQ+fW01q7WFJNtXdwCmsZ78DVw1ppd2pS5xcb78Eef hFQB7zYRaL0WYpqTsSoflN1I5iZLpbDv22hYwnr6vR/fAXw8hIJPkHrJfifx1cRaWSIE Y/ZkFHJ6+PdJP8sL25chgl2MfZBqXxizGibURkA/CLxah7/sc1gxO1cJAoFIzstZO8HU PZhvRj5n0Ehp/dHBpUxUXFztr7GH7adI9iwS6RjKaJrwGjkpl5nTdIBFYHUKU/KgW1/u Twzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=TS5udvl9UremdoH9y/xFmrvPEM9vc4q6jv5IMVM4ZHo=; b=qK0wMkkqPpzkOaYO3G9ljoVfOJmzAhpSt3M8489WYbzkIpR3Q+3jls92nc8Gor67D7 i+MTXZly/nyor9faqH40gD8ivBinVg0jlIZ4VK9DHUgZqwv43aKI7U98XASqfUaaqPDi 1OpNtBM6K1yhMXSUVws/Xh5UxGkY6nqxYLi+WiB6tIxSmpW/FJ+sXwJ0TcJKQETfbqOi dpMTur/AKTk5WifMz4vMagIkHAVYYdLTUHeqC60Wbc1u7YLeHRH4zSQGqQ9JaMr+2C4f NE74vq1uZDiZESsWez/K1JsJS6iJ8jit5Qn3segxLXLV5Q8qvzZ5l2L5yiGiz23ELyE1 xHUg== X-Gm-Message-State: APjAAAWd8DTf5jvMQ3BrdcQOWSZOGFEH9KdtlarC2kzd7wif6Yz/1QHT BnyAx1/O348i2OQLBK/zs8dpijR0 X-Google-Smtp-Source: APXvYqxwn8zdSCqrml9PqtS6GITvYolEQKX7JjB94NwDMcoJI2C2MbxutkY9wo7UA6i4SyW+rZsGwA== X-Received: by 2002:a05:600c:254a:: with SMTP id e10mr13029698wma.113.1566062323532; Sat, 17 Aug 2019 10:18:43 -0700 (PDT) Received: from localhost.localdomain (ns304657.ip-46-105-103.eu. [46.105.103.66]) by smtp.gmail.com with ESMTPSA id w13sm20864877wre.44.2019.08.17.10.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Aug 2019 10:18:43 -0700 (PDT) From: "Yann E. MORIN" To: buildroot@buildroot.org Date: Sat, 17 Aug 2019 19:18:28 +0200 Message-Id: <7d974d2d24f11c454e59d76f5b22d364a0ed71e1.1566062299.git.yann.morin.1998@free.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Buildroot] [PATCH 7/9] support/graph-size: add option to report size with IEC prefixes X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Yann E. MORIN" , Thomas De Schampheleire Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" When dealing with embedded devices, storage is more often than not some kind of flash device, on which the memory is usually counted as powers of 1024 instead of powers of 1000. As such, people may prefer reports using IEC prefixes [0] instead of the SI prefixes. Add an option to that effect. We use argparse's ability to use custom actions [1] [2], to provide a set of options that act on a boolean, but has a single help entry and internally ensures consistency of the settings. We could have been using the more conventional store_true/stor_false actions instead, but that would have meant either two help entries, one for each set of options, and/or some logic after parse_args() to check the validity of the settings. [0] https://en.wikipedia.org/wiki/Binary_prefix [1] https://docs.python.org/2/library/argparse.html#action [2] https://docs.python.org/2/library/argparse.html#argparse.Action Signed-off-by: Yann E. MORIN Cc: Thomas De Schampheleire --- docs/manual/common-usage.txt | 3 +++ support/scripts/size-stats | 29 +++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/manual/common-usage.txt b/docs/manual/common-usage.txt index 7e78d350d4..5653e85e12 100644 --- a/docs/manual/common-usage.txt +++ b/docs/manual/common-usage.txt @@ -326,6 +326,9 @@ to further control the generated graph. Accepted options are: contributing less than 1% are grouped under _Others_. Accepted values are in the range `[0.0..1.0]`. +* `--iec`, `--binary`, `--si`, `--decimal`, to use IEC (binary, powers + of 1024) or SI (decimal, powers of 1000; the default) prefixes. + .Note The collected filesystem size data is only meaningful after a complete clean rebuild. Be sure to run +make clean all+ before using +make diff --git a/support/scripts/size-stats b/support/scripts/size-stats index 3454acd681..5bf0ee6e95 100755 --- a/support/scripts/size-stats +++ b/support/scripts/size-stats @@ -35,6 +35,7 @@ except ImportError: class Config(): + iec = False size_limit = 0.01 colors = ['#e60004', '#009836', '#2e1d86', '#ffed00', '#0068b5', '#f28e00', '#940084', '#97c000'] @@ -132,8 +133,12 @@ def build_package_size(filesdict, builddir): # def draw_graph(pkgsize, outputf): def size2string(sz): - divider = 1000.0 - prefixes = ['', 'k', 'M', 'G', 'T'] + if Config.iec: + divider = 1024.0 + prefixes = ['', 'Ki', 'Mi', 'Gi', 'Ti'] + else: + divider = 1000.0 + prefixes = ['', 'k', 'M', 'G', 'T'] while sz > divider and len(prefixes) > 1: prefixes = prefixes[1:] sz = sz/divider @@ -238,6 +243,21 @@ def gen_packages_csv(pkgsizes, outputf): wr.writerow([pkg, size, "%.1f" % (float(size) / total * 100)]) +# +# Our special action for --iec, --binary, --si, --decimal +# +class PrefixAction(argparse.Action): + def __init__(self, option_strings, dest, **kwargs): + for key in ["type", "nargs"]: + if key in kwargs: + raise ValueError('"{}" not allowed'.format(key)) + super(PrefixAction, self).__init__(option_strings, dest, nargs=0, + type=bool, **kwargs) + + def __call__(self, parser, namespace, values, option_string=None): + setattr(namespace, self.dest, option_string in ["--iec", "--binary"]) + + def main(): parser = argparse.ArgumentParser(description='Draw size statistics graphs') @@ -249,11 +269,16 @@ def main(): help="CSV output file with file size statistics") parser.add_argument("--package-size-csv", '-p', metavar="PKG_SIZE_CSV", help="CSV output file with package size statistics") + parser.add_argument("--iec", "--binary", "--si", "--decimal", + action=PrefixAction, + help="Use IEC (binary, powers of 1024) or SI (decimal, " + "powers of 1000, the default) prefixes") parser.add_argument("--size-limit", "-l", type=float, help='Under this size ratio, files are accounted to ' + 'the generic "Other" package. Default: 0.01 (1%%)') args = parser.parse_args() + Config.iec = args.iec if args.size_limit is not None: if args.size_limit < 0.0 or args.size_limit > 1.0: raise ValueError("--size-limit must be in [0.0..1.0]")