14 #ifndef HYPERPLATFORM_PERF_COUNTER_H_ 15 #define HYPERPLATFORM_PERF_COUNTER_H_ 17 #include <fltKernel.h> 24 #define HYPERPLATFORM_PERFCOUNTER_P_JOIN2(x, y) x##y 25 #define HYPERPLATFORM_PERFCOUNTER_P_JOIN1(x, y) \ 26 HYPERPLATFORM_PERFCOUNTER_P_JOIN2(x, y) 31 #define HYPERPLATFORM_PERFCOUNTER_P_JOIN(x, y) \ 32 HYPERPLATFORM_PERFCOUNTER_P_JOIN1(x, y) 34 #define HYPERPLATFORM_PERFCOUNTER_P_TO_STRING1(n) #n 38 #define HYPERPLATFORM_PERFCOUNTER_P_TO_STRING(n) \ 39 HYPERPLATFORM_PERFCOUNTER_P_TO_STRING1(n) 82 #define HYPERPLATFORM_PERFCOUNTER_MEASURE_TIME(collector, query_time_routine) \ 83 const PerfCounter HYPERPLATFORM_PERFCOUNTER_P_JOIN(perf_obj_, __COUNTER__)( \ 84 (collector), (query_time_routine), \ 85 __FUNCTION__ "(" HYPERPLATFORM_PERFCOUNTER_P_TO_STRING(__LINE__) ")") 123 _In_ ULONG64 total_execution_count,
124 _In_ ULONG64 total_elapsed_time,
125 _In_opt_
void* output_context);
148 _In_opt_
void* lock_context =
nullptr,
149 _In_opt_
void* output_context =
nullptr) {
167 if (
data_[i].key ==
nullptr) {
180 bool AddData(_In_
const char* location_name, _In_ ULONG64 elapsed_time) {
213 _In_opt_
void* lock_context)
232 UNREFERENCED_PARAMETER(output_context);
238 UNREFERENCED_PARAMETER(lock_context);
254 if (
data_[i].key == key) {
258 if (
data_[i].key ==
nullptr) {
290 _In_
const char* location_name)
307 static ULONG64
RdTsc() {
return __rdtsc(); }
315 #endif // HYPERPLATFORM_PERF_COUNTER_H_
bool AddData(_In_ const char *location_name, _In_ ULONG64 elapsed_time)
Saves performance data taken by PerfCounter.
ScopedLock(_In_ LockRoutine *lock_routine, _In_ LockRoutine *leave_routine, _In_opt_ void *lock_context)
Acquires a lock using lock_routine.
void Terminate()
Destructor; prints out accumulated performance results.
ULONG GetPerfDataIndex(_In_ const char *key)
Returns an index of data corresponds to the location_name.
Represents performance data for each location.
OutputRoutine * output_routine_
~ScopedLock()
Releases a lock using ScopedLock::leave_routine_.
const ULONG64 before_time_
QueryTimeRoutine * query_time_routine_
static ULONG64 RdTsc()
Gets the current time using the RDTSC instruction.
void Initialize(_In_ OutputRoutine *output_routine, _In_opt_ InitialOutputRoutine *initial_output_routine=NoOutputRoutine, _In_opt_ FinalOutputRoutine *final_output_routine=NoOutputRoutine, _In_opt_ LockRoutine *lock_enter_routine=NoLockRoutine, _In_opt_ LockRoutine *lock_leave_routine=NoLockRoutine, _In_opt_ void *lock_context=nullptr, _In_opt_ void *output_context=nullptr)
Constructor; call this only once before any other code in this module runs.
ULONG64 total_elapsed_time
An accumulated elapsed time.
Measure elapsed time of the scope.
ULONG64() QueryTimeRoutine
static const ULONG kInvalidDataIndex
PerfCounter(_In_ PerfCollector *collector, _In_opt_ QueryTimeRoutine *query_time_routine, _In_ const char *location_name)
Gets the current time using query_time_routine.
void(_In_ const char *location_name, _In_ ULONG64 total_execution_count, _In_ ULONG64 total_elapsed_time, _In_opt_ void *output_context) OutputRoutine
A function type for printing out results.
FinalOutputRoutine * final_output_routine_
void(_In_opt_ void *output_context) FinalOutputRoutine
A function type for printing out a footer line of results.
const char * location_name_
InitialOutputRoutine * initial_output_routine_
LockRoutine * leave_routine_
ULONG64 total_execution_count
How many times executed.
static const ULONG kMaxNumberOfDataEntries
LockRoutine * lock_leave_routine_
PerfDataEntry data_[kMaxNumberOfDataEntries]
LockRoutine * lock_routine_
static void NoOutputRoutine(_In_opt_ void *output_context)
Default empty output routine.
const char * key
Identifies a subject matter location.
void(_In_opt_ void *output_context) InitialOutputRoutine
A function type for printing out a header line of results.
Responsible for collecting and saving data supplied by PerfCounter.
static void NoLockRoutine(_In_opt_ void *lock_context)
Default empty lock and release routine.
~PerfCounter()
Measures an elapsed time and stores it to PerfCounter::collector_.
void(_In_opt_ void *lock_context) LockRoutine
A function type for acquiring and releasing a lock.
LockRoutine * lock_enter_routine_
PerfCollector * collector_