timestamp_trace.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  3. * Copyright (c) 2013-2017 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, COUNTER now_us,
  38. COUNTER tx_us, COUNTER next_tx_us)
  39. {
  40. if (trace_num >= TRACE_MAX_ENTRIES)
  41. return;
  42. timestamp_trace_entry_array[trace_num].bytes_sent = bytes_sent;
  43. timestamp_trace_entry_array[trace_num].now_us = now_us;
  44. timestamp_trace_entry_array[trace_num].tx_us = tx_us;
  45. timestamp_trace_entry_array[trace_num].next_tx_us = next_tx_us;
  46. }
  47. static inline void add_timestamp_trace_entry(COUNTER size, struct timeval *timestamp, COUNTER skip_length)
  48. {
  49. if (trace_num >= TRACE_MAX_ENTRIES)
  50. return;
  51. timestamp_trace_entry_array[trace_num].skip_length = skip_length;
  52. timestamp_trace_entry_array[trace_num].size = size;
  53. timestamp_trace_entry_array[trace_num].timestamp.tv_sec = timestamp->tv_sec;
  54. timestamp_trace_entry_array[trace_num].timestamp.tv_usec = timestamp->tv_usec;
  55. ++trace_num;
  56. }
  57. static inline void dump_timestamp_trace_array(const struct timeval *start,
  58. const struct timeval *stop, const COUNTER bps)
  59. {
  60. uint32_t i;
  61. COUNTER start_us = TIMEVAL_TO_MICROSEC(start);
  62. printf("dump_timestamp_trace_array: start=%zd.%06zd stop=%zd.%06zd start_us=%llu traces=%u bps=%llu\n",
  63. start->tv_sec, start->tv_usec,
  64. stop->tv_sec, stop->tv_usec,
  65. start_us,
  66. trace_num, bps);
  67. for (i = 0; i < trace_num; ++i) {
  68. long long int delta = timestamp_trace_entry_array[i].tx_us -
  69. timestamp_trace_entry_array[i].next_tx_us;
  70. printf("timestamp=%zd.%zd, size=%llu now_us=%llu tx_us=%llu next_tx_us=%llu delta=%lld bytes_sent=%llu skip=%llu\n",
  71. timestamp_trace_entry_array[i].timestamp.tv_sec,
  72. timestamp_trace_entry_array[i].timestamp.tv_usec,
  73. timestamp_trace_entry_array[i].size,
  74. timestamp_trace_entry_array[i].now_us,
  75. timestamp_trace_entry_array[i].tx_us,
  76. timestamp_trace_entry_array[i].next_tx_us,
  77. delta,
  78. timestamp_trace_entry_array[i].bytes_sent,
  79. timestamp_trace_entry_array[i].skip_length);
  80. }
  81. }
  82. #else
  83. static inline void update_current_timestamp_trace_entry(COUNTER UNUSED(bytes_sent), COUNTER UNUSED(now_us),
  84. COUNTER UNUSED(tx_us), COUNTER UNUSED(next_tx_us)) { }
  85. static inline void add_timestamp_trace_entry(COUNTER UNUSED(size), struct timeval *UNUSED(timestamp),
  86. COUNTER UNUSED(skip_length)) { }
  87. static inline void dump_timestamp_trace_array(const struct timeval *UNUSED(start),
  88. const struct timeval *UNUSED(stop), const COUNTER UNUSED(bps)) { }
  89. #endif /* TIMESTAMP_TRACE */
  90. #endif /* TIMESTAMP_TRACE_H_ */