remote_connection_status.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #pragma once
  2. #include "codegen.h"
  3. #include "duration_histogram.h"
  4. #include "message_counter.h"
  5. #include "message_status_counter.h"
  6. #include "queue_config.h"
  7. #include "session_config.h"
  8. #include <library/cpp/messagebus/actor/executor.h>
  9. #include <library/cpp/deprecated/enum_codegen/enum_codegen.h>
  10. namespace NBus {
  11. class TConnectionStatusMonRecord;
  12. }
  13. namespace NBus {
  14. namespace NPrivate {
  15. #define WRITER_STATE_MAP(XX) \
  16. XX(WRITER_UNKNOWN) \
  17. XX(WRITER_FILLING) \
  18. XX(WRITER_FLUSHING) \
  19. /**/
  20. // TODO: move elsewhere
  21. enum EWriterState {
  22. WRITER_STATE_MAP(ENUM_VALUE_GEN_NO_VALUE)
  23. };
  24. ENUM_TO_STRING(EWriterState, WRITER_STATE_MAP)
  25. #define STRUCT_FIELD_ADD(name, type, func) func(name, that.name);
  26. template <typename T>
  27. void Reset(T& t) {
  28. t.~T();
  29. new (&t) T();
  30. }
  31. #define DURATION_COUNTER_MAP(XX, comma) \
  32. XX(Count, unsigned, Add) \
  33. comma \
  34. XX(SumDuration, TDuration, Add) comma \
  35. XX(MaxDuration, TDuration, Max) /**/
  36. struct TDurationCounter {
  37. DURATION_COUNTER_MAP(STRUCT_FIELD_GEN, )
  38. TDuration AvgDuration() const;
  39. TDurationCounter();
  40. void AddDuration(TDuration d) {
  41. Count += 1;
  42. SumDuration += d;
  43. if (d > MaxDuration) {
  44. MaxDuration = d;
  45. }
  46. }
  47. TDurationCounter& operator+=(const TDurationCounter&);
  48. TString ToString() const;
  49. };
  50. #define REMOTE_CONNECTION_STATUS_BASE_MAP(XX, comma) \
  51. XX(ConnectionId, ui64, AssertZero) \
  52. comma \
  53. XX(Fd, SOCKET, AssertZero) comma \
  54. XX(Acts, ui64, Add) comma \
  55. XX(BufferSize, ui64, Add) /**/
  56. struct TRemoteConnectionStatusBase {
  57. REMOTE_CONNECTION_STATUS_BASE_MAP(STRUCT_FIELD_GEN, )
  58. TRemoteConnectionStatusBase& operator+=(const TRemoteConnectionStatusBase&);
  59. TRemoteConnectionStatusBase();
  60. };
  61. #define REMOTE_CONNECTION_INCREMENTAL_STATUS_BASE_MAP(XX, comma) \
  62. XX(BufferDrops, unsigned, Add) \
  63. comma \
  64. XX(NetworkOps, unsigned, Add) /**/
  65. struct TRemoteConnectionIncrementalStatusBase {
  66. REMOTE_CONNECTION_INCREMENTAL_STATUS_BASE_MAP(STRUCT_FIELD_GEN, )
  67. TRemoteConnectionIncrementalStatusBase& operator+=(const TRemoteConnectionIncrementalStatusBase&);
  68. TRemoteConnectionIncrementalStatusBase();
  69. };
  70. #define REMOTE_CONNECTION_READER_INCREMENTAL_STATUS_MAP(XX, comma) \
  71. XX(MessageCounter, TMessageCounter, Add) \
  72. comma \
  73. XX(StatusCounter, TMessageStatusCounter, Add) /**/
  74. struct TRemoteConnectionReaderIncrementalStatus: public TRemoteConnectionIncrementalStatusBase {
  75. REMOTE_CONNECTION_READER_INCREMENTAL_STATUS_MAP(STRUCT_FIELD_GEN, )
  76. TRemoteConnectionReaderIncrementalStatus& operator+=(const TRemoteConnectionReaderIncrementalStatus&);
  77. TRemoteConnectionReaderIncrementalStatus();
  78. };
  79. #define REMOTE_CONNECTION_READER_STATUS_MAP(XX, comma) \
  80. XX(QuotaMsg, size_t, Add) \
  81. comma \
  82. XX(QuotaBytes, size_t, Add) comma \
  83. XX(QuotaExhausted, size_t, Add) comma \
  84. XX(Incremental, TRemoteConnectionReaderIncrementalStatus, Add) /**/
  85. struct TRemoteConnectionReaderStatus: public TRemoteConnectionStatusBase {
  86. REMOTE_CONNECTION_READER_STATUS_MAP(STRUCT_FIELD_GEN, )
  87. TRemoteConnectionReaderStatus& operator+=(const TRemoteConnectionReaderStatus&);
  88. TRemoteConnectionReaderStatus();
  89. };
  90. #define REMOTE_CONNECTION_WRITER_INCREMENTAL_STATUS(XX, comma) \
  91. XX(MessageCounter, TMessageCounter, Add) \
  92. comma \
  93. XX(StatusCounter, TMessageStatusCounter, Add) comma \
  94. XX(ProcessDurationHistogram, TDurationHistogram, Add) /**/
  95. struct TRemoteConnectionWriterIncrementalStatus: public TRemoteConnectionIncrementalStatusBase {
  96. REMOTE_CONNECTION_WRITER_INCREMENTAL_STATUS(STRUCT_FIELD_GEN, )
  97. TRemoteConnectionWriterIncrementalStatus& operator+=(const TRemoteConnectionWriterIncrementalStatus&);
  98. TRemoteConnectionWriterIncrementalStatus();
  99. };
  100. #define REMOTE_CONNECTION_WRITER_STATUS(XX, comma) \
  101. XX(Connected, bool, AssertZero) \
  102. comma \
  103. XX(ConnectTime, TInstant, AssertZero) comma /* either connect time on client or accept time on server */ \
  104. XX(ConnectError, int, AssertZero) comma \
  105. XX(ConnectSyscalls, unsigned, Add) comma \
  106. XX(PeerAddr, TNetAddr, AssertZero) comma \
  107. XX(MyAddr, TNetAddr, AssertZero) comma \
  108. XX(State, EWriterState, AssertZero) comma \
  109. XX(SendQueueSize, size_t, Add) comma \
  110. XX(AckMessagesSize, size_t, Add) comma /* client only */ \
  111. XX(DurationCounter, TDurationCounter, Add) comma /* server only */ \
  112. XX(DurationCounterPrev, TDurationCounter, Add) comma /* server only */ \
  113. XX(Incremental, TRemoteConnectionWriterIncrementalStatus, Add) comma \
  114. XX(ReaderWakeups, size_t, Add) /**/
  115. struct TRemoteConnectionWriterStatus: public TRemoteConnectionStatusBase {
  116. REMOTE_CONNECTION_WRITER_STATUS(STRUCT_FIELD_GEN, )
  117. TRemoteConnectionWriterStatus();
  118. TRemoteConnectionWriterStatus& operator+=(const TRemoteConnectionWriterStatus&);
  119. size_t GetInFlight() const;
  120. };
  121. #define REMOTE_CONNECTION_STATUS_MAP(XX, comma) \
  122. XX(Summary, bool) \
  123. comma \
  124. XX(Server, bool) /**/
  125. struct TRemoteConnectionStatus {
  126. REMOTE_CONNECTION_STATUS_MAP(STRUCT_FIELD_GEN, )
  127. TRemoteConnectionReaderStatus ReaderStatus;
  128. TRemoteConnectionWriterStatus WriterStatus;
  129. TRemoteConnectionStatus();
  130. TString PrintToString() const;
  131. TConnectionStatusMonRecord GetStatusProtobuf() const;
  132. };
  133. struct TBusSessionStatus {
  134. size_t InFlightCount;
  135. size_t InFlightSize;
  136. bool InputPaused;
  137. TBusSessionStatus();
  138. };
  139. struct TSessionDumpStatus {
  140. bool Shutdown;
  141. TString Head;
  142. TString Acceptors;
  143. TString ConnectionsSummary;
  144. TString Connections;
  145. TBusSessionStatus Status;
  146. TRemoteConnectionStatus ConnectionStatusSummary;
  147. TBusSessionConfig Config;
  148. TSessionDumpStatus()
  149. : Shutdown(false)
  150. {
  151. }
  152. TString PrintToString() const;
  153. };
  154. // without sessions
  155. struct TBusMessageQueueStatus {
  156. NActor::NPrivate::TExecutorStatus ExecutorStatus;
  157. TBusQueueConfig Config;
  158. TString PrintToString() const;
  159. };
  160. }
  161. }