vfs: check userland buffers before reading them.
[haiku.git] / src / system / kernel / scheduler / scheduler_profiler.h
blobd2c1bfca3dfb3189e1b015024977c1fff3fbed59
1 /*
2 * Copyright 2013, Paweł Dziepak, pdziepak@quarnos.org.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef KERNEL_SCHEDULER_PROFILER_H
6 #define KERNEL_SCHEDULER_PROFILER_H
9 #include <smp.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()
23 namespace Scheduler {
25 namespace Profiling {
27 class Profiler {
28 public:
29 Profiler();
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();
45 private:
46 struct FunctionData {
47 const char* fFunction;
49 uint32 fCalled;
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,
73 const void* b);
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;
84 status_t fStatus;
87 class Function {
88 public:
89 inline Function(const char* functionName);
90 inline ~Function();
92 inline void Exit();
94 private:
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)
110 Exit();
114 void
115 Function::Exit()
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