control.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "probes.h"
  2. #include <library/cpp/lwtrace/protos/lwtrace.pb.h>
  3. #include <util/generic/string.h>
  4. namespace NLWTrace {
  5. LWTRACE_USING(LWTRACE_INTERNAL_PROVIDER);
  6. TProbeMap TManager::GetProbesMap() {
  7. class TProbeReader
  8. {
  9. private:
  10. TProbeMap& Result;
  11. public:
  12. TProbeReader(TProbeMap& result)
  13. : Result(result)
  14. {}
  15. void Push(NLWTrace::TProbe* probe)
  16. {
  17. Result[std::make_pair(probe->Event.Name, probe->Event.GetProvider())] = probe;
  18. }
  19. };
  20. TProbeMap result;
  21. auto reader = TProbeReader(result);
  22. ReadProbes(reader);
  23. return result;
  24. }
  25. void TManager::CreateTraceRequest(TTraceRequest& msg, TOrbit& orbit)
  26. {
  27. msg.SetIsTraced(orbit.HasShuttles());
  28. }
  29. bool TManager::HandleTraceRequest(
  30. const TTraceRequest& msg,
  31. TOrbit& orbit)
  32. {
  33. if (!msg.GetIsTraced()) {
  34. return false;
  35. }
  36. TParams params;
  37. SerializingExecutor->Execute(orbit, params);
  38. return true;
  39. }
  40. TTraceDeserializeStatus TManager::HandleTraceResponse(
  41. const TTraceResponse& msg,
  42. const TProbeMap& probesMap,
  43. TOrbit& orbit,
  44. i64 timeOffset,
  45. double timeScale)
  46. {
  47. TTraceDeserializeStatus result;
  48. if (!msg.GetTrace().GetEvents().size()) {
  49. return result;
  50. }
  51. ui64 prev = EpochNanosecondsToCycles(
  52. msg.GetTrace().GetEvents()[0].GetTimestampNanosec());
  53. for (auto& v : msg.GetTrace().GetEvents()) {
  54. auto it = probesMap.find(std::make_pair(v.GetName(), v.GetProvider()));
  55. if (it != probesMap.end()) {
  56. TProbe* probe = it->second;
  57. TParams params;
  58. if(!probe->Event.Signature.DeserializeFromPb(params, v.GetParams())) {
  59. LWTRACK(DeserializationError, orbit, probe->Event.Name, probe->Event.GetProvider());
  60. result.AddFailedEventName(v.GetName());
  61. } else {
  62. // in case of fork join probes would be like "start 0 fork 1 ....... join 10 forked 5 forked 6"
  63. ui64 timestamp = EpochNanosecondsToCycles(v.GetTimestampNanosec());
  64. if (timestamp > prev) {
  65. timestamp = prev + (timestamp-prev)*timeScale + timeOffset;
  66. } else {
  67. timestamp += timeOffset;
  68. }
  69. orbit.AddProbe(
  70. probe,
  71. params,
  72. timestamp);
  73. probe->Event.Signature.DestroyParams(params);
  74. prev = timestamp;
  75. }
  76. } else {
  77. result.AddFailedEventName(v.GetName());
  78. }
  79. }
  80. return result;
  81. }
  82. void TManager::CreateTraceResponse(TTraceResponse& msg, TOrbit& orbit)
  83. {
  84. orbit.Serialize(0, *msg.MutableTrace());
  85. }
  86. }