xref: /aosp_15_r20/external/intel-media-driver/cmrtlib/agnostic/hardware/cm_timer.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2017, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 #include "cm_timer.h"
23 #include "cm_perf_statistics.h"
24 
25 #define MSG_STRING_SIZE 256
26 
27 #if MDF_PROFILER_ENABLED
28 extern CmPerfStatistics gCmPerfStatistics;
29 
CmTimer(const char * functionName)30 CmTimer::CmTimer(const char *functionName):
31     m_cycles(0),
32     m_funcName(const_cast<char*>(functionName))
33 {
34     //Get frequency
35     QueryPerformanceFrequency(&m_freq);
36 
37     // initialize private variables
38     m_start.QuadPart = 0;
39     m_end.QuadPart   = 0;
40 
41     //Start timer
42     Start();
43 
44     return;
45 }
46 
~CmTimer()47 CmTimer::~CmTimer()
48 {
49     Stop();
50     gCmPerfStatistics.InsertApiCallRecord(m_funcName, GetTimeinMs(), m_start,
51                                           m_end);
52 }
53 
Start()54 void CmTimer::Start()
55 {
56     QueryPerformanceCounter(&m_start);  // recode API start time
57     InsertEventStartFlag();
58     return;
59 }
60 
Stop()61 void CmTimer::Stop()
62 {
63     QueryPerformanceCounter(&m_end);
64     m_cycles = m_end.QuadPart - m_start.QuadPart;
65     InsertEventEndFlag();
66     return;
67 }
68 
GetTimeinMs()69 float CmTimer::GetTimeinMs()
70 {
71     return (float)m_cycles * (float)1000.0 / (float)m_freq.QuadPart;
72 }
73 
74 #endif  // #if MDF_PROFILER_ENABLED
75