Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
io_graph_item.h
Go to the documentation of this file.
1
14#ifndef __IO_GRAPH_ITEM_H__
15#define __IO_GRAPH_ITEM_H__
16
17#include <epan/cfile.h>
18#include <wsutil/ws_assert.h>
19
20#include <epan/epan_dissect.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
45
46
56typedef struct _io_graph_item_t {
57 uint32_t frames;
58 uint64_t bytes;
59 uint64_t fields;
62 union {
64 double double_max;
65 int64_t int_max;
66 uint64_t uint_max;
67 };
68
70 union {
72 double double_min;
73 int64_t int_min;
74 uint64_t uint_min;
75 };
76
78 union {
80 double double_tot;
81 };
82
88
94static inline void
95reset_io_graph_items(io_graph_item_t *items, size_t count, int hf_index _U_) {
96 io_graph_item_t *item;
97 size_t i;
98
99 for (i = 0; i < count; i++) {
100 item = &items[i];
101
102 item->frames = 0;
103 item->bytes = 0;
104 item->fields = 0;
105 item->first_frame_in_invl = 0;
106 item->min_frame_in_invl = 0;
107 item->max_frame_in_invl = 0;
108 item->last_frame_in_invl = 0;
109
110 nstime_set_zero(&item->time_max);
111 nstime_set_zero(&item->time_min);
112 nstime_set_zero(&item->time_tot);
113
114#if 0
115 /* XXX - On C, type punning is explicitly allowed since C99 so
116 * setting the nstime_t values to 0 is always sufficient.
117 * On C++ that appears technically to be undefined behavior (though
118 * I don't know of any compilers for which it doesn't work and I
119 * can't get UBSAN to complain about it) and this would be safer.
120 */
121 if (hf_index > 0) {
122
123 switch (proto_registrar_get_ftype(hf_index)) {
124
125 case FT_INT8:
126 case FT_INT16:
127 case FT_INT24:
128 case FT_INT32:
129 case FT_INT40:
130 case FT_INT48:
131 case FT_INT56:
132 case FT_INT64:
133 item->int_max = 0;
134 item->int_min = 0;
135 item->double_tot = 0;
136 break;
137
138 case FT_UINT8:
139 case FT_UINT16:
140 case FT_UINT24:
141 case FT_UINT32:
142 case FT_UINT40:
143 case FT_UINT48:
144 case FT_UINT56:
145 case FT_UINT64:
146 item->uint_max = 0;
147 item->uint_min = 0;
148 item->double_tot = 0;
149 break;
150
151 case FT_DOUBLE:
152 case FT_FLOAT:
153 item->double_max = 0;
154 item->double_min = 0;
155 item->double_tot = 0;
156 break;
157
158 case FT_RELATIVE_TIME:
159 nstime_set_zero(&item->time_max);
160 nstime_set_zero(&item->time_min);
161 nstime_set_zero(&item->time_tot);
162 break;
163
164 default:
165 break;
166 }
167 }
168#endif
169 }
170}
171
183int64_t get_io_graph_index(packet_info *pinfo, int interval);
184
195GString *check_field_unit(const char *field_name, int *hf_index, io_graph_item_unit_t item_unit, const char* type_unit_name);
196
208double get_io_graph_item(const io_graph_item_t *items, io_graph_item_unit_t val_units, int idx, int hf_index, const capture_file *cap_file, int interval, int cur_idx, bool asAOT);
209
224static inline bool
225update_io_graph_item(io_graph_item_t *items, int idx, packet_info *pinfo, epan_dissect_t *edt, int hf_index, int item_unit, uint32_t interval) {
226 io_graph_item_t *item = &items[idx];
227
228 /* Set the first and last frame num in current interval matching the target field+filter */
229 if (item->first_frame_in_invl == 0) {
230 item->first_frame_in_invl = pinfo->num;
231 }
232 item->last_frame_in_invl = pinfo->num;
233
234 if (edt && hf_index >= 0) {
235 GPtrArray *gp;
236 unsigned i;
237
238 gp = proto_get_finfo_ptr_array(edt->tree, hf_index);
239 if (!gp) {
240 return false;
241 }
242
243 /* Update the appropriate counters. If fields == 0, this is the first seen
244 * value so set any min/max values accordingly. */
245 for (i=0; i < gp->len; i++) {
246 int64_t new_int64;
247 uint64_t new_uint64;
248 float new_float;
249 double new_double;
250 const nstime_t *new_time;
251
252 switch (proto_registrar_get_ftype(hf_index)) {
253 case FT_UINT8:
254 case FT_UINT16:
255 case FT_UINT24:
256 case FT_UINT32:
257 new_uint64 = fvalue_get_uinteger(((field_info *)gp->pdata[i])->value);
258
259 if ((new_uint64 > item->uint_max) || (item->fields == 0)) {
260 item->uint_max = new_uint64;
261 item->max_frame_in_invl = pinfo->num;
262 }
263 if ((new_uint64 < item->uint_min) || (item->fields == 0)) {
264 item->uint_min = new_uint64;
265 item->min_frame_in_invl = pinfo->num;
266 }
267 item->double_tot += (double)new_uint64;
268 item->fields++;
269 break;
270 case FT_INT8:
271 case FT_INT16:
272 case FT_INT24:
273 case FT_INT32:
274 new_int64 = fvalue_get_sinteger(((field_info *)gp->pdata[i])->value);
275 if ((new_int64 > item->int_max) || (item->fields == 0)) {
276 item->int_max = new_int64;
277 item->max_frame_in_invl = pinfo->num;
278 }
279 if ((new_int64 < item->int_min) || (item->fields == 0)) {
280 item->int_min = new_int64;
281 item->min_frame_in_invl = pinfo->num;
282 }
283 item->double_tot += (double)new_int64;
284 item->fields++;
285 break;
286 case FT_UINT40:
287 case FT_UINT48:
288 case FT_UINT56:
289 case FT_UINT64:
290 new_uint64 = fvalue_get_uinteger64(((field_info *)gp->pdata[i])->value);
291 if ((new_uint64 > item->uint_max) || (item->fields == 0)) {
292 item->uint_max = new_uint64;
293 item->max_frame_in_invl = pinfo->num;
294 }
295 if ((new_uint64 < item->uint_min) || (item->fields == 0)) {
296 item->uint_min = new_uint64;
297 item->min_frame_in_invl = pinfo->num;
298 }
299 item->double_tot += (double)new_uint64;
300 item->fields++;
301 break;
302 case FT_INT40:
303 case FT_INT48:
304 case FT_INT56:
305 case FT_INT64:
306 new_int64 = fvalue_get_sinteger64(((field_info *)gp->pdata[i])->value);
307 if ((new_int64 > item->int_max) || (item->fields == 0)) {
308 item->int_max = new_int64;
309 item->max_frame_in_invl = pinfo->num;
310 }
311 if ((new_int64 < item->int_min) || (item->fields == 0)) {
312 item->int_min = new_int64;
313 item->min_frame_in_invl = pinfo->num;
314 }
315 item->double_tot += (double)new_int64;
316 item->fields++;
317 break;
318 case FT_FLOAT:
319 new_float = (float)fvalue_get_floating(((field_info *)gp->pdata[i])->value);
320 if ((new_float > item->double_max) || (item->fields == 0)) {
321 item->double_max = new_float;
322 item->max_frame_in_invl = pinfo->num;
323 }
324 if ((new_float < item->double_min) || (item->fields == 0)) {
325 item->double_min = new_float;
326 item->min_frame_in_invl = pinfo->num;
327 }
328 item->double_tot += new_float;
329 item->fields++;
330 break;
331 case FT_DOUBLE:
332 new_double = fvalue_get_floating(((field_info *)gp->pdata[i])->value);
333 if ((new_double > item->double_max) || (item->fields == 0)) {
334 item->double_max = new_double;
335 item->max_frame_in_invl = pinfo->num;
336 }
337 if ((new_double < item->double_min) || (item->fields == 0)) {
338 item->double_min = new_double;
339 item->min_frame_in_invl = pinfo->num;
340 }
341 item->double_tot += new_double;
342 item->fields++;
343 break;
344 case FT_RELATIVE_TIME:
345 new_time = fvalue_get_time(((field_info *)gp->pdata[i])->value);
346
347 switch (item_unit) {
349 {
350 uint64_t t, pt; /* time in us */
351 int j;
352 /*
353 * Add the time this call spanned each interval according to
354 * its contribution to that interval.
355 * If the call time is negative (unlikely, requires both an
356 * out of order capture file plus retransmission), ignore.
357 */
358 const nstime_t time_zero = NSTIME_INIT_ZERO;
359 if (nstime_cmp(new_time, &time_zero) < 0) {
360 break;
361 }
362 t = new_time->secs;
363 t = t * 1000000 + new_time->nsecs / 1000;
364 j = idx;
365 /*
366 * Handle current interval
367 * This cannot be negative, because get_io_graph_index
368 * returns an invalid interval if so.
369 */
370 pt = pinfo->rel_ts.secs * 1000000 + pinfo->rel_ts.nsecs / 1000;
371 pt = pt % interval;
372 if (pt > t) {
373 pt = t;
374 }
375 while (t) {
376 io_graph_item_t *load_item;
377
378 load_item = &items[j];
379 load_item->time_tot.nsecs += (int) (pt * 1000);
380 if (load_item->time_tot.nsecs > 1000000000) {
381 load_item->time_tot.secs++;
382 load_item->time_tot.nsecs -= 1000000000;
383 }
384 load_item->fields++;
385
386 if (j == 0) {
387 break;
388 }
389 j--;
390 t -= pt;
391 if (t > (uint64_t) interval) {
392 pt = (uint64_t) interval;
393 } else {
394 pt = t;
395 }
396 }
397 break;
398 }
399 default:
400 if ( (nstime_cmp(new_time, &item->time_max) > 0)
401 || (item->fields == 0)) {
402 item->time_max = *new_time;
403 item->max_frame_in_invl = pinfo->num;
404 }
405 if ( (nstime_cmp(new_time, &item->time_min) < 0)
406 || (item->fields == 0)) {
407 item->time_min = *new_time;
408 item->min_frame_in_invl = pinfo->num;
409 }
410 nstime_add(&item->time_tot, new_time);
411 item->fields++;
412 }
413 break;
414 default:
415 if ((item_unit == IOG_ITEM_UNIT_CALC_FRAMES) ||
416 (item_unit == IOG_ITEM_UNIT_CALC_FIELDS)) {
417 /*
418 * It's not an integeresque type, but
419 * all we want to do is count it, so
420 * that's all right.
421 */
422 item->fields++;
423 }
424 else {
425 /*
426 * "Can't happen"; see the "check that the
427 * type is compatible" check in
428 * filter_callback().
429 */
431 }
432 break;
433 }
434 }
435 }
436
437 item->frames++;
438 item->bytes += pinfo->fd->pkt_len;
439
440 return true;
441}
442
443
444#ifdef __cplusplus
445}
446#endif /* __cplusplus */
447
448#endif /* __IO_GRAPH_ITEM_H__ */
@ FT_INT64
Definition ftypes.h:46
@ FT_FLOAT
Definition ftypes.h:49
@ FT_INT16
Definition ftypes.h:40
@ FT_RELATIVE_TIME
Definition ftypes.h:52
@ FT_UINT64
Definition ftypes.h:38
@ FT_INT32
Definition ftypes.h:42
@ FT_INT8
Definition ftypes.h:39
@ FT_INT40
Definition ftypes.h:43
@ FT_UINT24
Definition ftypes.h:33
@ FT_INT24
Definition ftypes.h:41
@ FT_UINT8
Definition ftypes.h:31
@ FT_INT48
Definition ftypes.h:44
@ FT_DOUBLE
Definition ftypes.h:50
@ FT_INT56
Definition ftypes.h:45
@ FT_UINT48
Definition ftypes.h:36
@ FT_UINT16
Definition ftypes.h:32
@ FT_UINT32
Definition ftypes.h:34
@ FT_UINT56
Definition ftypes.h:37
@ FT_UINT40
Definition ftypes.h:35
enum ftenum proto_registrar_get_ftype(const int n)
Definition proto.c:11546
GPtrArray * proto_get_finfo_ptr_array(const proto_tree *tree, const int id)
Definition proto.c:11634
GString * check_field_unit(const char *field_name, int *hf_index, io_graph_item_unit_t item_unit, const char *type_unit_name)
Definition io_graph_item.c:43
struct _io_graph_item_t io_graph_item_t
Accumulated statistics for all frames falling within a single I/O graph time interval.
int64_t get_io_graph_index(packet_info *pinfo, int interval)
Definition io_graph_item.c:24
double get_io_graph_item(const io_graph_item_t *items, io_graph_item_unit_t val_units, int idx, int hf_index, const capture_file *cap_file, int interval, int cur_idx, bool asAOT)
Definition io_graph_item.c:141
io_graph_item_unit_t
Selects the Y-axis value unit or aggregate calculation mode for an I/O graph plot.
Definition io_graph_item.h:29
@ IOG_ITEM_UNIT_CALC_FIELDS
Definition io_graph_item.h:36
@ IOG_ITEM_UNIT_BITS
Definition io_graph_item.h:33
@ IOG_ITEM_UNIT_CALC_SUM
Definition io_graph_item.h:34
@ IOG_ITEM_UNIT_CALC_MIN
Definition io_graph_item.h:38
@ IOG_ITEM_UNIT_CALC_THROUGHPUT
Definition io_graph_item.h:40
@ IOG_ITEM_UNIT_BYTES
Definition io_graph_item.h:32
@ IOG_ITEM_UNIT_CALC_FRAMES
Definition io_graph_item.h:35
@ IOG_ITEM_UNIT_PACKETS
Definition io_graph_item.h:31
@ IOG_ITEM_UNIT_CALC_LOAD
Definition io_graph_item.h:41
@ IOG_ITEM_UNIT_LAST
Definition io_graph_item.h:42
@ NUM_IOG_ITEM_UNITS
Definition io_graph_item.h:43
@ IOG_ITEM_UNIT_CALC_MAX
Definition io_graph_item.h:37
@ IOG_ITEM_UNIT_CALC_AVERAGE
Definition io_graph_item.h:39
@ IOG_ITEM_UNIT_FIRST
Definition io_graph_item.h:30
#define nstime_add(sum, a)
Adds a time value to an existing sum.
Definition nstime.h:208
Represents a capture file and its associated metadata.
Definition cfile.h:84
Accumulated statistics for all frames falling within a single I/O graph time interval.
Definition io_graph_item.h:56
int64_t int_max
Definition io_graph_item.h:65
uint32_t max_frame_in_invl
Definition io_graph_item.h:85
nstime_t time_tot
Definition io_graph_item.h:79
double double_min
Definition io_graph_item.h:72
double double_tot
Definition io_graph_item.h:80
uint32_t frames
Definition io_graph_item.h:57
uint64_t uint_min
Definition io_graph_item.h:74
uint32_t min_frame_in_invl
Definition io_graph_item.h:84
nstime_t time_max
Definition io_graph_item.h:63
uint64_t fields
Definition io_graph_item.h:59
nstime_t time_min
Definition io_graph_item.h:71
uint64_t uint_max
Definition io_graph_item.h:66
int64_t int_min
Definition io_graph_item.h:73
double double_max
Definition io_graph_item.h:64
uint32_t first_frame_in_invl
Definition io_graph_item.h:83
uint64_t bytes
Definition io_graph_item.h:58
uint32_t last_frame_in_invl
Definition io_graph_item.h:86
Represents the metadata and indexing information for a single captured frame.
Definition packet_info.h:43
frame_data * fd
Definition packet_info.h:53
uint32_t num
Definition packet_info.h:47
nstime_t rel_ts
Definition packet_info.h:49
Holds all state for the dissection of a single byte array, including session, buffer,...
Definition epan_dissect.h:28
proto_tree * tree
Definition epan_dissect.h:31
Definition proto.h:817
Definition nstime.h:26
#define ws_assert_not_reached()
Unconditionally abort execution if reached; always indicates a programming error.
Definition ws_assert.h:166