log_shuttle.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "log_shuttle.h"
  2. #include "probes.h"
  3. namespace NLWTrace {
  4. LWTRACE_USING(LWTRACE_INTERNAL_PROVIDER);
  5. #ifdef LWTRACE_DISABLE
  6. template <class TDepot>
  7. bool TLogShuttle<TDepot>::DoFork(TShuttlePtr& child) {
  8. Y_UNUSED(child);
  9. return false;
  10. }
  11. template <class TDepot>
  12. bool TLogShuttle<TDepot>::DoJoin(const TShuttlePtr& child) {
  13. Y_UNUSED(child);
  14. return false;
  15. }
  16. #else
  17. template <class TDepot>
  18. bool TLogShuttle<TDepot>::DoFork(TShuttlePtr& child) {
  19. if (child = Executor->RentShuttle()) {
  20. child->SetParentSpanId(GetSpanId());
  21. Executor->Cast(child)->SetIgnore(true);
  22. TParams params;
  23. params.Param[0].CopyConstruct<ui64>(child->GetSpanId());
  24. bool result = DoAddProbe(&LWTRACE_GET_NAME(Fork).Probe, params, 0);
  25. TUserSignature<ui64>::DestroyParams(params);
  26. return result;
  27. }
  28. AtomicIncrement(ForkFailed);
  29. return false;
  30. }
  31. template <class TDepot>
  32. bool TLogShuttle<TDepot>::DoJoin(const TShuttlePtr& shuttle) {
  33. auto* child = Executor->Cast(shuttle);
  34. TParams params;
  35. params.Param[0].CopyConstruct<ui64>(child->GetSpanId());
  36. params.Param[1].CopyConstruct<ui64>(child->TrackLog.Items.size());
  37. bool result = DoAddProbe(&LWTRACE_GET_NAME(Join).Probe, params, 0);
  38. TUserSignature<ui64, ui64>::DestroyParams(params);
  39. if (result) {
  40. with_lock (Lock) {
  41. ssize_t n = MaxTrackLength - TrackLog.Items.size();
  42. for (auto& item: child->TrackLog.Items) {
  43. if (n-- <= 0) {
  44. TrackLog.Truncated = true;
  45. break;
  46. }
  47. TrackLog.Items.emplace_back(item);
  48. }
  49. }
  50. }
  51. AtomicAdd(ForkFailed, AtomicGet(child->ForkFailed));
  52. Executor->ParkShuttle(child);
  53. return result;
  54. }
  55. #endif
  56. template class TLogShuttle<TDurationDepot>;
  57. template class TLogShuttle<TCyclicDepot>;
  58. }