From 5539dba1df313816491bb28718433d4d81162aa3 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 10 Jan 2016 18:07:24 +0100 Subject: [PATCH] Do not apply color rule filter every dissection Introduce a frame_data flag "need_colorize" to indicate that coloring rules need to be evaluated and set it for the GUI (not tshark). This restores the original performance characteristics. It additionally fixes a regression where the color filter name and filter is not shown anymore in the tree (I guess it is related to the edt->tree being NULL when re-selected, resulting in empty color_filter). Remaining problems: - Display filter cannot contain frame.coloring_rule.* fields. Code is present to enable this, but then a method is needed to avoid an expensive second calculation (which is why it is disabled). - The columns are still not updated after coloring rule change. - The two frame.coloring_rule fields in the tree are not updated when the coloring rule is changed (e.g. Ctrl-1). The last two issues were supposed to be fixed by the previous patch, but there is probably some missing code... Tested with GTK and Qt. Bug: 11980 Change-Id: I3ef7713b28db242e178d20f6a5f333374718b52e Reviewed-on: https://code.wireshark.org/review/13170 Petri-Dish: Alexis La Goutte Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- epan/dissectors/file-file.c | 11 ++++++++--- epan/dissectors/packet-frame.c | 12 ++++++++---- epan/frame_data.h | 1 + file.c | 9 +++++++++ ui/gtk/packet_list_store.c | 4 +++- ui/qt/packet_list_record.cpp | 5 ++++- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/epan/dissectors/file-file.c b/epan/dissectors/file-file.c index e61d4310bf..0c092edbda 100644 --- a/epan/dissectors/file-file.c +++ b/epan/dissectors/file-file.c @@ -298,9 +298,14 @@ dissect_file_record(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, ENDTRY; } - /* XXX optimize this so it doesn't need to scan the second time */ - color_filter = color_filters_colorize_packet(file_data->color_edt); - + /* Attempt to (re-)calculate color filters (if any). */ + if (pinfo->fd->flags.need_colorize) { + color_filter = color_filters_colorize_packet(file_data->color_edt); + pinfo->fd->color_filter = color_filter; + pinfo->fd->flags.need_colorize = 0; + } else { + color_filter = pinfo->fd->color_filter; + } if (color_filter) { pinfo->fd->color_filter = color_filter; item = proto_tree_add_string(fh_tree, hf_file_color_filter_name, tvb, diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c index 2cec2d50fa..83e6c963f9 100644 --- a/epan/dissectors/packet-frame.c +++ b/epan/dissectors/packet-frame.c @@ -616,11 +616,15 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* ENDTRY; } - /* XXX optimize this so it doesn't need to scan the second time */ - color_filter = color_filters_colorize_packet(fr_data->color_edt); - - if (color_filter) { + /* Attempt to (re-)calculate color filters (if any). */ + if (pinfo->fd->flags.need_colorize) { + color_filter = color_filters_colorize_packet(fr_data->color_edt); pinfo->fd->color_filter = color_filter; + pinfo->fd->flags.need_colorize = 0; + } else { + color_filter = pinfo->fd->color_filter; + } + if (color_filter) { item = proto_tree_add_string(fh_tree, hf_frame_color_filter_name, tvb, 0, 0, color_filter->filter_name); PROTO_ITEM_SET_GENERATED(item); diff --git a/epan/frame_data.h b/epan/frame_data.h index ef859d9818..6dec802645 100644 --- a/epan/frame_data.h +++ b/epan/frame_data.h @@ -84,6 +84,7 @@ typedef struct _frame_data { unsigned int has_ts : 1; /**< 1 = has time stamp, 0 = no time stamp */ unsigned int has_phdr_comment : 1; /** 1 = there's comment for this packet */ unsigned int has_user_comment : 1; /** 1 = user set (also deleted) comment for this packet */ + unsigned int need_colorize : 1; /**< 1 = need to (re-)calculate packet color */ } flags; gint16 tsprec; /**< Time stamp precision */ diff --git a/file.c b/file.c index 44ff87b142..125976f778 100644 --- a/file.c +++ b/file.c @@ -1099,6 +1099,15 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, if (dfcode != NULL) { epan_dissect_prime_dfilter(edt, dfcode); } +#if 0 + /* Prepare coloring rules, this ensures that display filter rules containing + * frame.color_rule references are still processed. + * TODO: actually detect that situation or maybe apply other optimizations? */ + if (edt->tree && color_filters_used()) { + color_filters_prime_edt(edt); + fdata->flags.need_colorize = 1; + } +#endif /* Dissect the frame. */ epan_dissect_run_with_taps(edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, buf), fdata, cinfo); diff --git a/ui/gtk/packet_list_store.c b/ui/gtk/packet_list_store.c index 5be13931a8..bbfe866f2e 100644 --- a/ui/gtk/packet_list_store.c +++ b/ui/gtk/packet_list_store.c @@ -1152,8 +1152,10 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord * create_proto_tree, FALSE /* proto_tree_visible */); - if (dissect_color) + if (dissect_color) { color_filters_prime_edt(&edt); + fdata->flags.need_colorize = 1; + } if (dissect_columns) col_custom_prime_edt(&edt, cinfo); diff --git a/ui/qt/packet_list_record.cpp b/ui/qt/packet_list_record.cpp index b6659db550..bdd17905a6 100644 --- a/ui/qt/packet_list_record.cpp +++ b/ui/qt/packet_list_record.cpp @@ -140,8 +140,11 @@ void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color) create_proto_tree, FALSE /* proto_tree_visible */); - if (dissect_color) + /* Re-color when the coloring rules are changed via the UI. */ + if (dissect_color) { color_filters_prime_edt(&edt); + fdata_->flags.need_colorize = 1; + } if (dissect_columns) col_custom_prime_edt(&edt, cinfo);