From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 7A1AF3842411 for ; Thu, 4 Mar 2021 12:25:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7A1AF3842411 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7B6C0AF9E; Thu, 4 Mar 2021 12:25:21 +0000 (UTC) Date: Thu, 4 Mar 2021 13:25:14 +0100 From: Tom de Vries To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org Subject: [PATCH] Add --devel-progress-mem Message-ID: <20210304122513.GA27486@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: dwz@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Dwz mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Mar 2021 12:25:23 -0000 Hi, Add an option --devel-progress-mem that adds memory usage printing to --devel-progress: ... $ dwz cc1 -lnone -o cc1.z --devel-progress-mem read_debug_info .debug_info user: 4.70 sys : 0.18 VM Peak: 1178532 (1.1G) VM Current: 1174432 (1.1G) RSS Peak: 1091784 (1.0G) RSS Current: 1087992 (1.0G) partition_dups user: 0.11 sys : 0.00 VM Peak: 1178532 (1.1G) VM Current: 1174860 (1.1G) RSS Peak: 1091784 (1.0G) RSS Current: 1088372 (1.0G) ... Any comments? Thanks, - Tom Add --devel-progress-mem 2021-03-04 Tom de Vries * dwz.c (print_mem): New function. (report_progress): Print memory usage statistics if progress_mem_p. (dwz_options, usage): Add --devel-progress-mem entries. (main): Set progress_p if progress_mem_p. --- dwz.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/dwz.c b/dwz.c index af1c5af..aec039d 100644 --- a/dwz.c +++ b/dwz.c @@ -132,6 +132,23 @@ #define MAX(A, B) ((A) > (B) ? (A) : (B)) #define MIN(A, B) ((A) < (B) ? (A) : (B)) +/* Print memory amount M (in kb) in both exact and human readable, like so: + 1382508 (1.3G). */ +static void +print_mem (long m) +{ + float h = m; + int level = 0; + const char *unit[] = { "K", "M", "G"}; + while (h > 1024 && level <= 2) + { + h = h / 1024; + level++; + } + fprintf (stderr, "%ld (%.1f%s)\n", m, h, unit[level]); +} + +static int progress_mem_p; static void report_progress (void) @@ -157,6 +174,40 @@ report_progress (void) clock_t sys = current.tms_stime - prev.tms_stime; fprintf (stderr, "user: %.2f\n", (float)user / (float)ticks_per_second); fprintf (stderr, "sys : %.2f\n", (float)sys / (float)ticks_per_second); + + if (progress_mem_p) + { + FILE *s = fopen ("/proc/self/status", "r"); + char *p; + bool print_next = false; + for (p = NULL; fscanf (s, "%ms", &p) && p != NULL; free (p)) + { + if (print_next) + { + long mem = strtol (p, NULL, 10); + print_mem (mem); + print_next = false; + continue; + } + + if (!(p[0] == 'V' && p[1] == 'm')) + continue; + + if (strcmp (&p[2], "Peak:") == 0) + fprintf (stderr, "VM Peak: "); + else if (strcmp (&p[2], "Size:") == 0) + fprintf (stderr, "VM Current: "); + else if (strcmp (&p[2], "HWM:") == 0) + fprintf (stderr, "RSS Peak: "); + else if (strcmp (&p[2], "RSS:") == 0) + fprintf (stderr, "RSS Current: "); + else + continue; + + print_next = true; + } + fclose (s); + } } #define obstack_chunk_alloc malloc @@ -16285,6 +16336,7 @@ static struct option dwz_options[] = #if DEVEL { "devel-trace", no_argument, &tracing, 1 }, { "devel-progress", no_argument, &progress_p, 1 }, + { "devel-progress-mem",no_argument, &progress_mem_p, 1 }, { "devel-ignore-size", no_argument, &ignore_size, 1 }, { "devel-ignore-locus",no_argument, &ignore_locus, 1 }, { "devel-force", no_argument, &force_p, 1 }, @@ -16552,6 +16604,7 @@ usage (const char *progname, int failing) fprintf (stream, "%s", (" --devel-trace\n" " --devel-progress\n" + " --devel-progress-mem\n" " --devel-stats\n" " --devel-ignore-size\n" " --devel-ignore-locus\n" @@ -16732,6 +16785,9 @@ main (int argc, char *argv[]) } } + if (progress_mem_p) + progress_p = 1; + /* Specifying a low-mem die-limit that is larger than or equal to the max die-limit has the effect of disabling low-mem mode. Make this explicit by setting it to the 'none' value. */