diff options
Diffstat (limited to 'xbmc/utils/Stopwatch.cpp')
| -rw-r--r-- | xbmc/utils/Stopwatch.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/xbmc/utils/Stopwatch.cpp b/xbmc/utils/Stopwatch.cpp new file mode 100644 index 0000000..bec498f --- /dev/null +++ b/xbmc/utils/Stopwatch.cpp | |||
| @@ -0,0 +1,47 @@ | |||
| 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 | |||
| 9 | #include "Stopwatch.h" | ||
| 10 | #if defined(TARGET_POSIX) | ||
| 11 | #include "threads/SystemClock.h" | ||
| 12 | #if !defined(TARGET_DARWIN) && !defined(TARGET_FREEBSD) | ||
| 13 | #include <sys/sysinfo.h> | ||
| 14 | #endif | ||
| 15 | #endif | ||
| 16 | #include "utils/TimeUtils.h" | ||
| 17 | |||
| 18 | CStopWatch::CStopWatch(bool useFrameTime /*=false*/) | ||
| 19 | { | ||
| 20 | m_timerPeriod = 0.0f; | ||
| 21 | m_startTick = 0; | ||
| 22 | m_stopTick = 0; | ||
| 23 | m_isRunning = false; | ||
| 24 | m_useFrameTime = useFrameTime; | ||
| 25 | |||
| 26 | #ifdef TARGET_POSIX | ||
| 27 | m_timerPeriod = 1.0f / 1000.0f; // we want seconds | ||
| 28 | #else | ||
| 29 | if (m_useFrameTime) | ||
| 30 | m_timerPeriod = 1.0f / 1000.0f; //frametime is in milliseconds | ||
| 31 | else | ||
| 32 | m_timerPeriod = 1.0f / (float)CurrentHostFrequency(); | ||
| 33 | #endif | ||
| 34 | } | ||
| 35 | |||
| 36 | CStopWatch::~CStopWatch() = default; | ||
| 37 | |||
| 38 | int64_t CStopWatch::GetTicks() const | ||
| 39 | { | ||
| 40 | if (m_useFrameTime) | ||
| 41 | return CTimeUtils::GetFrameTime(); | ||
| 42 | #ifndef TARGET_POSIX | ||
| 43 | return CurrentHostCounter(); | ||
| 44 | #else | ||
| 45 | return XbmcThreads::SystemClockMillis(); | ||
| 46 | #endif | ||
| 47 | } | ||
