This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gdb/symfile.c: Transfer rate calculation


The transfer rate calculation in print_transfer_performance uses a
time unit of whole seconds. This gross time unit limits the accuracy
of the calculation, since the number of elapsed whole seconds usually
has only one significant digit. This patch adds
print_transfer_performance_ms which uses a time unit of milliseconds.
It leaves the semantics of print_transfer_performance unchanged
because gdb/m32r-rom.c and gdb/remote-m32r-sdi.c use it.

Cheers,
Shaun

2005-07-08  Shaun Jackman  <sjackman@gmail.com>

	* gdb/symfile.c (print_transfer_performance_ms): New function.
	Use gettimeofday instead of date to obtain microsecond precision. 
	(print_transfer_performance): Call print_transfer_performance_ms.

--- ./gdb/symfile.c-	2004-06-24 15:09:34.000000000 -0700
+++ ./gdb/symfile.c	2005-07-08 16:25:05.000000000 -0700
@@ -54,6 +54,7 @@
 #include "gdb_string.h"
 #include "gdb_stat.h"
 #include <ctype.h>
+#include <sys/time.h>
 #include <time.h>
 
  #ifndef O_BINARY
@@ -92,6 +93,9 @@
 
  static void symbol_file_add_main_1 (char *args, int from_tty, int flags);
 
+static void print_transfer_performance_ms (struct ui_file *,
+    unsigned long, unsigned long, unsigned long);
+
 static void add_symbol_file_command (char *, int);
 
 static void add_shared_symbol_files_command (char *, int);
@@ -1460,7 +1464,7 @@
 {
   asection *s;
   bfd *loadfile_bfd;
-  time_t start_time, end_time;	/* Start and end times of download */
+  struct timeval start_time, end_time;	/* Start and end times of download */
   char *filename;
   struct cleanup *old_cleanups;
   char *offptr;
@@ -1512,11 +1516,11 @@
   bfd_map_over_sections (loadfile_bfd, add_section_size_callback,
  			 (void *) &cbdata.total_size);
 
-  start_time = time (NULL);
+  gettimeofday(&start_time, NULL);
 
   bfd_map_over_sections (loadfile_bfd, load_section_callback, &cbdata);
 
-  end_time = time (NULL);
+  gettimeofday(&end_time, NULL);
 
   entry = bfd_get_start_address (loadfile_bfd);
   ui_out_text (uiout, "Start address ");
@@ -1534,8 +1538,10 @@
      file is loaded in.  Some targets do (e.g., remote-vx.c) but
      others don't (or didn't - perhaphs they have all been deleted).  */
 
-  print_transfer_performance (gdb_stdout, cbdata.data_count,
-			      cbdata.write_count, end_time - start_time);
+  print_transfer_performance_ms (gdb_stdout, cbdata.data_count,
+			      cbdata.write_count,
+				  (end_time.tv_sec - start_time.tv_sec)*1000 +
+				  (end_time.tv_usec - start_time.tv_usec)/1000);
 
   do_cleanups (old_cleanups);
 }
@@ -1554,8 +1560,8 @@
 			      end_time - start_time, 0);
 }
 
-void
-print_transfer_performance (struct ui_file *stream,
+static void
+print_transfer_performance_ms (struct ui_file *stream,
 			    unsigned long data_count,
 			    unsigned long write_count,
 			    unsigned long time_count)
@@ -1564,8 +1570,8 @@
   if (time_count > 0)
     {
       ui_out_field_fmt (uiout, "transfer-rate", "%lu",
-			(data_count * 8) / time_count);
-      ui_out_text (uiout, " bits/sec");
+			1000 * data_count / time_count);
+      ui_out_text (uiout, " bytes/sec");
     }
   else
     {
@@ -1581,6 +1587,16 @@
   ui_out_text (uiout, ".\n");
 }
 
