MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rte_pcapng_write_stats

Function rte_pcapng_write_stats

dpdk/lib/pcapng/rte_pcapng.c:323–386  ·  view source on GitHub ↗

* Write an Interface statistics block at the end of capture. */

Source from the content-addressed store, hash-verified

321 * Write an Interface statistics block at the end of capture.
322 */
323ssize_t
324rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port_id,
325 uint64_t ifrecv, uint64_t ifdrop,
326 const char *comment)
327{
328 struct pcapng_statistics *hdr;
329 struct pcapng_option *opt;
330 uint64_t start_time = self->offset_ns;
331 uint64_t sample_time;
332 uint32_t optlen, len;
333 uint32_t buf[PCAPNG_BLKSIZ];
334
335 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
336
337 optlen = 0;
338
339 if (ifrecv != UINT64_MAX)
340 optlen += pcapng_optlen(sizeof(ifrecv));
341 if (ifdrop != UINT64_MAX)
342 optlen += pcapng_optlen(sizeof(ifdrop));
343
344 if (start_time != 0)
345 optlen += pcapng_optlen(sizeof(start_time));
346
347 if (comment)
348 optlen += pcapng_optlen(strlen(comment));
349 if (optlen != 0)
350 optlen += pcapng_optlen(0);
351
352 len = sizeof(*hdr) + optlen + sizeof(uint32_t);
353 if (len > sizeof(buf))
354 return -1;
355
356 hdr = (struct pcapng_statistics *)buf;
357 opt = (struct pcapng_option *)(hdr + 1);
358
359 if (comment)
360 opt = pcapng_add_option(opt, PCAPNG_OPT_COMMENT,
361 comment, strlen(comment));
362 if (start_time != 0)
363 opt = pcapng_add_option(opt, PCAPNG_ISB_STARTTIME,
364 &start_time, sizeof(start_time));
365 if (ifrecv != UINT64_MAX)
366 opt = pcapng_add_option(opt, PCAPNG_ISB_IFRECV,
367 &ifrecv, sizeof(ifrecv));
368 if (ifdrop != UINT64_MAX)
369 opt = pcapng_add_option(opt, PCAPNG_ISB_IFDROP,
370 &ifdrop, sizeof(ifdrop));
371 if (optlen != 0)
372 opt = pcapng_add_option(opt, PCAPNG_OPT_END, NULL, 0);
373
374 hdr->block_type = PCAPNG_INTERFACE_STATS_BLOCK;
375 hdr->block_length = len;
376 hdr->interface_id = self->port_index[port_id];
377
378 sample_time = pcapng_timestamp(self, rte_get_tsc_cycles());
379 hdr->timestamp_hi = sample_time >> 32;
380 hdr->timestamp_lo = (uint32_t)sample_time;

Callers 2

report_packet_statsFunction · 0.85
test_write_packetsFunction · 0.85

Calls 6

pcapng_optlenFunction · 0.85
pcapng_add_optionFunction · 0.85
pcapng_timestampFunction · 0.85
rte_get_tsc_cyclesFunction · 0.50
memcpyFunction · 0.50
writeFunction · 0.50

Tested by 1

test_write_packetsFunction · 0.68