operation_tracker.cpp 946 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "operation_tracker.h"
  2. #include <yt/cpp/mapreduce/interface/config.h>
  3. namespace NYT {
  4. ////////////////////////////////////////////////////////////////////////////////
  5. void TOperationExecutionTimeTracker::Start(const TOperationId& operationId) {
  6. with_lock(Lock_) {
  7. StartTimes_[operationId] = TInstant::Now();
  8. }
  9. }
  10. TMaybe<TDuration> TOperationExecutionTimeTracker::Finish(const TOperationId& operationId) {
  11. TDuration duration;
  12. with_lock(Lock_) {
  13. auto i = StartTimes_.find(operationId);
  14. if (i == StartTimes_.end()) {
  15. return Nothing();
  16. }
  17. duration = TInstant::Now() - i->second;
  18. StartTimes_.erase(i);
  19. }
  20. return duration;
  21. }
  22. TOperationExecutionTimeTracker* TOperationExecutionTimeTracker::Get() {
  23. return Singleton<TOperationExecutionTimeTracker>();
  24. }
  25. ////////////////////////////////////////////////////////////////////////////////
  26. } // namespace NYT