Add a "fieldcount" report to tshark -G to let us easily see how many fields

are registered.

Change-Id: I06f10d96916640cb9a782cae87898a5dd6c9c6e3
Reviewed-on: https://code.wireshark.org/review/10601
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Jeff Morriss 2015-09-21 15:00:35 -04:00 committed by Anders Broman
parent e64c81609f
commit cd7387d22b
4 changed files with 50 additions and 0 deletions

View File

@ -387,6 +387,8 @@ is one record per line. The fields are tab-delimited.
* Field 3 = type (textual representation of the ftenum type)
* Field 4 = base for display (for integer types)
B<fieldcount> Dumps the number of header fields to stdout.
B<fields> Dumps the contents of the registration database to
stdout. An independent program can take this output and format it into nice
tables or HTML or whatever. There is one record per line. Each record is

View File

@ -7806,6 +7806,48 @@ proto_registrar_dump_values(void)
}
}
/* Prints the number of registered fields.
* Useful for determining an appropriate value for
* PROTO_PRE_ALLOC_HF_FIELDS_MEM.
*/
void
proto_registrar_dump_fieldcount(void)
{
guint32 i;
header_field_info *hfinfo;
guint32 deregistered_count = 0;
guint32 same_name_count = 0;
guint32 protocol_count = 0;
for (i = 0; i < gpa_hfinfo.len; i++) {
if (gpa_hfinfo.hfi[i] == NULL) {
deregistered_count++;
continue; /* This is a deregistered protocol or header field */
}
PROTO_REGISTRAR_GET_NTH(i, hfinfo);
if (proto_registrar_is_protocol(i))
protocol_count++;
if (hfinfo->same_name_prev_id != -1)
same_name_count++;
}
printf("There are %d header fields registered, of which:\n"
"\t%d are deregistered\n"
"\t%d are protocols\n"
"\t%d have the same name as another field\n\n",
gpa_hfinfo.len, deregistered_count, protocol_count,
same_name_count);
printf("The header field table consumes %d KiB of memory.\n",
(int)(gpa_hfinfo.allocated_len * sizeof(header_field_info *) / 1024));
printf("The fields themselves consume %d KiB of memory.\n",
(int)(gpa_hfinfo.len * sizeof(header_field_info) / 1024));
}
/* Dumps the contents of the registration database to stdout. An independent
* program can take this output and format it into nice tables or HTML or
* whatever.

View File

@ -2251,6 +2251,9 @@ WS_DLL_PUBLIC void proto_registrar_dump_protocols(void);
/** Dumps a glossary of the field value strings or true/false strings to STDOUT */
WS_DLL_PUBLIC void proto_registrar_dump_values(void);
/** Dumps the number of protocol and field registrations to STDOUT. */
WS_DLL_PUBLIC void proto_registrar_dump_fieldcount(void);
/** Dumps a glossary of the protocol and field registrations to STDOUT. */
WS_DLL_PUBLIC void proto_registrar_dump_fields(void);

View File

@ -446,6 +446,7 @@ glossary_option_help(void)
fprintf(output, " -G column-formats dump column format codes and exit\n");
fprintf(output, " -G decodes dump \"layer type\"/\"decode as\" associations and exit\n");
fprintf(output, " -G dissector-tables dump dissector table names, types, and properties\n");
fprintf(output, " -G fieldcount dump count of header fields and exit\n");
fprintf(output, " -G fields dump fields glossary and exit\n");
fprintf(output, " -G ftypes dump field type basic and descriptive names\n");
fprintf(output, " -G heuristic-decodes dump heuristic dissector tables\n");
@ -1275,6 +1276,8 @@ DIAG_ON(cast-qual)
write_prefs(NULL);
else if (strcmp(argv[2], "dissector-tables") == 0)
dissector_dump_dissector_tables();
else if (strcmp(argv[2], "fieldcount") == 0)
proto_registrar_dump_fieldcount();
else if (strcmp(argv[2], "fields") == 0)
proto_registrar_dump_fields();
else if (strcmp(argv[2], "ftypes") == 0)