2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2010, Michael Lotz, mmlr@mlotz.ch.
4 * Distributed under the terms of the MIT License.
15 // #pragma mark - File Descriptor Tracing
18 #if FILE_DESCRIPTOR_TRACING
20 namespace FileDescriptorTracing
{
24 : public TRACE_ENTRY_SELECTOR(FILE_DESCRIPTOR_TRACING_STACK_TRACE
) {
26 FDTraceEntry(file_descriptor
* descriptor
)
28 TraceEntryBase(FILE_DESCRIPTOR_TRACING_STACK_TRACE
, 0, true),
29 fDescriptor(descriptor
),
30 fReferenceCount(descriptor
->ref_count
)
35 file_descriptor
* fDescriptor
;
36 int32 fReferenceCount
;
40 class NewFD
: public FDTraceEntry
{
42 NewFD(io_context
* context
, int fd
, file_descriptor
* descriptor
)
44 FDTraceEntry(descriptor
),
51 virtual void AddDump(TraceOutput
& out
)
53 out
.Print("fd new: descriptor: %p (%" B_PRId32
"), context: %p, "
54 "fd: %d", fDescriptor
, fReferenceCount
, fContext
, fFD
);
63 class PutFD
: public FDTraceEntry
{
65 PutFD(file_descriptor
* descriptor
)
67 FDTraceEntry(descriptor
)
72 virtual void AddDump(TraceOutput
& out
)
74 out
.Print("fd put: descriptor: %p (%" B_PRId32
")", fDescriptor
,
80 class GetFD
: public FDTraceEntry
{
82 GetFD(io_context
* context
, int fd
, file_descriptor
* descriptor
)
84 FDTraceEntry(descriptor
),
91 virtual void AddDump(TraceOutput
& out
)
93 out
.Print("fd get: descriptor: %p (%" B_PRId32
"), context: %p, "
94 "fd: %d", fDescriptor
, fReferenceCount
, fContext
, fFD
);
103 class RemoveFD
: public FDTraceEntry
{
105 RemoveFD(io_context
* context
, int fd
, file_descriptor
* descriptor
)
107 FDTraceEntry(descriptor
),
114 virtual void AddDump(TraceOutput
& out
)
116 out
.Print("fd remove: descriptor: %p (%" B_PRId32
"), context: %p, "
117 "fd: %d", fDescriptor
, fReferenceCount
, fContext
, fFD
);
121 io_context
* fContext
;
126 class Dup2FD
: public FDTraceEntry
{
128 Dup2FD(io_context
* context
, int oldFD
, int newFD
)
130 FDTraceEntry(context
->fds
[oldFD
]),
132 fEvictedDescriptor(context
->fds
[newFD
]),
133 fEvictedReferenceCount(
134 fEvictedDescriptor
!= NULL
? fEvictedDescriptor
->ref_count
: 0),
141 virtual void AddDump(TraceOutput
& out
)
143 out
.Print("fd dup2: descriptor: %p (%" B_PRId32
"), context: %p, "
144 "fd: %d -> %d, evicted: %p (%" B_PRId32
")", fDescriptor
,
145 fReferenceCount
, fContext
, fOldFD
, fNewFD
, fEvictedDescriptor
,
146 fEvictedReferenceCount
);
150 io_context
* fContext
;
151 file_descriptor
* fEvictedDescriptor
;
152 int32 fEvictedReferenceCount
;
158 class InheritFD
: public FDTraceEntry
{
160 InheritFD(io_context
* context
, int fd
, file_descriptor
* descriptor
,
161 io_context
* parentContext
)
163 FDTraceEntry(descriptor
),
165 fParentContext(parentContext
),
171 virtual void AddDump(TraceOutput
& out
)
173 out
.Print("fd inherit: descriptor: %p (%" B_PRId32
"), context: %p, "
174 "fd: %d, parentContext: %p", fDescriptor
, fReferenceCount
, fContext
,
175 fFD
, fParentContext
);
179 io_context
* fContext
;
180 io_context
* fParentContext
;
185 } // namespace FileDescriptorTracing
187 # define TFD(x) new(std::nothrow) FileDescriptorTracing::x
191 #endif // FILE_DESCRIPTOR_TRACING
194 // #pragma mark - IO Context Tracing
198 #if IO_CONTEXT_TRACING
200 namespace IOContextTracing
{
203 class IOContextTraceEntry
: public AbstractTraceEntry
{
205 IOContextTraceEntry(io_context
* context
)
209 #if IO_CONTEXT_TRACING_STACK_TRACE
210 fStackTrace
= capture_tracing_stack_trace(
211 IO_CONTEXT_TRACING_STACK_TRACE
, 0, false);
215 #if IO_CONTEXT_TRACING_STACK_TRACE
216 virtual void DumpStackTrace(TraceOutput
& out
)
218 out
.PrintStackTrace(fStackTrace
);
223 io_context
* fContext
;
224 #if IO_CONTEXT_TRACING_STACK_TRACE
225 tracing_stack_trace
* fStackTrace
;
230 class NewIOContext
: public IOContextTraceEntry
{
232 NewIOContext(io_context
* context
, io_context
* parentContext
)
234 IOContextTraceEntry(context
),
235 fParentContext(parentContext
)
240 virtual void AddDump(TraceOutput
& out
)
242 out
.Print("iocontext new: context: %p, parent: %p", fContext
,
247 io_context
* fParentContext
;
251 class FreeIOContext
: public IOContextTraceEntry
{
253 FreeIOContext(io_context
* context
)
255 IOContextTraceEntry(context
)
260 virtual void AddDump(TraceOutput
& out
)
262 out
.Print("iocontext free: context: %p", fContext
);
267 class ResizeIOContext
: public IOContextTraceEntry
{
269 ResizeIOContext(io_context
* context
, uint32 newTableSize
)
271 IOContextTraceEntry(context
),
272 fOldTableSize(context
->table_size
),
273 fNewTableSize(newTableSize
)
278 virtual void AddDump(TraceOutput
& out
)
280 out
.Print("iocontext resize: context: %p, size: %" B_PRIu32
" -> %"
281 B_PRIu32
, fContext
, fOldTableSize
, fNewTableSize
);
285 uint32 fOldTableSize
;
286 uint32 fNewTableSize
;
290 } // namespace IOContextTracing
292 # define TIOC(x) new(std::nothrow) IOContextTracing::x
296 #endif // IO_CONTEXT_TRACING
299 #endif // VFS_TRACING_H