thorstats.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2016 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "platform.h"
  14. #include "jstats.h"
  15. #include "thorstats.hpp"
  16. #include "jdebug.hpp"
  17. //Cycles are accumulated locally, time is updated once it is serialized or persisted
  18. const StatisticsMapping nestedSectionStatistics(StCycleLocalExecuteCycles, StTimeLocalExecute, StNumStarted, StNumStopped, StKindNone);
  19. ThorSectionTimer::ThorSectionTimer(const char * _name, CRuntimeStatistic & _starts, CRuntimeStatistic & _stops, CRuntimeStatistic & _elapsed)
  20. : starts(_starts), stops(_stops), elapsed(_elapsed), name(_name)
  21. {
  22. }
  23. ThorSectionTimer * ThorSectionTimer::createTimer(CRuntimeStatisticCollection & stats, const char * name)
  24. {
  25. StatsScopeId scope(SSTfunction, name);
  26. CRuntimeStatisticCollection & nested = stats.registerNested(scope, nestedSectionStatistics);
  27. CRuntimeStatistic & starts = nested.queryStatistic(StNumStarted);
  28. CRuntimeStatistic & stops = nested.queryStatistic(StNumStopped);
  29. CRuntimeStatistic & elapsed = nested.queryStatistic(StCycleLocalExecuteCycles);
  30. return new ThorSectionTimer(name, starts, stops, elapsed);
  31. }
  32. unsigned __int64 ThorSectionTimer::getStartCycles()
  33. {
  34. starts.addAtomic(1);
  35. return get_cycles_now();
  36. }
  37. void ThorSectionTimer::noteSectionTime(unsigned __int64 startCycles)
  38. {
  39. cycle_t delay = get_cycles_now() - startCycles;
  40. elapsed.addAtomic(delay);
  41. stops.addAtomic(1);
  42. }