summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordump2file <[email protected]>2019-01-24 15:20:18 +0600
committerdump2file <[email protected]>2019-01-24 15:20:18 +0600
commitc1543c1f08af61b296fe3de0ac31f3411f349c23 (patch)
treeaf77254de090a2c5f7e836307b3808572111a8b1
parentd7a6f7ff4cb7bc4f353deba13fe5b9f46e8afc9f (diff)
使用clock_gettime计算包延迟,输出单位为ns
-rw-r--r--packet_io/packet_io.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/packet_io/packet_io.c b/packet_io/packet_io.c
index 9bee7c7..e2a2ea7 100644
--- a/packet_io/packet_io.c
+++ b/packet_io/packet_io.c
@@ -451,7 +451,11 @@ static int mesa_default_pkt_cb(const raw_pkt_t *p_raw_pkt, unsigned char dir, in
int ret = PASS;
long long before_call = 0, after_call, timecost;
- before_call = sapp_get_cpu_cycle();
+ struct timespec start, end;
+
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ //before_call = sapp_get_cpu_cycle();
+
#if CYCLE_PKT_DUMP
cycle_pkt_dump(thread_num, p_raw_pkt);
#endif
@@ -487,12 +491,12 @@ static int mesa_default_pkt_cb(const raw_pkt_t *p_raw_pkt, unsigned char dir, in
}
}
- after_call = sapp_get_cpu_cycle();
- if(after_call > before_call){ //cross second
- timecost = after_call - before_call;
- timestamp_region_update(thread_num, timecost);
- sapp_fs2_set_latency(thread_num, timecost);
- }
+ //after_call = sapp_get_cpu_cycle();
+ //timecost = after_call - before_call;
+ clock_gettime(CLOCK_MONOTONIC, &end);
+ timecost = (end.tv_sec - start.tv_sec)*1000000 + (end.tv_nsec - start.tv_nsec)/1000;
+ timestamp_region_update(thread_num, timecost);
+ sapp_fs2_set_latency(thread_num, timecost);
#if DEBUG
if(unlikely(g_timestamp_record_sw)){