+void
+print_transfer_performance (struct ui_file *stream,
+			    unsigned long data_count,
+			    unsigned long write_count,
+			    unsigned long time_count)
+{
+  print_transfer_performance_ms(stream, data_count, write_count,
+				1000*time_count);
+}
+
 /* This function allows the addition of incrementally linked object files.
    It does not modify any state in the target, only in the debugger.  */
  /* Note: ezannoni 2000-04-13 This function/command used to have a
2005-07-08  Shaun Jackman  <sjackman@gmail.com>

	* gdb/symfile.c (print_transfer_performance_ms): New function.
	Use gettimeofday instead of date to obtain microsecond precision. 
	(print_transfer_performance): Call print_transfer_performance_ms.

--- ./gdb/symfile.c-	2004-06-24 15:09:34.000000000 -0700
+++ ./gdb/symfile.c	2005-07-08 16:25:05.000000000 -0700
@@ -54,6 +54,7 @@
 #include "gdb_string.h"
 #include "gdb_stat.h"
 #include <ctype.h>
+#include <sys/time.h>
 #include <time.h>
 
 #ifndef O_BINARY
@@ -92,6 +93,9 @@
 
 static void symbol_file_add_main_1 (char *args, int from_tty, int flags);
 
+static void print_transfer_performance_ms (struct ui_file *,
+    unsigned long, unsigned long, unsigned long);
+
 static void add_symbol_file_command (char *, int);
 
 static void add_shared_symbol_files_command (char *, int);
@@ -1460,7 +1464,7 @@
 {
   asection *s;
   bfd *loadfile_bfd;
-  time_t start_time, end_time;	/* Start and end times of download */
+  struct timeval start_time, end_time;	/* Start and end times of download */
   char *filename;
   struct cleanup *old_cleanups;
   char *offptr;
@@ -1512,11 +1516,11 @@
   bfd_map_over_sections (loadfile_bfd, add_section_size_callback,
 			 (void *) &cbdata.total_size);
 
-  start_time = time (NULL);
+  gettimeofday(&start_time, NULL);
 
   bfd_map_over_sections (loadfile_bfd, load_section_callback, &cbdata);
 
-  end_time = time (NULL);
+  gettimeofday(&end_time, NULL);
 
   entry = bfd_get_start_address (loadfile_bfd);
   ui_out_text (uiout, "Start address ");
@@ -1534,8 +1538,10 @@
      file is loaded in.  Some targets do (e.g., remote-vx.c) but
      others don't (or didn't - perhaphs they have all been deleted).  */
 
-  print_transfer_performance (gdb_stdout, cbdata.data_count,
-			      cbdata.write_count, end_time - start_time);
+  print_transfer_performance_ms (gdb_stdout, cbdata.data_count,
+			      cbdata.write_count,
+				  (end_time.tv_sec - start_time.tv_sec)*1000 +
+				  (end_time.tv_usec - start_time.tv_usec)/1000);
 
   do_cleanups (old_cleanups);
 }
@@ -1554,8 +1560,8 @@
 			      end_time - start_time, 0);
 }
 
-void
-print_transfer_performance (struct ui_file *stream,
+static void
+print_transfer_performance_ms (struct ui_file *stream,
 			    unsigned long data_count,
 			    unsigned long write_count,
 			    unsigned long time_count)
@@ -1564,8 +1570,8 @@
   if (time_count > 0)
     {
       ui_out_field_fmt (uiout, "transfer-rate", "%lu",
-			(data_count * 8) / time_count);
-      ui_out_text (uiout, " bits/sec");
+			1000 * data_count / time_count);
+      ui_out_text (uiout, " bytes/sec");
     }
   else
     {
@@ -1581,6 +1587,16 @@
   ui_out_text (uiout, ".\n");
 }
 
+void
+print_transfer_performance (struct ui_file *stream,
+			    unsigned long data_count,
+			    unsigned long write_count,
+			    unsigned long time_count)
+{
+  print_transfer_performance_ms(stream, data_count, write_count,
+				1000*time_count);
+}
+
 /* This function allows the addition of incrementally linked object files.
    It does not modify any state in the target, only in the debugger.  */
 /* Note: ezannoni 2000-04-13 This function/command used to have a

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]