Mark3 Realtime Kernel
profile.cpp
Go to the documentation of this file.
1 /*===========================================================================
2  _____ _____ _____ _____
3  ___| _|__ __|_ |__ __|__ |__ __| __ |__ ______
4 | \ / | || \ || | || |/ / ||___ |
5 | \/ | || \ || \ || \ ||___ |
6 |__/\__/|__|_||__|\__\ __||__|\__\ __||__|\__\ __||______|
7  |_____| |_____| |_____| |_____|
8 
9 --[Mark3 Realtime Platform]--------------------------------------------------
10 
11 Copyright (c) 2012 - 2019 m0slevin, all rights reserved.
12 See license.txt for more information
13 ===========================================================================*/
21 #include "mark3.h"
22 namespace Mark3
23 {
24 //---------------------------------------------------------------------------
26 {
27  m_u32StartTicks = 0;
28  m_u32Cumulative = 0;
29  m_u16Iterations = 0;
30  m_bActive = false;
31 }
32 
33 //---------------------------------------------------------------------------
35 {
36  if (!m_bActive) {
37  { // Begin critical section
38  const auto cs = CriticalGuard{};
40  } // End Critical Section
41  m_bActive = true;
42  }
43 }
44 
45 //---------------------------------------------------------------------------
47 {
48  if (m_bActive) {
49  uint32_t u32Final;
50  { // Begin critical section
51  const auto cs = CriticalGuard{};
52  u32Final = Kernel::GetTicks();
53  // Compute total for current iteration...
57  } // End critical section
58  m_bActive = false;
59  }
60 }
61 
62 //---------------------------------------------------------------------------
64 {
65  if (0u != m_u16Iterations) {
66  return (m_u32Cumulative + static_cast<uint32_t>(m_u16Iterations / 2)) / static_cast<uint32_t>(m_u16Iterations);
67  }
68  return 0;
69 }
70 
71 //---------------------------------------------------------------------------
73 {
74  if (m_bActive) {
75  uint32_t u32Current;
76  { // Begin critical section
77  const auto cs = CriticalGuard{};
78  u32Current = Kernel::GetTicks() - m_u32StartTicks;
79  } // End critical section
80  return u32Current;
81  }
82  return m_u32CurrentIteration;
83 }
84 } // namespace Mark3
uint32_t GetCurrent()
GetCurrent Return the current tick count held by the profiler. Valid for both active and stopped time...
Definition: profile.cpp:72
Definition: atomic.cpp:23
bool m_bActive
Wheter or not the timer is active or stopped.
Definition: profile.h:113
uint32_t m_u32Cumulative
Cumulative ticks tracked.
Definition: profile.h:111
Single include file given to users of the Mark3 Kernel API.
static uint32_t GetTicks()
Definition: kernel.cpp:90
uint32_t GetAverage()
GetAverage Get the average time associated with this operation.
Definition: profile.cpp:63
uint32_t m_u32CurrentIteration
Tick count for current iteration.
Definition: profile.h:110
uint16_t m_u16Iterations
Number of iterations executed for this profiling timer.
Definition: profile.h:112
The CriticalGuard class. This class provides an implemention of RAII for critical sections...
Definition: criticalguard.h:38
void Start()
Start Start a profiling session, if the timer is not already active. Has no effect if the timer is al...
Definition: profile.cpp:34
void Stop()
Stop Stop the current profiling session, adding to the cumulative time for this timer, and the total iteration count.
Definition: profile.cpp:46
uint32_t m_u32StartTicks
Cumulative tick-count for this timer.
Definition: profile.h:109
void Init()
Init Initialize the profiling timer prior to use. Can also be used to reset a timer that&#39;s been used ...
Definition: profile.cpp:25