timestamp_trace.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  3. * Copyright (c) 2013-2018 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. #ifndef TIMESTAMP_TRACE_H_
  19. #define TIMESTAMP_TRACE_H_
  20. #include "config.h"
  21. #include "defines.h"
  22. #define TRACE_MAX_ENTRIES 15000
  23. uint32_t trace_num;
  24. struct timestamp_trace_entry {
  25. COUNTER skip_length;
  26. COUNTER size;
  27. COUNTER bytes_sent;
  28. COUNTER now_us;
  29. COUNTER tx_us;
  30. COUNTER next_tx_us;
  31. COUNTER sent_bits;
  32. struct timeval timestamp;
  33. };
  34. typedef struct timestamp_trace_entry timestamp_trace_entry_t;
  35. #ifdef TIMESTAMP_TRACE
  36. timestamp_trace_entry_t timestamp_trace_entry_array[TRACE_MAX_ENTRIES];
  37. static inline void update_current_timestamp_trace_entry(COUNTER bytes_sent,
  38. COUNTER now_us, COUNTER tx_us, COUNTER next_tx_us)
  39. {
  40. if (trace_num >= TRACE_MAX_ENTRIES)
  41. return;
  42. if (!now_us) {
  43. struct timeval now;
  44. gettimeofday(&now, NULL);
  45. now_us = TIMSTAMP_TO_MICROSEC(&now);
  46. }
  47. timestamp_trace_entry_array[trace_num].bytes_sent = bytes_sent;
  48. timestamp_trace_entry_array[trace_num].now_us = now_us;
  49. timestamp_trace_entry_array[trace_num].tx_us = tx_us;
  50. timestamp_trace_entry_array[trace_num].next_tx_us = next_tx_us;
  51. }
  52. static inline void add_timestamp_trace_entry(COUNTER size,
  53. struct timeval *timestamp, COUNTER skip_length)
  54. {
  55. if (trace_num >= TRACE_MAX_ENTRIES)
  56. return;
  57. timestamp_trace_entry_array[trace_num].skip_length = skip_length;
  58. timestamp_trace_entry_array[trace_num].size = size;
  59. timestamp_trace_entry_array[trace_num].timestamp.tv_sec = timestamp->tv_sec;
  60. timestamp_trace_entry_array[trace_num].timestamp.tv_usec = timestamp->tv_usec;
  61. ++trace_num;
  62. }
  63. static inline void dump_timestamp_trace_array(const struct timeval *start,
  64. const struct timeval *stop, const COUNTER bps)
  65. {
  66. uint32_t i;
  67. COUNTER start_us = TIMEVAL_TO_MICROSEC(start);
  68. printf("dump_timestamp_trace_array: start=%zd.%06zd stop=%zd.%06zd start_us=%llu traces=%u bps=%llu\n",
  69. start->tv_sec, start->tv_usec,
  70. stop->tv_sec, stop->tv_usec,
  71. start_us,
  72. trace_num, bps);
  73. for (i = 0; i < trace_num; ++i) {
  74. long long int delta = timestamp_trace_entry_array[i].tx_us -
  75. timestamp_trace_entry_array[i].next_tx_us;
  76. printf("timestamp=%zd.%zd, size=%llu now_us=%llu tx_us=%llu next_tx_us=%llu delta=%lld bytes_sent=%llu skip=%llu\n",
  77. timestamp_trace_entry_array[i].timestamp.tv_sec,
  78. timestamp_trace_entry_array[i].timestamp.tv_usec,
  79. timestamp_trace_entry_array[i].size,
  80. timestamp_trace_entry_array[i].now_us,
  81. timestamp_trace_entry_array[i].tx_us,
  82. timestamp_trace_entry_array[i].next_tx_us,
  83. delta,
  84. timestamp_trace_entry_array[i].bytes_sent,
  85. timestamp_trace_entry_array[i].skip_length);
  86. }
  87. }
  88. #else
  89. static inline void update_current_timestamp_trace_entry(COUNTER UNUSED(bytes_sent), COUNTER UNUSED(now_us),
  90. COUNTER UNUSED(tx_us), COUNTER UNUSED(next_tx_us)) { }
  91. static inline void add_timestamp_trace_entry(COUNTER UNUSED(size), struct timeval *UNUSED(timestamp),
  92. COUNTER UNUSED(skip_length)) { }
  93. static inline void dump_timestamp_trace_array(const struct timeval *UNUSED(start),
  94. const struct timeval *UNUSED(stop), const COUNTER UNUSED(bps)) { }
  95. #endif /* TIMESTAMP_TRACE */
  96. #endif /* TIMESTAMP_TRACE_H_ */