Print human-readable statistics by default. Raw values can be printed
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 26 Feb 2013 06:40:25 +0000 (06:40 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 26 Feb 2013 06:40:25 +0000 (06:40 +0000)
using "-M". Based on a suggestion by Hansang Bae.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@47900 f5534014-38df-0310-8fa8-9805f1628bb7

capinfos.c
doc/capinfos.pod
docbook/release-notes.xml
wsutil/str_util.c
wsutil/str_util.h

index a238e8fae54f98a5a248ce547e1a204ad9c1558b..e373663e45e9887a26cedd0fce88cc089e3359cc 100644 (file)
@@ -80,6 +80,7 @@
 #include <epan/report_err.h>
 #include "wtap.h"
 #include <wsutil/privileges.h>
+#include <wsutil/str_util.h>
 
 #ifdef HAVE_LIBGCRYPT
 #include <wsutil/wsgcrypt.h>
@@ -116,6 +117,7 @@ static gboolean long_report = TRUE;         /* By default generate long report
 static gchar table_report_header = TRUE;    /* Generate column header by default     */
 static gchar field_separator = '\t';        /* Use TAB as field separator by default */
 static gchar quote_char = '\0';             /* Do NOT quote fields by default        */
+static gboolean machine_readable = FALSE;   /* Display machine-readable numbers      */
 
 /*
  * capinfos has the ability to report on a number of
@@ -219,6 +221,8 @@ static GOptionEntry output_format_entries[] =
     "generate long report (default)", NULL },
   { "Table", 'T', 0, G_OPTION_ARG_NONE, &table_report,
     "generate table report", NULL },
+  { "machine-readable", 'M', 0, G_OPTION_ARG_NONE, &machine_readable,
+    "display machine-readable (unabbreviated) values in long reports", NULL },
   { NULL,'\0',0,G_OPTION_ARG_NONE,NULL,NULL,NULL }
 };
 
@@ -443,6 +447,7 @@ print_stats(const gchar *filename, capture_info *cf_info)
   const gchar           *file_type_string, *file_encap_string;
   time_t                start_time_t;
   time_t                stop_time_t;
+  gchar                 *size_string;
 
   /* Build printable strings for various stats */
   file_type_string = wtap_file_type_string(cf_info->file_type);
@@ -473,25 +478,76 @@ print_stats(const gchar *filename, capture_info *cf_info)
                           printf     ("Packet size limit:   inferred: %u bytes - %u bytes (range)\n",
                                       cf_info->snaplen_min_inferred, cf_info->snaplen_max_inferred);
   }
