public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add --trace/-t
@ 2019-01-01  0:00 Tom de Vries
  2019-01-01  0:00 ` [committed] Add --devel-trace Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz, jakub

Hi,

Add a tracing option, to show more information about how dwz is progressing.

Regular mode:
...
$ dwz -t a.out
Compressing a.out
...

Low-mem mode:
...
$ dwz -t -l0 a.out
Compressing a.out
Hit low-mem die-limit
Compressing a.out in low-mem mode
...

Hardlink handling:
...
$ dwz -t -h a.out b.out
Compressing a.out
Updating hardlink b.out to changed file
...

Multifile mode:
...
$ dwz -t -m common.out a.out b.out
Compressing a.out
Write-multifile a.out
Compressing b.out
Write-multifile b.out
Optimize-multifile
Read-multifile
Compressing a.out in finalize-multifile mode
Compressing b.out in finalize-multifile mode
...

OK for trunk?

Thanks,
- Tom

Add --trace/-t

2019-03-08  Tom de Vries  <tdevries@suse.de>

	* dwz.c (read_debug_info, write_multifile, dwz, optimize_multifile)
	(read_multifile): Add tracing.
	(main): Add parsing of --trace/-t.

---
 dwz.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/dwz.c b/dwz.c
index 476807a..684fc71 100644
--- a/dwz.c
+++ b/dwz.c
@@ -136,6 +136,8 @@ static struct obstack ob2;
    and restored during final cleanup.  */
 static struct obstack alt_ob, alt_ob2;
 
+static bool tracing;
+
 typedef struct
 {
   Elf *elf;
@@ -4733,6 +4735,8 @@ read_debug_info (DSO *dso, int kind)
 		 caller that it should retry with low_mem.  */
 	      if (likely (!low_mem) && ndies == low_mem_die_limit)
 		{
+		  if (tracing)
+		    fprintf (stderr, "Hit low-mem die-limit\n");
 		  ret = 2;
 		  goto fail;
 		}
@@ -10822,6 +10826,8 @@ write_multifile (DSO *dso)
 	  *cup = (*cup)->cu_next;
       *cup = NULL;
       multifile_mode = MULTIFILE_MODE_WR;
+      if (tracing)
+	fprintf (stderr, "Write-multifile %s\n", dso->filename);
       if (compute_abbrevs (NULL))
 	ret = 1;
       else if (debug_sections[DEBUG_MACRO].data && read_macro (dso))
@@ -11027,6 +11033,9 @@ dwz (const char *file, const char *outfile, struct file_result *res,
 	     state.  */
 	  if (resa[n].res == 1)
 	    {
+	      if (tracing)
+		fprintf (stderr, "Skipping hardlink %s to unchanged file\n",
+			 file);
 	      close (fd);
 	      res->res = -2;
 	      return 1;
@@ -11037,6 +11046,9 @@ dwz (const char *file, const char *outfile, struct file_result *res,
 	      size_t len = strlen (file);
 	      char *filename = alloca (len + sizeof (".#dwz#.XXXXXX"));
 	      int fd2;
+	      if (tracing)
+		fprintf (stderr, "Updating hardlink %s to changed file\n",
+			 file);
 	      memcpy (filename, file, len);
 	      memcpy (filename + len, ".#dwz#.XXXXXX",
 		      sizeof (".#dwz#.XXXXXX"));
@@ -11056,10 +11068,27 @@ dwz (const char *file, const char *outfile, struct file_result *res,
 		      unlink (filename);
 		    }
 		}
+	      if (tracing)
+		fprintf (stderr,
+			 "Updating hardlink %s to changed file failed\n", file);
 	    }
 	}
     }
 
+  if (tracing)
+    {
+      fprintf (stderr, "Compressing %s", file);
+      if (multifile_mode == 0)
+	;
+      else if (low_mem)
+	fprintf (stderr, " in low-mem mode");
+      else if (fi_multifile)
+	fprintf (stderr, " in finalize-multifile mode");
+      else
+	abort ();
+      fprintf (stderr, "\n");
+    }
+
   dso = fdopen_dso (fd, file);
   if (dso == NULL)
     return 1;
@@ -11356,6 +11385,8 @@ optimize_multifile (void)
   memset (&dsobuf, '\0', sizeof (dsobuf));
   dso = &dsobuf;
   dso->filename = multifile;
+  if (tracing)
+    fprintf (stderr, "Optimize-multifile\n");
   multifile_mode = MULTIFILE_MODE_OP;
 
   obstack_alloc_failed_handler = dwz_oom;
@@ -11645,6 +11676,8 @@ read_multifile (int fd)
   DSO *dso, *volatile ret;
   unsigned int i;
 
+  if (tracing)
+    fprintf (stderr, "Read-multifile\n");
   multifile_mode = MULTIFILE_MODE_RD;
   dso = fdopen_dso (fd, multifile);
   if (dso == NULL)
@@ -11790,6 +11823,7 @@ static struct option dwz_options[] =
   { "multifile-name",	 required_argument, 0, 'M' },
   { "relative",		 no_argument,	    0, 'r' },
   { "version",		 no_argument,	    0, 'v' },
+  { "trace",		 no_argument,	    0, 't' },
   { NULL,		 no_argument,	    0, 0 }
 };
 
@@ -11834,7 +11868,8 @@ main (int argc, char *argv[])
   while (1)
     {
       int option_index;
-      int c = getopt_long (argc, argv, "m:o:qhl:L:M:r?v", dwz_options, &option_index);
+      int c = getopt_long (argc, argv, "m:o:qhl:L:M:r?vt", dwz_options,
+			   &option_index);
       if (c == -1)
 	break;
       switch (c)
@@ -11885,6 +11920,10 @@ main (int argc, char *argv[])
 	case 'v':
 	  version ();
 	  break;
+
+	case 't':
+	  tracing = true;
+	  break;
 	}
     }
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [committed] Add --devel-trace
  2019-01-01  0:00 [PATCH] Add --trace/-t Tom de Vries
@ 2019-01-01  0:00 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz, jakub

[-- Attachment #1: Type: text/plain, Size: 217 bytes --]

[ was: Re: [PATCH] Add --trace/-t ]

On 08-03-19 12:33, Tom de Vries wrote:
> Hi,
> 
> Add a tracing option, to show more information about how dwz is progressing.
> 

Added as developer-only option.

Thanks,
- Tom



[-- Attachment #2: 0001-Add-devel-trace.patch --]
[-- Type: text/x-patch, Size: 4724 bytes --]

Add --devel-trace

Add a developer-only tracing option, to show more information about how dwz is
progressing.

The option is developer-only, meaning:
- not listed in usage
- only available with long option name, starting with '--'
- long option name starts with '--devel-', to prevent abbreviation clashes
  with user options.

Regular mode:
...
$ dwz --devel-trace a.out
Compressing a.out
...

Low-mem mode:
...
$ dwz --devel-trace -l0 a.out
Compressing a.out
Hit low-mem die-limit
Compressing a.out in low-mem mode
...

Hardlink handling:
...
$ dwz --devel-trace -h a.out b.out
Compressing a.out
Updating hardlink b.out to changed file
...

Multifile mode:
...
$ dwz --devel-trace -m common.out a.out b.out
Compressing a.out
Write-multifile a.out
Compressing b.out
Write-multifile b.out
Optimize-multifile
Read-multifile
Compressing a.out in finalize-multifile mode
Compressing b.out in finalize-multifile mode
...

2019-04-01  Tom de Vries  <tdevries@suse.de>

	* dwz.c (read_debug_info, write_multifile, dwz, optimize_multifile)
	(read_multifile): Add tracing.
	(main): Add parsing of --devel-trace.
	* testsuite/dwz.tests/devel-trace.sh: New test.

---
 dwz.c                              | 35 +++++++++++++++++++++++++++++++++++
 testsuite/dwz.tests/devel-trace.sh |  5 +++++
 2 files changed, 40 insertions(+)

diff --git a/dwz.c b/dwz.c
index 8ad613d..f1416fa 100644
--- a/dwz.c
+++ b/dwz.c
@@ -136,6 +136,8 @@ static struct obstack ob2;
    and restored during final cleanup.  */
 static struct obstack alt_ob, alt_ob2;
 
+static int tracing;
+
 typedef struct
 {
   Elf *elf;
@@ -4733,6 +4735,8 @@ read_debug_info (DSO *dso, int kind)
 		 caller that it should retry with low_mem.  */
 	      if (likely (!low_mem) && ndies == low_mem_die_limit)
 		{
+		  if (tracing)
+		    fprintf (stderr, "Hit low-mem die-limit\n");
 		  ret = 2;
 		  goto fail;
 		}
@@ -10824,6 +10828,8 @@ write_multifile (DSO *dso)
 	  *cup = (*cup)->cu_next;
       *cup = NULL;
       multifile_mode = MULTIFILE_MODE_WR;
+      if (tracing)
+	fprintf (stderr, "Write-multifile %s\n", dso->filename);
       if (compute_abbrevs (NULL))
 	ret = 1;
       else if (debug_sections[DEBUG_MACRO].data && read_macro (dso))
@@ -11029,6 +11035,9 @@ dwz (const char *file, const char *outfile, struct file_result *res,
 	     state.  */
 	  if (resa[n].res == 1)
 	    {
+	      if (tracing)
+		fprintf (stderr, "Skipping hardlink %s to unchanged file\n",
+			 file);
 	      close (fd);
 	      res->res = -2;
 	      return 1;
@@ -11039,6 +11048,9 @@ dwz (const char *file, const char *outfile, struct file_result *res,
 	      size_t len = strlen (file);
 	      char *filename = alloca (len + sizeof (".#dwz#.XXXXXX"));
 	      int fd2;
+	      if (tracing)
+		fprintf (stderr, "Updating hardlink %s to changed file\n",
+			 file);
 	      memcpy (filename, file, len);
 	      memcpy (filename + len, ".#dwz#.XXXXXX",
 		      sizeof (".#dwz#.XXXXXX"));
@@ -11062,6 +11074,20 @@ dwz (const char *file, const char *outfile, struct file_result *res,
 	}
     }
 
+  if (tracing)
+    {
+      fprintf (stderr, "Compressing %s", file);
+      if (multifile_mode == 0)
+	;
+      else if (low_mem)
+	fprintf (stderr, " in low-mem mode");
+      else if (fi_multifile)
+	fprintf (stderr, " in finalize-multifile mode");
+      else
+	abort ();
+      fprintf (stderr, "\n");
+    }
+
   dso = fdopen_dso (fd, file);
   if (dso == NULL)
     return 1;
@@ -11358,6 +11384,8 @@ optimize_multifile (void)
   memset (&dsobuf, '\0', sizeof (dsobuf));
   dso = &dsobuf;
   dso->filename = multifile;
+  if (tracing)
+    fprintf (stderr, "Optimize-multifile\n");
   multifile_mode = MULTIFILE_MODE_OP;
 
   obstack_alloc_failed_handler = dwz_oom;
@@ -11647,6 +11675,8 @@ read_multifile (int fd)
   DSO *dso, *volatile ret;
   unsigned int i;
 
+  if (tracing)
+    fprintf (stderr, "Read-multifile\n");
   multifile_mode = MULTIFILE_MODE_RD;
   dso = fdopen_dso (fd, multifile);
   if (dso == NULL)
@@ -11792,6 +11822,7 @@ static struct option dwz_options[] =
   { "multifile-name",	 required_argument, 0, 'M' },
   { "relative",		 no_argument,	    0, 'r' },
   { "version",		 no_argument,	    0, 'v' },
+  { "devel-trace",	 no_argument,	    &tracing, 1 },
   { NULL,		 no_argument,	    0, 0 }
 };
 
@@ -11846,6 +11877,10 @@ main (int argc, char *argv[])
 	  usage ();
 	  break;
 
+	case 0:
+	  /* Option handled by getopt_long.  */
+	  break;
+
 	case 'o':
 	  outfile = optarg;
 	  break;
diff --git a/testsuite/dwz.tests/devel-trace.sh b/testsuite/dwz.tests/devel-trace.sh
new file mode 100644
index 0000000..089cb52
--- /dev/null
+++ b/testsuite/dwz.tests/devel-trace.sh
@@ -0,0 +1,5 @@
+cp ../hello 1
+
+dwz --devel-trace 1 2>/dev/null
+
+rm -f 1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-04-01  6:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01  0:00 [PATCH] Add --trace/-t Tom de Vries
2019-01-01  0:00 ` [committed] Add --devel-trace Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).