2 * Copyright 2013, Paweł Dziepak, pdziepak@quarnos.org.
3 * Distributed under the terms of the MIT License.
5 #ifndef KERNEL_SCHEDULER_PROFILER_H
6 #define KERNEL_SCHEDULER_PROFILER_H
12 //#define SCHEDULER_PROFILING
13 #ifdef SCHEDULER_PROFILING
16 #define SCHEDULER_ENTER_FUNCTION() \
17 Scheduler::Profiling::Function schedulerProfiler(__PRETTY_FUNCTION__)
19 #define SCHEDULER_EXIT_FUNCTION() \
20 schedulerProfiler.Exit()
31 void EnterFunction(int32 cpu
, const char* function
);
32 void ExitFunction(int32 cpu
, const char* function
);
34 void DumpCalled(uint32 count
);
35 void DumpTimeInclusive(uint32 count
);
36 void DumpTimeExclusive(uint32 count
);
37 void DumpTimeInclusivePerCall(uint32 count
);
38 void DumpTimeExclusivePerCall(uint32 count
);
40 status_t
GetStatus() const { return fStatus
; }
42 static Profiler
* Get();
43 static void Initialize();
47 const char* fFunction
;
51 bigtime_t fTimeInclusive
;
52 bigtime_t fTimeExclusive
;
55 struct FunctionEntry
{
56 FunctionData
* fFunction
;
58 nanotime_t fEntryTime
;
59 nanotime_t fOthersTime
;
60 nanotime_t fProfilerTime
;
63 uint32
_FunctionCount() const;
64 void _Dump(uint32 count
);
66 FunctionData
* _FindFunction(const char* function
);
68 template<typename Type
, Type
FunctionData::*Member
>
69 static int _CompareFunctions(const void* a
, const void* b
);
71 template<typename Type
, Type
FunctionData::*Member
>
72 static int _CompareFunctionsPerCall(const void* a
,
75 const uint32 kMaxFunctionEntries
;
76 const uint32 kMaxFunctionStackEntries
;
78 FunctionEntry
* fFunctionStacks
[SMP_MAX_CPUS
];
79 uint32 fFunctionStackPointers
[SMP_MAX_CPUS
];
81 FunctionData
* fFunctionData
;
82 spinlock fFunctionLock
;
89 inline Function(const char* functionName
);
95 const char* fFunctionName
;
99 Function::Function(const char* functionName
)
101 fFunctionName(functionName
)
103 Profiler::Get()->EnterFunction(smp_get_current_cpu(), fFunctionName
);
107 Function::~Function()
109 if (fFunctionName
!= NULL
)
117 Profiler::Get()->ExitFunction(smp_get_current_cpu(), fFunctionName
);
118 fFunctionName
= NULL
;
122 } // namespace Profiling
124 } // namespace Scheduler
127 #else // SCHEDULER_PROFILING
129 #define SCHEDULER_ENTER_FUNCTION() (void)0
130 #define SCHEDULER_EXIT_FUNCTION() (void)0
132 #endif // !SCHEDULER_PROFILING
135 #endif // KERNEL_SCHEDULER_PROFILER_H