PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 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
18CStopWatch::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
36CStopWatch::~CStopWatch() = default;
37
38int64_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}