acceptor_status.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "acceptor_status.h"
  2. #include "key_value_printer.h"
  3. #include <util/stream/format.h>
  4. #include <util/stream/output.h>
  5. using namespace NBus;
  6. using namespace NBus::NPrivate;
  7. TAcceptorStatus::TAcceptorStatus()
  8. : Summary(false)
  9. , AcceptorId(0)
  10. , Fd(INVALID_SOCKET)
  11. {
  12. ResetIncremental();
  13. }
  14. void TAcceptorStatus::ResetIncremental() {
  15. AcceptSuccessCount = 0;
  16. AcceptErrorCount = 0;
  17. LastAcceptErrorErrno = 0;
  18. LastAcceptErrorInstant = TInstant();
  19. LastAcceptSuccessInstant = TInstant();
  20. }
  21. TAcceptorStatus& TAcceptorStatus::operator+=(const TAcceptorStatus& that) {
  22. Y_ASSERT(Summary);
  23. Y_ASSERT(AcceptorId == 0);
  24. AcceptSuccessCount += that.AcceptSuccessCount;
  25. LastAcceptSuccessInstant = Max(LastAcceptSuccessInstant, that.LastAcceptSuccessInstant);
  26. AcceptErrorCount += that.AcceptErrorCount;
  27. if (that.LastAcceptErrorInstant > LastAcceptErrorInstant) {
  28. LastAcceptErrorInstant = that.LastAcceptErrorInstant;
  29. LastAcceptErrorErrno = that.LastAcceptErrorErrno;
  30. }
  31. return *this;
  32. }
  33. TString TAcceptorStatus::PrintToString() const {
  34. TStringStream ss;
  35. if (!Summary) {
  36. ss << "acceptor (" << AcceptorId << "), fd=" << Fd << ", addr=" << ListenAddr << Endl;
  37. }
  38. TKeyValuePrinter p;
  39. p.AddRow("accept error count", LeftPad(AcceptErrorCount, 4));
  40. if (AcceptErrorCount > 0) {
  41. p.AddRow("last accept error",
  42. TString() + LastSystemErrorText(LastAcceptErrorErrno) + " at " + LastAcceptErrorInstant.ToString());
  43. }
  44. p.AddRow("accept success count", LeftPad(AcceptSuccessCount, 4));
  45. if (AcceptSuccessCount > 0) {
  46. p.AddRow("last accept success",
  47. TString() + "at " + LastAcceptSuccessInstant.ToString());
  48. }
  49. ss << p.PrintToString();
  50. return ss.Str();
  51. }