2 * Definitions and functions for IO graph items
4 * Copied from gtk/io_stat.c, (c) 2002 Ronnie Sahlberg
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #ifndef __IO_GRAPH_ITEM_H__
14 #define __IO_GRAPH_ITEM_H__
18 #endif /* __cplusplus */
22 IOG_ITEM_UNIT_PACKETS = IOG_ITEM_UNIT_FIRST,
25 IOG_ITEM_UNIT_CALC_SUM,
26 IOG_ITEM_UNIT_CALC_FRAMES,
27 IOG_ITEM_UNIT_CALC_FIELDS,
28 IOG_ITEM_UNIT_CALC_MAX,
29 IOG_ITEM_UNIT_CALC_MIN,
30 IOG_ITEM_UNIT_CALC_AVERAGE,
31 IOG_ITEM_UNIT_CALC_LOAD,
32 IOG_ITEM_UNIT_LAST = IOG_ITEM_UNIT_CALC_LOAD,
34 } io_graph_item_unit_t;
36 typedef struct _io_graph_item_t {
37 guint32 frames; /* always calculated, will hold number of frames*/
38 guint64 bytes; /* always calculated, will hold number of bytes*/
43 /* XXX - Why do we always use 64-bit ints but split floats between
55 guint32 first_frame_in_invl;
56 guint32 extreme_frame_in_invl; /* frame with min/max value */
57 guint32 last_frame_in_invl;
60 /** Reset (zero) an io_graph_item_t.
62 * @param items [in,out] Array containing the items to reset.
63 * @param count [in] The number of items in the array.
66 reset_io_graph_items(io_graph_item_t *items, gsize count) {
67 io_graph_item_t *item;
70 for (i = 0; i < count; i++) {
85 nstime_set_zero(&item->time_max);
86 nstime_set_zero(&item->time_min);
87 nstime_set_zero(&item->time_tot);
88 item->first_frame_in_invl = 0;
89 item->extreme_frame_in_invl = 0;
90 item->last_frame_in_invl = 0;
94 /** Get the interval (array index) for a packet
96 * It is up to the caller to determine if the return value is valid.
98 * @param [in] pinfo Packet of interest.
99 * @param [in] interval Time interval in milliseconds.
100 * @return Array index on success, -1 on failure.
102 int get_io_graph_index(packet_info *pinfo, int interval);
104 /** Check field and item unit compatibility
106 * @param field_name [in] Header field name to check
107 * @param hf_index [out] Assigned the header field index corresponding to field_name if valid.
109 * @param item_unit [in] The type of unit to calculate. From IOG_ITEM_UNITS.
110 * @return NULL if compatible, otherwise an error string. The string must
111 * be freed by the caller.
113 GString *check_field_unit(const char *field_name, int *hf_index, io_graph_item_unit_t item_unit);
115 /** Update the values of an io_graph_item_t.
117 * Frame and byte counts are always calculated. If edt is non-NULL advanced
118 * statistics are calculated using hfindex.
120 * @param items [in,out] Array containing the item to update.
121 * @param idx [in] Index of the item to update.
122 * @param pinfo [in] Packet containing update information.
123 * @param edt [in] Dissection information for advanced statistics. May be NULL.
124 * @param hf_index [in] Header field index for advanced statistics.
125 * @param item_unit [in] The type of unit to calculate. From IOG_ITEM_UNITS.
126 * @param interval [in] Timing interval in ms.
127 * @return TRUE if the update was successful, otherwise FALSE.
129 static inline gboolean
130 update_io_graph_item(io_graph_item_t *items, int idx, packet_info *pinfo, epan_dissect_t *edt, int hf_index, int item_unit, guint32 interval) {
131 io_graph_item_t *item = &items[idx];
133 /* Set the first and last frame num in current interval matching the target field+filter */
134 if (item->first_frame_in_invl == 0) {
135 item->first_frame_in_invl = pinfo->num;
137 item->last_frame_in_invl = pinfo->num;
139 if (edt && hf_index >= 0) {
143 gp = proto_get_finfo_ptr_array(edt->tree, hf_index);
148 /* Update the appropriate counters. If fields == 0, this is the first seen
149 * value so set any min/max values accordingly. */
150 for (i=0; i < gp->len; i++) {
157 switch (proto_registrar_get_ftype(hf_index)) {
162 new_int = fvalue_get_uinteger(&((field_info *)gp->pdata[i])->value);
164 if ((new_int > item->int_max) || (item->fields == 0)) {
165 item->int_max = new_int;
166 if (item_unit == IOG_ITEM_UNIT_CALC_MAX) {
167 item->extreme_frame_in_invl = pinfo->num;
170 if ((new_int < item->int_min) || (item->fields == 0)) {
171 item->int_min = new_int;
172 if (item_unit == IOG_ITEM_UNIT_CALC_MIN) {
173 item->extreme_frame_in_invl = pinfo->num;
176 item->int_tot += new_int;
183 new_int = fvalue_get_sinteger(&((field_info *)gp->pdata[i])->value);
184 if ((new_int > item->int_max) || (item->fields == 0)) {
185 item->int_max = new_int;
186 if (item_unit == IOG_ITEM_UNIT_CALC_MAX) {
187 item->extreme_frame_in_invl = pinfo->num;
190 if ((new_int < item->int_min) || (item->fields == 0)) {
191 item->int_min = new_int;
192 if (item_unit == IOG_ITEM_UNIT_CALC_MIN) {
193 item->extreme_frame_in_invl = pinfo->num;
196 item->int_tot += new_int;
203 new_int64 = fvalue_get_uinteger64(&((field_info *)gp->pdata[i])->value);
204 if ((new_int64 > item->int_max) || (item->fields == 0)) {
205 item->int_max = new_int64;
206 if (item_unit == IOG_ITEM_UNIT_CALC_MAX) {
207 item->extreme_frame_in_invl = pinfo->num;
210 if ((new_int64 < item->int_min) || (item->fields == 0)) {
211 item->int_min = new_int64;
212 if (item_unit == IOG_ITEM_UNIT_CALC_MIN) {
213 item->extreme_frame_in_invl = pinfo->num;
216 item->int_tot += new_int64;
223 new_int64 = fvalue_get_sinteger64(&((field_info *)gp->pdata[i])->value);
224 if ((new_int64 > item->int_max) || (item->fields == 0)) {
225 item->int_max = new_int64;
226 if (item_unit == IOG_ITEM_UNIT_CALC_MAX) {
227 item->extreme_frame_in_invl = pinfo->num;
230 if ((new_int64 < item->int_min) || (item->fields == 0)) {
231 item->int_min = new_int64;
232 if (item_unit == IOG_ITEM_UNIT_CALC_MIN) {
233 item->extreme_frame_in_invl = pinfo->num;
236 item->int_tot += new_int64;
240 new_float = (gfloat)fvalue_get_floating(&((field_info *)gp->pdata[i])->value);
241 if ((new_float > item->float_max) || (item->fields == 0)) {
242 item->float_max = new_float;
243 if (item_unit == IOG_ITEM_UNIT_CALC_MAX) {
244 item->extreme_frame_in_invl = pinfo->num;
247 if ((new_float < item->float_min) || (item->fields == 0)) {
248 item->float_min = new_float;
249 if (item_unit == IOG_ITEM_UNIT_CALC_MIN) {
250 item->extreme_frame_in_invl = pinfo->num;
253 item->float_tot += new_float;
257 new_double = fvalue_get_floating(&((field_info *)gp->pdata[i])->value);
258 if ((new_double > item->double_max) || (item->fields == 0)) {
259 item->double_max = new_double;
260 if (item_unit == IOG_ITEM_UNIT_CALC_MAX) {
261 item->extreme_frame_in_invl = pinfo->num;
264 if ((new_double < item->double_min) || (item->fields == 0)) {
265 item->double_min = new_double;
266 if (item_unit == IOG_ITEM_UNIT_CALC_MIN) {
267 item->extreme_frame_in_invl = pinfo->num;
270 item->double_tot += new_double;
273 case FT_RELATIVE_TIME:
274 new_time = (nstime_t *)fvalue_get(&((field_info *)gp->pdata[i])->value);
277 case IOG_ITEM_UNIT_CALC_LOAD:
279 guint64 t, pt; /* time in us */
282 * Add the time this call spanned each interval according to its contribution
286 t = t * 1000000 + new_time->nsecs / 1000;
289 * Handle current interval
291 pt = pinfo->rel_ts.secs * 1000000 + pinfo->rel_ts.nsecs / 1000;
292 pt = pt % (interval * 1000);
297 io_graph_item_t *load_item;
299 load_item = &items[j];
300 load_item->time_tot.nsecs += (int) (pt * 1000);
301 if (load_item->time_tot.nsecs > 1000000000) {
302 load_item->time_tot.secs++;
303 load_item->time_tot.nsecs -= 1000000000;
311 if (t > (guint64) interval * 1000) {
312 pt = (guint64) interval * 1000;
320 if ( (new_time->secs > item->time_max.secs)
321 || ( (new_time->secs == item->time_max.secs)
322 && (new_time->nsecs > item->time_max.nsecs))
323 || (item->fields == 0)) {
324 item->time_max = *new_time;
325 if (item_unit == IOG_ITEM_UNIT_CALC_MAX) {
326 item->extreme_frame_in_invl = pinfo->num;
329 if ( (new_time->secs<item->time_min.secs)
330 || ( (new_time->secs == item->time_min.secs)
331 && (new_time->nsecs < item->time_min.nsecs))
332 || (item->fields == 0)) {
333 item->time_min = *new_time;
334 if (item_unit == IOG_ITEM_UNIT_CALC_MIN) {
335 item->extreme_frame_in_invl = pinfo->num;
338 nstime_add(&item->time_tot, new_time);
343 if ((item_unit == IOG_ITEM_UNIT_CALC_FRAMES) ||
344 (item_unit == IOG_ITEM_UNIT_CALC_FIELDS)) {
346 * It's not an integeresque type, but
347 * all we want to do is count it, so
354 * "Can't happen"; see the "check that the
355 * type is compatible" check in
358 g_assert_not_reached();
366 item->bytes += pinfo->fd->pkt_len;
374 #endif /* __cplusplus */
376 #endif /* __IO_GRAPH_ITEM_H__ */
384 * indent-tabs-mode: nil
387 * ex: set shiftwidth=4 tabstop=8 expandtab:
388 * :indentSize=4:tabSize=8:noTabs=true: