[3/4] pcapng: change timestamp argument to write_stats

Message ID 20230921042349.104150-4-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series pcapng fixes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Sept. 21, 2023, 4:23 a.m. UTC
  In order to cleanup the management of time base calculation,
later patch will move the calculation from pcapng to the pdump
library. One of the changes necessary is to move the timestamp
calculation in the write_stats call from the pcapng library
into the caller. Since dumpcap already does this for other timestamps
the change is rather small.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/dumpcap/main.c      | 3 ++-
 app/test/test_pcapng.c  | 4 ++--
 lib/pcapng/rte_pcapng.c | 8 +++-----
 lib/pcapng/rte_pcapng.h | 5 ++++-
 4 files changed, 11 insertions(+), 9 deletions(-)
  

Patch

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index 37754fd06f4f..8f6ab3396cef 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -577,6 +577,7 @@  report_packet_stats(dumpcap_out_t out)
 	struct rte_pdump_stats pdump_stats;
 	struct interface *intf;
 	uint64_t ifrecv, ifdrop;
+	uint64_t timestamp = create_timestamp();
 	double percent;
 
 	fputc('\n', stderr);
@@ -590,7 +591,7 @@  report_packet_stats(dumpcap_out_t out)
 
 		if (use_pcapng)
 			rte_pcapng_write_stats(out.pcapng, intf->port, NULL,
-					       start_time, end_time,
+					       timestamp, start_time, end_time,
 					       ifrecv, ifdrop);
 
 		if (ifrecv == 0)
diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c
index b8429a02f160..55aa2cf93666 100644
--- a/app/test/test_pcapng.c
+++ b/app/test/test_pcapng.c
@@ -173,8 +173,8 @@  test_write_stats(void)
 	ssize_t len;
 
 	/* write a statistics block */
-	len = rte_pcapng_write_stats(pcapng, port_id,
-				     NULL, 0, 0,
+	len = rte_pcapng_write_stats(pcapng, port_id, NULL,
+				     0, 0, 0,
 				     NUM_PACKETS, 0);
 	if (len <= 0) {
 		fprintf(stderr, "Write of statistics failed\n");
diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c
index 3c91fc77644a..ddce7bc87141 100644
--- a/lib/pcapng/rte_pcapng.c
+++ b/lib/pcapng/rte_pcapng.c
@@ -368,7 +368,7 @@  rte_pcapng_add_interface(rte_pcapng_t *self, uint16_t port,
  */
 ssize_t
 rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port_id,
-		       const char *comment,
+		       const char *comment, uint64_t sample_time,
 		       uint64_t start_time, uint64_t end_time,
 		       uint64_t ifrecv, uint64_t ifdrop)
 {
@@ -376,7 +376,6 @@  rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port_id,
 	struct pcapng_option *opt;
 	uint32_t optlen, len;
 	uint8_t *buf;
-	uint64_t ns;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
 
@@ -425,9 +424,8 @@  rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port_id,
 	hdr->block_length = len;
 	hdr->interface_id = self->port_index[port_id];
 
-	ns = pcapng_tsc_to_ns(rte_get_tsc_cycles());
-	hdr->timestamp_hi = ns >> 32;
-	hdr->timestamp_lo = (uint32_t)ns;
+	hdr->timestamp_hi = sample_time >> 32;
+	hdr->timestamp_lo = (uint32_t)sample_time;
 
 	/* clone block_length after option */
 	memcpy(opt, &len, sizeof(uint32_t));
diff --git a/lib/pcapng/rte_pcapng.h b/lib/pcapng/rte_pcapng.h
index d93cc9f73ad5..1225ed5536ff 100644
--- a/lib/pcapng/rte_pcapng.h
+++ b/lib/pcapng/rte_pcapng.h
@@ -189,7 +189,9 @@  rte_pcapng_write_packets(rte_pcapng_t *self,
  * @param port
  *  The Ethernet port to report stats on.
  * @param comment
- *   Optional comment to add to statistics.
+ *  Optional comment to add to statistics.
+ * @param timestamp
+ *  Time this statistic sample refers to in nanoseconds.
  * @param start_time
  *  The time when packet capture was started in nanoseconds.
  *  Optional: can be zero if not known.
@@ -209,6 +211,7 @@  __rte_experimental
 ssize_t
 rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port,
 		       const char *comment,
+		       uint64_t timestamp,
 		       uint64_t start_time, uint64_t end_time,
 		       uint64_t ifrecv, uint64_t ifdrop);