| 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 |
#ifndef CMRTLIB_AGNOSTIC_HARDWARE_CM_PERF_STATISTICS_H_ |
| 23 |
#define CMRTLIB_AGNOSTIC_HARDWARE_CM_PERF_STATISTICS_H_ |
| 24 |
|
| 25 |
#include <vector> |
| 26 |
#include <cstdio> |
| 27 |
#include "cm_def_hw.h" |
| 28 |
#include "cm_include.h" |
| 29 |
|
| 30 |
#if MDF_PROFILER_ENABLED |
| 31 |
|
| 32 |
#define MAX_RECORD_NUM 256 |
| 33 |
#define MSG_STRING_SIZE 256 |
| 34 |
#define INIT_ARRAY_ZIE 256 |
| 35 |
|
| 36 |
struct ApiPerfStatistic |
| 37 |
{ |
| 38 |
char functionName[MSG_STRING_SIZE]; // function name |
| 39 |
float time; // accumulative api duration |
| 40 |
uint32_t callTimes; // called times |
| 41 |
}; |
| 42 |
|
| 43 |
struct ApiCallRecord |
| 44 |
{ |
| 45 |
char functionName[MSG_STRING_SIZE]; // function name |
| 46 |
LARGE_INTEGER startTime; // start time |
| 47 |
LARGE_INTEGER endTime; // end time |
| 48 |
float duration; // duration |
| 49 |
}; |
| 50 |
|
| 51 |
enum PerfLogLevel |
| 52 |
{ |
| 53 |
CM_RT_PERF_LOG_LEVEL_DEFAULT = 0 , // default level: only dump the statistics results when destorying cm device |
| 54 |
CM_RT_PERF_LOG_LEVEL_ETW = 1 , // ETW level: generate etw logs in each call and dump statistics results |
| 55 |
CM_RT_PERF_LOG_LEVEL_RECORDS = 2 , // records each call in m_log_file ; generate etw logs ; dump statistics results |
| 56 |
}; |
| 57 |
|
| 58 |
class CmPerfStatistics |
| 59 |
{ |
| 60 |
public: |
| 61 |
CmPerfStatistics(); |
| 62 |
~CmPerfStatistics(); |
| 63 |
|
| 64 |
//! |
| 65 |
//! \brief Insert API call record |
| 66 |
//! \details Insert API call record which contains function name, start time, end and duration. |
| 67 |
//! \param [in] functionName |
| 68 |
//! pointer to function name's string |
| 69 |
//! \param [in] time |
| 70 |
//! function's duration |
| 71 |
//! \param [in] start |
| 72 |
//! function's start time |
| 73 |
//! \param [in] end |
| 74 |
//! function's end time |
| 75 |
//! |
| 76 |
void InsertApiCallRecord(char *functionName, float time, LARGE_INTEGER start, LARGE_INTEGER end); |
| 77 |
|
| 78 |
//! |
| 79 |
//! \brief Insert API call record into performace statistic record |
| 80 |
//! \details Insert API call record into performace statistic record. |
| 81 |
//! \param [in] pRecords |
| 82 |
//! pointer to API call record |
| 83 |
//! |
| 84 |
void InsertPerfStatistic(ApiCallRecord *records); |
| 85 |
|
| 86 |
private: |
| 87 |
|
| 88 |
//! |
| 89 |
//! \brief Check the profiler level |
| 90 |
//! \details So far, this function turns the profiler on. |
| 91 |
//! |
| 92 |
void GetProfilerLevel(); |
| 93 |
|
| 94 |
//! |
| 95 |
//! \brief Dump API call records into file |
| 96 |
//! \details Dump API call records into file, |
| 97 |
//! "CmPerfLog.csv" under app's location. |
| 98 |
//! |
| 99 |
void DumpApiCallRecords(); |
| 100 |
|
| 101 |
//! |
| 102 |
//! \brief Dump API call statistic records into file |
| 103 |
//! \details Dump API call statistic records into file, |
| 104 |
//! "CmPerfStatistics" under app's location. |
| 105 |
//! |
| 106 |
void DumpPerfStatisticRecords(); |
| 107 |
|
| 108 |
CSync m_criticalSectionOnApiCallRecords; |
| 109 |
uint32_t m_apiCallRecordCount; |
| 110 |
FILE *m_apiCallFile; |
| 111 |
|
| 112 |
CSync m_criticalSectionOnPerfStatisticRecords; |
| 113 |
FILE *m_perfStatisticFile; |
| 114 |
uint32_t m_perfStatisticCount; |
| 115 |
|
| 116 |
std::vector<ApiCallRecord*> m_apiCallRecords; // array to store api call records |
| 117 |
std::vector<ApiPerfStatistic*> m_perfStatisticRecords; // array to store perf statistic information |
| 118 |
|
| 119 |
PerfLogLevel m_profilerLevel; // profiler level |
| 120 |
bool m_profilerOn; // profiler on or off |
| 121 |
|
| 122 |
private: |
| 123 |
CmPerfStatistics(const CmPerfStatistics &other); |
| 124 |
CmPerfStatistics &operator=(const CmPerfStatistics &other); |
| 125 |
|
| 126 |
}; |
| 127 |
|
| 128 |
#endif |
| 129 |
|
| 130 |
#endif // #ifndef CMRTLIB_AGNOSTIC_HARDWARE_CM_PERF_STATISTICS_H_ |