libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / system / kernel / scheduler / scheduler_tracing.h
blobf537a6b6f3179688e1d37d58bbdfda30a04b92ac
1 /*
2 * Copyright 2008-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de.
4 * Distributed under the terms of the MIT License.
5 */
6 #ifndef KERNEL_SCHEDULER_TRACING_H
7 #define KERNEL_SCHEDULER_TRACING_H
10 #include <arch/debug.h>
11 #include <cpu.h>
12 #include <thread.h>
13 #include <tracing.h>
16 #if SCHEDULER_TRACING
18 namespace SchedulerTracing {
20 class SchedulerTraceEntry : public AbstractTraceEntry {
21 public:
22 SchedulerTraceEntry(Thread* thread)
24 fID(thread->id)
28 thread_id ThreadID() const { return fID; }
30 virtual const char* Name() const = 0;
32 protected:
33 thread_id fID;
37 class EnqueueThread : public SchedulerTraceEntry {
38 public:
39 EnqueueThread(Thread* thread, int32 effectivePriority)
41 SchedulerTraceEntry(thread),
42 fPriority(thread->priority),
43 fEffectivePriority(effectivePriority)
45 fName = alloc_tracing_buffer_strcpy(thread->name, B_OS_NAME_LENGTH,
46 false);
47 Initialized();
50 virtual void AddDump(TraceOutput& out);
52 virtual const char* Name() const;
54 private:
55 char* fName;
56 int32 fPriority;
57 int32 fEffectivePriority;
61 class RemoveThread : public SchedulerTraceEntry {
62 public:
63 RemoveThread(Thread* thread)
65 SchedulerTraceEntry(thread),
66 fPriority(thread->priority)
68 Initialized();
71 virtual void AddDump(TraceOutput& out);
73 virtual const char* Name() const;
75 private:
76 uint8 fPriority;
80 class ScheduleThread : public SchedulerTraceEntry {
81 public:
82 ScheduleThread(Thread* thread, Thread* previous)
84 SchedulerTraceEntry(thread),
85 fPreviousID(previous->id),
86 fCPU(previous->cpu->cpu_num),
87 fPriority(thread->priority),
88 fPreviousState(previous->state),
89 fPreviousWaitObjectType(previous->wait.type)
91 fName = alloc_tracing_buffer_strcpy(thread->name, B_OS_NAME_LENGTH,
92 false);
94 #if SCHEDULER_TRACING >= 2
95 if (fPreviousState == B_THREAD_READY)
96 fPreviousPC = arch_debug_get_interrupt_pc(NULL);
97 else
98 #endif
99 fPreviousWaitObject = previous->wait.object;
101 Initialized();
104 virtual void AddDump(TraceOutput& out);
106 virtual const char* Name() const;
108 thread_id PreviousThreadID() const { return fPreviousID; }
109 uint8 PreviousState() const { return fPreviousState; }
110 uint16 PreviousWaitObjectType() const { return fPreviousWaitObjectType; }
111 const void* PreviousWaitObject() const { return fPreviousWaitObject; }
113 private:
114 thread_id fPreviousID;
115 int32 fCPU;
116 char* fName;
117 uint8 fPriority;
118 uint8 fPreviousState;
119 uint16 fPreviousWaitObjectType;
120 union {
121 const void* fPreviousWaitObject;
122 void* fPreviousPC;
126 } // namespace SchedulerTracing
128 # define T(x) new(std::nothrow) SchedulerTracing::x;
129 #else
130 # define T(x) ;
131 #endif
134 #if SCHEDULER_TRACING
136 namespace SchedulerTracing {
138 enum ScheduleState {
139 RUNNING,
140 STILL_RUNNING,
141 PREEMPTED,
142 READY,
143 WAITING,
144 UNKNOWN
149 int cmd_scheduler(int argc, char** argv);
151 #endif // SCHEDULER_TRACING
153 #endif // KERNEL_SCHEDULER_TRACING_H