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.
6 #ifndef KERNEL_SCHEDULER_TRACING_H
7 #define KERNEL_SCHEDULER_TRACING_H
10 #include <arch/debug.h>
18 namespace SchedulerTracing
{
20 class SchedulerTraceEntry
: public AbstractTraceEntry
{
22 SchedulerTraceEntry(Thread
* thread
)
28 thread_id
ThreadID() const { return fID
; }
30 virtual const char* Name() const = 0;
37 class EnqueueThread
: public SchedulerTraceEntry
{
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
,
50 virtual void AddDump(TraceOutput
& out
);
52 virtual const char* Name() const;
57 int32 fEffectivePriority
;
61 class RemoveThread
: public SchedulerTraceEntry
{
63 RemoveThread(Thread
* thread
)
65 SchedulerTraceEntry(thread
),
66 fPriority(thread
->priority
)
71 virtual void AddDump(TraceOutput
& out
);
73 virtual const char* Name() const;
80 class ScheduleThread
: public SchedulerTraceEntry
{
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
,
94 #if SCHEDULER_TRACING >= 2
95 if (fPreviousState
== B_THREAD_READY
)
96 fPreviousPC
= arch_debug_get_interrupt_pc(NULL
);
99 fPreviousWaitObject
= previous
->wait
.object
;
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
; }
114 thread_id fPreviousID
;
118 uint8 fPreviousState
;
119 uint16 fPreviousWaitObjectType
;
121 const void* fPreviousWaitObject
;
126 } // namespace SchedulerTracing
128 # define T(x) new(std::nothrow) SchedulerTracing::x;
134 #if SCHEDULER_TRACING
136 namespace SchedulerTracing
{
149 int cmd_scheduler(int argc
, char** argv
);
151 #endif // SCHEDULER_TRACING
153 #endif // KERNEL_SCHEDULER_TRACING_H