-  if (cap_packet_count)   printf     ("Number of packets:   %u\n", cf_info->packet_count);
-  if (cap_file_size)      printf     ("File size:           %" G_GINT64_MODIFIER "d bytes\n", cf_info->filesize);
-  if (cap_data_size)      printf     ("Data size:           %" G_GINT64_MODIFIER "u bytes\n", cf_info->packet_bytes);
+  if (cap_packet_count) {
+    printf     ("Number of packets:   ");
+    if (machine_readable) {
+      printf ("%u\n", cf_info->packet_count);
+    } else {
+      size_string = format_size(cf_info->packet_count, format_size_unit_none);
+      printf ("%s\n", size_string);
+      g_free(size_string);
+    }
+  }
+  if (cap_file_size) {
+    printf     ("File size:           ");
+    if (machine_readable) {
+      printf     ("%" G_GINT64_MODIFIER "d bytes\n", cf_info->filesize);
+    } else {
+      size_string = format_size(cf_info->filesize, format_size_unit_bytes);
+      printf ("%s\n", size_string);
+      g_free(size_string);
+    }
+  }
+  if (cap_data_size) {
+    printf     ("Data size:           ");
+    if (machine_readable) {
+      printf     ("%" G_GINT64_MODIFIER "u bytes\n", cf_info->packet_bytes);
+    } else {
+      size_string = format_size(cf_info->packet_bytes, format_size_unit_bytes);
+      printf ("%s\n", size_string);
+      g_free(size_string);
+    }
+  }
   if (cf_info->times_known) {
-    if (cap_duration)
+    if (cap_duration) /* XXX - shorten to hh:mm:ss */
                           print_value("Capture duration:    ", 0, " seconds",   cf_info->duration);
     if (cap_start_time)
                           printf     ("Start time:          %s", time_string(start_time_t, cf_info, TRUE));
     if (cap_end_time)
                           printf     ("End time:            %s", time_string(stop_time_t, cf_info, TRUE));
-    if (cap_data_rate_byte)
-                          print_value("Data byte rate:      ", 2, " bytes/sec",   cf_info->data_rate);
-    if (cap_data_rate_bit)
-                          print_value("Data bit rate:       ", 2, " bits/sec",    cf_info->data_rate*8);
+    if (cap_data_rate_byte) {
+                          printf     ("Data byte rate:      ");
+      if (machine_readable) {
+       print_value("", 2, " bytes/sec",   cf_info->data_rate);
+      } else {
+       size_string = format_size(cf_info->data_rate, format_size_unit_bytes_s);
+       printf ("%s\n", size_string);
+       g_free(size_string);
+      }
+    }
+    if (cap_data_rate_bit) {
+                          printf     ("Data bit rate:       ");
+      if (machine_readable) {
+        print_value("", 2, " bits/sec",    cf_info->data_rate*8);
+      } else {
+       size_string = format_size(cf_info->data_rate*8, format_size_unit_bits_s);
+       printf ("%s\n", size_string);
+       g_free(size_string);
+      }
+    }
   }
   if (cap_packet_size)    printf     ("Average packet size: %.2f bytes\n",        cf_info->packet_size);
   if (cf_info->times_known) {
-    if (cap_packet_rate)
-                          print_value("Average packet rate: ", 2, " packets/sec", cf_info->packet_rate);
+    if (cap_packet_rate) {
+                          printf     ("Average packet rate: ");
+      if (machine_readable) {
+       print_value("", 2, " packets/sec", cf_info->packet_rate);
+      } else {
+       size_string = format_size(cf_info->packet_rate, format_size_unit_none);
+       printf ("%spackets/sec\n", size_string);
+       g_free(size_string);
+      }
+    }
   }
 #ifdef HAVE_LIBGCRYPT
   if (cap_file_hashes) {
@@ -948,6 +1004,7 @@ usage(gboolean is_error)
   fprintf(output, "Output format:\n");
   fprintf(output, "  -L generate long report (default)\n");
   fprintf(output, "  -T generate table report\n");
+  fprintf(output, "  -M display machine-readable values in long reports\n");
   fprintf(output, "\n");
   fprintf(output, "Table report options:\n");
   fprintf(output, "  -R generate header record (default)\n");
@@ -1091,7 +1148,7 @@ main(int argc, char *argv[])
   g_option_context_free(ctx);
 
 #endif /* USE_GOPTION */
-  while ((opt = getopt(argc, argv, "tEcs" FILE_HASH_OPT "dluaeyizvhxoCALTRrSNqQBmb")) !=-1) {
+  while ((opt = getopt(argc, argv, "tEcs" FILE_HASH_OPT "dluaeyizvhxoCALTMRrSNqQBmb")) !=-1) {
 
     switch (opt) {
 
@@ -1192,6 +1249,10 @@ main(int argc, char *argv[])
       long_report = FALSE;
       break;
 
+    case 'M':
+      machine_readable = TRUE;
+      break;
+
     case 'R':
       table_report_header = TRUE;
       break;
index c9bef726c9314bc88ee22dc535951de64a5f3277..5ab1b59312d248d42023ff35e77108eb7dd138a7 100644 (file)
@@ -21,6 +21,7 @@ S<[ B<-i> ]>
 S<[ B<-l> ]>
 S<[ B<-L> ]>
 S<[ B<-m> ]>
+S<[ B<-M> ]>
 S<[ B<-N> ]>
 S<[ B<-o> ]>
 S<[ B<-q> ]>
@@ -177,6 +178,12 @@ is only useful when generating a table style report (-T).
 The various info values will be separated (delimited)
 from one another with a single comma "," character.
 
+=item -M
+
+Print raw (machine readable) numeric values in long reports.
+By default capinfos prints human-readable values with SI
+suffixes. Table reports (-T) always print raw values.
+
 =item -N
 
 Do not quote the infos.  This option is only useful
index 9c1c63a8a3de243f7230fb5c033dddab483fdae6..266fd61e41c30b2e32209f93eed2b405c75a6598 100644 (file)
@@ -83,6 +83,13 @@ Wireshark Info
           </para>
         </listitem>
 
+        <listitem>
+          <para>
+            Capinfos now prints human-readable statistics with SI suffixes
+           by default.
+          </para>
+        </listitem>
+
       </itemizedlist>
 
     </para>
index 9f8cac5320b5573ac54af0c9090211bb39531fc8..f2de5bfbee063b3ebf6293fa7e18066fd68c1b3a 100644 (file)
@@ -131,6 +131,9 @@ gchar *format_size(gint64 size, format_size_flags_e flags) {
                case format_size_unit_bits_s:
                        g_string_append(human_str, is_small ? "bits/s" : "bps");
                        break;
+               case format_size_unit_bytes_s:
+                       g_string_append(human_str, is_small ? "bytes/s" : "Bps");
+                       break;
                default:
                        g_assert_not_reached();
        }
index 7fc189b0ccf9ea26ee67b3702f7a2925b30ead00..120fc00820507887124c7a09e3d3fc6f0469c77c 100644 (file)
@@ -80,9 +80,9 @@ gboolean isdigit_string(guchar *string);
 typedef enum {
     format_size_unit_none    = 0,       /**< No unit will be appended. You must supply your own. */
     format_size_unit_bytes   = 1,       /**< "bytes" for un-prefixed sizes, "B" otherwise. */
-    /* XXX Do we use bytes/s anywhere? */
     format_size_unit_bits    = 2,       /**< "bits" for un-prefixed sizes, "b" otherwise. */
     format_size_unit_bits_s  = 3,       /**< "bits/s" for un-prefixed sizes, "bps" otherwise. */
+    format_size_unit_bytes_s = 4,       /**< "bytes/s" for un-prefixed sizes, "Bps" otherwise. */
     format_size_prefix_si    = 0 << 8,  /**< SI (power of 1000) prefixes will be used. */
     format_size_prefix_iec   = 1 << 8   /**< IEC (power of 1024) prefixes will be used. */
     /* XXX format_size_prefix_default_for_this_particular_os ? */