Skip to content

Commit

Permalink
Replace relative timestamp with reference frame number. Saves 16B per…
Browse files Browse the repository at this point in the history
… frame.

svn path=/trunk/; revision=50772
  • Loading branch information
jwzawadzki committed Jul 21, 2013
1 parent 74b6c59 commit c702e92
Show file tree
Hide file tree
Showing 42 changed files with 222 additions and 138 deletions.
2 changes: 1 addition & 1 deletion asn1/t38/t38.cnf
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ VAL_PTR=&Data_Field_field_type_value
/* we use the first fragment's frame_number as fragment ID because the protocol doesn't provide it */
p_t38_conv_info->reass_ID = actx->pinfo->fd->num;
p_t38_conv_info->reass_start_seqnum = seq_number;
p_t38_conv_info->time_first_t4_data = nstime_to_sec(&actx->pinfo->fd->rel_ts);
p_t38_conv_info->time_first_t4_data = nstime_to_sec(&actx->pinfo->rel_ts);
p_t38_conv_info->additional_hdlc_data_field_counter = 0;
p_t38_packet_conv_info->reass_ID = p_t38_conv_info->reass_ID;
p_t38_packet_conv_info->reass_start_seqnum = p_t38_conv_info->reass_start_seqnum;
Expand Down
19 changes: 14 additions & 5 deletions epan/column-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,20 +971,25 @@ set_time_hour_min_sec(const nstime_t *ts, gchar *buf)
static void
col_set_rel_time(const frame_data *fd, column_info *cinfo, const int col)
{
nstime_t del_rel_ts;

if (!fd->flags.has_ts) {
cinfo->col_buf[col][0] = '\0';
return;
}

frame_delta_abs_time(cinfo->epan, fd, fd->frame_ref_num, &del_rel_ts);

switch (timestamp_get_seconds_type()) {
case TS_SECONDS_DEFAULT:
set_time_seconds(&fd->rel_ts, cinfo->col_buf[col]);
set_time_seconds(&del_rel_ts, cinfo->col_buf[col]);
cinfo->col_expr.col_expr[col] = "frame.time_relative";
g_strlcpy(cinfo->col_expr.col_expr_val[col],cinfo->col_buf[col],COL_MAX_LEN);
break;
case TS_SECONDS_HOUR_MIN_SEC:
set_time_hour_min_sec(&fd->rel_ts, cinfo->col_buf[col]);
set_time_hour_min_sec(&del_rel_ts, cinfo->col_buf[col]);
cinfo->col_expr.col_expr[col] = "frame.time_relative";
set_time_seconds(&fd->rel_ts, cinfo->col_expr.col_expr_val[col]);
set_time_seconds(&del_rel_ts, cinfo->col_expr.col_expr_val[col]);
break;
default:
g_assert_not_reached();
Expand Down Expand Up @@ -1208,12 +1213,16 @@ set_fd_time(const epan_t *epan, frame_data *fd, gchar *buf)

case TS_RELATIVE:
if (fd->flags.has_ts) {
nstime_t del_rel_ts;

frame_delta_abs_time(epan, fd, fd->frame_ref_num, &del_rel_ts);

switch (timestamp_get_seconds_type()) {
case TS_SECONDS_DEFAULT:
set_time_seconds(&fd->rel_ts, buf);
set_time_seconds(&del_rel_ts, buf);
break;
case TS_SECONDS_HOUR_MIN_SEC:
set_time_seconds(&fd->rel_ts, buf);
set_time_seconds(&del_rel_ts, buf);
break;
default:
g_assert_not_reached();
Expand Down
2 changes: 1 addition & 1 deletion epan/dissectors/packet-frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
}

item = proto_tree_add_time(fh_tree, hf_frame_time_relative, tvb,
0, 0, &(pinfo->fd->rel_ts));
0, 0, &(pinfo->rel_ts));
PROTO_ITEM_SET_GENERATED(item);

if(pinfo->fd->flags.ref_time){
Expand Down
2 changes: 1 addition & 1 deletion epan/dissectors/packet-t38.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ dissect_t38_T_field_data(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_
/* we use the first fragment's frame_number as fragment ID because the protocol doesn't provide it */
p_t38_conv_info->reass_ID = actx->pinfo->fd->num;
p_t38_conv_info->reass_start_seqnum = seq_number;
p_t38_conv_info->time_first_t4_data = nstime_to_sec(&actx->pinfo->fd->rel_ts);
p_t38_conv_info->time_first_t4_data = nstime_to_sec(&actx->pinfo->rel_ts);
p_t38_conv_info->additional_hdlc_data_field_counter = 0;
p_t38_packet_conv_info->reass_ID = p_t38_conv_info->reass_ID;
p_t38_packet_conv_info->reass_start_seqnum = p_t38_conv_info->reass_start_seqnum;
Expand Down
47 changes: 29 additions & 18 deletions epan/frame_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ frame_data_time_delta_compare(const struct epan_session *epan, const frame_data
return COMPARE_TS_REAL(del_cap_ts1, del_cap_ts2);
}

static gint
frame_data_time_delta_rel_compare(const struct epan_session *epan, const frame_data *fdata1, const frame_data *fdata2)
{
nstime_t del_rel_ts1, del_rel_ts2;

frame_delta_abs_time(epan, fdata1, fdata1->frame_ref_num, &del_rel_ts1);
frame_delta_abs_time(epan, fdata2, fdata2->frame_ref_num, &del_rel_ts2);

return COMPARE_TS_REAL(del_rel_ts1, del_rel_ts2);
}

static gint
frame_data_time_delta_dis_compare(const struct epan_session *epan, const frame_data *fdata1, const frame_data *fdata2)
{
Expand Down Expand Up @@ -207,7 +218,7 @@ frame_data_compare(const struct epan_session *epan, const frame_data *fdata1, co
return COMPARE_TS(abs_ts);

case TS_RELATIVE:
return COMPARE_TS(rel_ts);
return frame_data_time_delta_rel_compare(epan, fdata1, fdata2);

case TS_DELTA:
return frame_data_time_delta_compare(epan, fdata1, fdata2);
Expand All @@ -227,7 +238,7 @@ frame_data_compare(const struct epan_session *epan, const frame_data *fdata1, co
return COMPARE_TS(abs_ts);

case COL_REL_TIME:
return COMPARE_TS(rel_ts);
return frame_data_time_delta_rel_compare(epan, fdata1, fdata2);

case COL_DELTA_TIME:
return frame_data_time_delta_compare(epan, fdata1, fdata2);
Expand Down Expand Up @@ -277,40 +288,40 @@ frame_data_init(frame_data *fdata, guint32 num,
fdata->abs_ts.nsecs = phdr->ts.nsecs;
fdata->shift_offset.secs = 0;
fdata->shift_offset.nsecs = 0;
fdata->rel_ts.secs = 0;
fdata->rel_ts.nsecs = 0;
fdata->frame_ref_num = 0;
fdata->prev_dis_num = 0;
fdata->opt_comment = phdr->opt_comment;
}

void
frame_data_set_before_dissect(frame_data *fdata,
nstime_t *elapsed_time,
nstime_t *first_ts,
const frame_data **frame_ref,
const frame_data *prev_dis)
{
/* If we don't have the time stamp of the first packet in the
capture, it's because this is the first packet. Save the time
stamp of this packet as the time stamp of the first packet. */
if (nstime_is_unset(first_ts))
*first_ts = fdata->abs_ts;

/* if this frames is marked as a reference time frame, reset
firstsec and firstusec to this frame */
nstime_t rel_ts;

/* Don't have the reference frame, set to current */
if (*frame_ref == NULL)
*frame_ref = fdata;

/* if this frames is marked as a reference time frame,
set reference frame this frame */
if(fdata->flags.ref_time)
*first_ts = fdata->abs_ts;
*frame_ref = fdata;

/* Get the time elapsed between the first packet and this packet. */
nstime_delta(&fdata->rel_ts, &fdata->abs_ts, first_ts);
nstime_delta(&rel_ts, &fdata->abs_ts, &(*frame_ref)->abs_ts);

/* If it's greater than the current elapsed time, set the elapsed time
to it (we check for "greater than" so as not to be confused by
time moving backwards). */
if ((gint32)elapsed_time->secs < fdata->rel_ts.secs
|| ((gint32)elapsed_time->secs == fdata->rel_ts.secs && (gint32)elapsed_time->nsecs < fdata->rel_ts.nsecs)) {
*elapsed_time = fdata->rel_ts;
if ((gint32)elapsed_time->secs < rel_ts.secs
|| ((gint32)elapsed_time->secs == rel_ts.secs && (gint32)elapsed_time->nsecs < rel_ts.nsecs)) {
*elapsed_time = rel_ts;
}

fdata->frame_ref_num = (*frame_ref != fdata) ? (*frame_ref)->num : 0;
fdata->prev_dis_num = (prev_dis) ? prev_dis->num : 0;
}

Expand Down
4 changes: 2 additions & 2 deletions epan/frame_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ typedef struct _frame_data {

nstime_t abs_ts; /**< Absolute timestamp */
nstime_t shift_offset; /**< How much the abs_tm of the frame is shifted */
nstime_t rel_ts; /**< Relative timestamp (yes, it can be negative) */
guint32 frame_ref_num; /**< Previous reference frame (0 if this is one) */
guint32 prev_dis_num; /**< Previous displayed frame (0 if first one) */
gchar *opt_comment; /**< NULL if not available */
} frame_data;
Expand Down Expand Up @@ -124,7 +124,7 @@ extern void frame_delta_abs_time(const struct epan_session *epan, const frame_da
*/
WS_DLL_PUBLIC void frame_data_set_before_dissect(frame_data *fdata,
nstime_t *elapsed_time,
nstime_t *first_ts,
const frame_data **frame_ref,
const frame_data *prev_dis);

WS_DLL_PUBLIC void frame_data_set_after_dissect(frame_data *fdata,
Expand Down
2 changes: 2 additions & 0 deletions epan/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ dissect_packet(epan_dissect_t *edt, struct wtap_pkthdr *phdr,
edt->pi.link_dir = LINK_DIR_UNKNOWN;
edt->tvb = tvb;

frame_delta_abs_time(edt->session, fd, fd->frame_ref_num, &edt->pi.rel_ts);

/* to enable decode as for ethertype=0x0000 (fix for bug 4721) */
edt->pi.ethertype = G_MAXINT;

Expand Down
1 change: 1 addition & 0 deletions epan/packet_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ typedef struct _packet_info {

struct _wmem_allocator_t *pool; /**< Memory pool scoped to the pinfo struct */
struct epan_session *epan;
nstime_t rel_ts; /**< Relative timestamp (yes, it can be negative) */
} packet_info;

/**< For old code that hasn't yet been changed. */
Expand Down
2 changes: 1 addition & 1 deletion epan/stats_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ extern int
stats_tree_packet(void *p, packet_info *pinfo, epan_dissect_t *edt, const void *pri)
{
stats_tree *st = (stats_tree *)p;
double now = nstime_to_msec(&pinfo->fd->rel_ts);
double now = nstime_to_msec(&pinfo->rel_ts);

if (st->start < 0.0) st->start = now;

Expand Down
2 changes: 1 addition & 1 deletion epan/wslua/wslua_pinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ PINFO_GET_NUMBER(Pinfo_number,pinfo->ws_pinfo->fd->num)
PINFO_GET_NUMBER(Pinfo_len,pinfo->ws_pinfo->fd->pkt_len)
PINFO_GET_NUMBER(Pinfo_caplen,pinfo->ws_pinfo->fd->cap_len)
PINFO_GET_NUMBER(Pinfo_abs_ts,lua_nstime_to_sec(&pinfo->ws_pinfo->fd->abs_ts))
PINFO_GET_NUMBER(Pinfo_rel_ts,lua_nstime_to_sec(&pinfo->ws_pinfo->fd->rel_ts))
PINFO_GET_NUMBER(Pinfo_rel_ts,lua_nstime_to_sec(&pinfo->ws_pinfo->rel_ts))
PINFO_GET_NUMBER(Pinfo_delta_ts,lua_delta_nstime_to_sec(pinfo, pinfo->ws_pinfo->fd, pinfo->ws_pinfo->fd->num - 1))
PINFO_GET_NUMBER(Pinfo_delta_dis_ts,lua_delta_nstime_to_sec(pinfo, pinfo->ws_pinfo->fd, pinfo->ws_pinfo->fd->prev_dis_num))
PINFO_GET_NUMBER(Pinfo_ipproto,pinfo->ws_pinfo->ipproto)
Expand Down
30 changes: 15 additions & 15 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ gboolean auto_scroll_live;
#endif

static guint32 cum_bytes;
static nstime_t first_ts;
const static frame_data *ref;
static frame_data *prev_dis;
static frame_data *prev_cap;

Expand Down Expand Up @@ -397,7 +397,7 @@ cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
cf->frames = new_frame_data_sequence();

nstime_set_zero(&cf->elapsed_time);
nstime_set_unset(&first_ts);
ref = NULL;
prev_dis = NULL;
prev_cap = NULL;
cum_bytes = 0;
Expand Down Expand Up @@ -1155,7 +1155,7 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
gint row = -1;

frame_data_set_before_dissect(fdata, &cf->elapsed_time,
&first_ts, prev_dis);
&ref, prev_dis);
prev_cap = fdata;

/* Dissect the frame. */
Expand Down Expand Up @@ -1871,7 +1871,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb
/* Iterate through the list of frames. Call a routine for each frame
to check whether it should be displayed and, if so, add it to
the display list. */
nstime_set_unset(&first_ts);
ref = NULL;
prev_dis = NULL;
prev_cap = NULL;
cum_bytes = 0;
Expand Down Expand Up @@ -2108,8 +2108,9 @@ ref_time_packets(capture_file *cf)
{
guint32 framenum;
frame_data *fdata;
nstime_t rel_ts;

nstime_set_unset(&first_ts);
ref = NULL;
prev_dis = NULL;
cum_bytes = 0;

Expand All @@ -2126,14 +2127,12 @@ ref_time_packets(capture_file *cf)
/* If we don't have the time stamp of the first packet in the
capture, it's because this is the first packet. Save the time
stamp of this packet as the time stamp of the first packet. */
if (nstime_is_unset(&first_ts)) {
first_ts = fdata->abs_ts;
}
if (ref == NULL)
ref = fdata;
/* if this frames is marked as a reference time frame, reset
firstsec and firstusec to this frame */
if (fdata->flags.ref_time) {
first_ts = fdata->abs_ts;
}
if (fdata->flags.ref_time)
ref = fdata;

/* If we don't have the time stamp of the previous displayed packet,
it's because this is the first displayed packet. Save the time
Expand All @@ -2144,14 +2143,15 @@ ref_time_packets(capture_file *cf)
}

/* Get the time elapsed between the first packet and this packet. */
nstime_delta(&fdata->rel_ts, &fdata->abs_ts, &first_ts);
fdata->frame_ref_num = (fdata != ref) ? ref->num : 0;
nstime_delta(&rel_ts, &fdata->abs_ts, &ref->abs_ts);

/* If it's greater than the current elapsed time, set the elapsed time
to it (we check for "greater than" so as not to be confused by
time moving backwards). */
if ((gint32)cf->elapsed_time.secs < fdata->rel_ts.secs
|| ((gint32)cf->elapsed_time.secs == fdata->rel_ts.secs && (gint32)cf->elapsed_time.nsecs < fdata->rel_ts.nsecs)) {
cf->elapsed_time = fdata->rel_ts;
if ((gint32)cf->elapsed_time.secs < rel_ts.secs
|| ((gint32)cf->elapsed_time.secs == rel_ts.secs && (gint32)cf->elapsed_time.nsecs < rel_ts.nsecs)) {
cf->elapsed_time = rel_ts;
}

/* If this frame is displayed, get the time elapsed between the
Expand Down
15 changes: 12 additions & 3 deletions rawshark.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@
static const gchar decode_as_arg_template[] = "<layer_type>==<selector>,<decode_as_protocol>";

static guint32 cum_bytes;
static nstime_t first_ts;
static const frame_data *ref;
static frame_data ref_frame;
static frame_data *prev_dis;
static frame_data prev_dis_frame;
static frame_data *prev_cap;
Expand Down Expand Up @@ -1074,7 +1075,12 @@ process_packet(capture_file *cf, gint64 offset, struct wtap_pkthdr *whdr,
printf("%lu", (unsigned long int) cf->count);

frame_data_set_before_dissect(&fdata, &cf->elapsed_time,
&first_ts, prev_dis);
&ref, prev_dis);

if (ref == &fdata) {
ref_frame = fdata;
ref = &ref_frame;
}

/* We only need the columns if we're printing packet info but we're
*not* verbose; in verbose mode, we print the protocol tree, not
Expand Down Expand Up @@ -1569,6 +1575,9 @@ open_failure_message(const char *filename, int err, gboolean for_writing)
const nstime_t *
raw_get_frame_ts(void *data _U_, guint32 frame_num)
{
if (ref && ref->num == frame_num)
return &ref->abs_ts;

if (prev_dis && prev_dis->num == frame_num)
return &prev_dis->abs_ts;

Expand Down Expand Up @@ -1622,7 +1631,7 @@ raw_cf_open(capture_file *cf, const char *fname)
cf->has_snap = FALSE;
cf->snap = WTAP_MAX_PACKET_SIZE;
nstime_set_zero(&cf->elapsed_time);
nstime_set_unset(&first_ts);
ref = NULL;
prev_dis = NULL;
prev_cap = NULL;

Expand Down
Loading

0 comments on commit c702e92

Please sign in to comment.