timestamp_trace.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  3. * Copyright (c) 2013-2022 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  4. *
  5. * The Tcpreplay Suite of tools is free software: you can redistribute it
  6. * and/or modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or with the authors permission any later version.
  9. *
  10. * The Tcpreplay Suite is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with the Tcpreplay Suite. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #include "defines.h"
  20. #include "config.h"
  21. #define TRACE_MAX_ENTRIES 15000
  22. struct timestamp_trace_entry {
  23. COUNTER skip_length;
  24. COUNTER size;
  25. COUNTER bytes_sent;
  26. COUNTER now_us;
  27. COUNTER tx_us;
  28. COUNTER next_tx_us;
  29. COUNTER sent_bits;
  30. struct timeval timestamp;
  31. };
  32. typedef struct timestamp_trace_entry timestamp_trace_entry_t;
  33. #ifdef TIMESTAMP_TRACE
  34. uint32_t trace_num;
  35. timestamp_trace_entry_t timestamp_trace_entry_array[TRACE_MAX_ENTRIES];
  36. static inline void
  37. update_current_timestamp_trace_entry(COUNTER bytes_sent, COUNTER now_us, COUNTER tx_us, COUNTER next_tx_us)
  38. {
  39. if (trace_num >= TRACE_MAX_ENTRIES)
  40. return;
  41. if (!now_us) {
  42. struct timeval now;
  43. gettimeofday(&now, NULL);
  44. now_us = TIMSTAMP_TO_MICROSEC(&now);
  45. }
  46. timestamp_trace_entry_array[trace_num].bytes_sent = bytes_sent;
  47. timestamp_trace_entry_array[trace_num].now_us = now_us;
  48. timestamp_trace_entry_array[trace_num].tx_us = tx_us;
  49. timestamp_trace_entry_array[trace_num].next_tx_us = next_tx_us;
  50. }
  51. static inline void
  52. add_timestamp_trace_entry(COUNTER size, struct timeval *timestamp, COUNTER skip_length)
  53. {
  54. if (trace_num >= TRACE_MAX_ENTRIES)
  55. return;
  56. timestamp_trace_entry_array[trace_num].skip_length = skip_length;
  57. timestamp_trace_entry_array[trace_num].size = size;
  58. timestamp_trace_entry_array[trace_num].timestamp.tv_sec = timestamp->tv_sec;
  59. timestamp_trace_entry_array[trace_num].timestamp.tv_usec = timestamp->tv_usec;
  60. ++trace_num;
  61. }
  62. static inline void
  63. dump_timestamp_trace_array(const struct timeval *start, const struct timeval *stop, const COUNTER bps)
  64. {
  65. uint32_t i;
  66. COUNTER start_us = TIMEVAL_TO_MICROSEC(start);
  67. printf("dump_timestamp_trace_array: start=%zd.%06zd stop=%zd.%06zd start_us=%llu traces=%u bps=%llu\n",
  68. start->tv_sec,
  69. start->tv_usec,
  70. stop->tv_sec,
  71. stop->tv_usec,
  72. start_us,
  73. trace_num,
  74. bps);
  75. for (i = 0; i < trace_num; ++i) {
  76. long long int delta = timestamp_trace_entry_array[i].tx_us - timestamp_trace_entry_array[i].next_tx_us;
  77. printf("timestamp=%zd.%zd, size=%llu now_us=%llu tx_us=%llu next_tx_us=%llu delta=%lld bytes_sent=%llu skip=%llu\n",
  78. timestamp_trace_entry_array[i].timestamp.tv_sec,
  79. timestamp_trace_entry_array[i].timestamp.tv_usec,
  80. timestamp_trace_entry_array[i].size,
  81. timestamp_trace_entry_array[i].now_us,
  82. timestamp_trace_entry_array[i].tx_us,
  83. timestamp_trace_entry_array[i].next_tx_us,
  84. delta,
  85. timestamp_trace_entry_array[i].bytes_sent,
  86. timestamp_trace_entry_array[i].skip_length);
  87. }
  88. }
  89. #else
  90. static inline void
  91. update_current_timestamp_trace_entry(COUNTER UNUSED(bytes_sent),
  92. COUNTER UNUSED(now_us),
  93. COUNTER UNUSED(tx_us),
  94. COUNTER UNUSED(next_tx_us))
  95. {}
  96. static inline void
  97. add_timestamp_trace_entry(COUNTER UNUSED(size), struct timeval *UNUSED(timestamp), COUNTER UNUSED(skip_length))
  98. {}
  99. static inline void
  100. dump_timestamp_trace_array(const struct timeval *UNUSED(start),
  101. const struct timeval *UNUSED(stop),
  102. const COUNTER UNUSED(bps))
  103. {}
  104. #endif /* TIMESTAMP_TRACE */