/xbmc/utils/Stopwatch.cpp

http://github.com/xbmc/xbmc · C++ · 47 lines · 35 code · 5 blank · 7 comment · 3 complexity · 9555c24d2b7dfc894ec57fd98107e0b7 MD5 · raw file

  1. /*
  2. * Copyright (C) 2005-2018 Team Kodi
  3. * This file is part of Kodi - https://kodi.tv
  4. *
  5. * SPDX-License-Identifier: GPL-2.0-or-later
  6. * See LICENSES/README.md for more information.
  7. */
  8. #include "Stopwatch.h"
  9. #if defined(TARGET_POSIX)
  10. #include "threads/SystemClock.h"
  11. #if !defined(TARGET_DARWIN) && !defined(TARGET_FREEBSD)
  12. #include <sys/sysinfo.h>
  13. #endif
  14. #endif
  15. #include "utils/TimeUtils.h"
  16. CStopWatch::CStopWatch(bool useFrameTime /*=false*/)
  17. {
  18. m_timerPeriod = 0.0f;
  19. m_startTick = 0;
  20. m_stopTick = 0;
  21. m_isRunning = false;
  22. m_useFrameTime = useFrameTime;
  23. #ifdef TARGET_POSIX
  24. m_timerPeriod = 1.0f / 1000.0f; // we want seconds
  25. #else
  26. if (m_useFrameTime)
  27. m_timerPeriod = 1.0f / 1000.0f; //frametime is in milliseconds
  28. else
  29. m_timerPeriod = 1.0f / (float)CurrentHostFrequency();
  30. #endif
  31. }
  32. CStopWatch::~CStopWatch() = default;
  33. int64_t CStopWatch::GetTicks() const
  34. {
  35. if (m_useFrameTime)
  36. return CTimeUtils::GetFrameTime();
  37. #ifndef TARGET_POSIX
  38. return CurrentHostCounter();
  39. #else
  40. return XbmcThreads::SystemClockMillis();
  41. #endif
  42. }