btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / system / kernel / fs / vfs_tracing.h
blob0de0489e7fe5e9ad17e5be7bef685beeb64cfc1f
1 /*
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.
5 */
6 #ifndef VFS_TRACING_H
7 #define VFS_TRACING_H
10 #include <fs/fd.h>
11 #include <tracing.h>
12 #include <vfs.h>
15 // #pragma mark - File Descriptor Tracing
18 #if FILE_DESCRIPTOR_TRACING
20 namespace FileDescriptorTracing {
23 class FDTraceEntry
24 : public TRACE_ENTRY_SELECTOR(FILE_DESCRIPTOR_TRACING_STACK_TRACE) {
25 public:
26 FDTraceEntry(file_descriptor* descriptor)
28 TraceEntryBase(FILE_DESCRIPTOR_TRACING_STACK_TRACE, 0, true),
29 fDescriptor(descriptor),
30 fReferenceCount(descriptor->ref_count)
34 protected:
35 file_descriptor* fDescriptor;
36 int32 fReferenceCount;
40 class NewFD : public FDTraceEntry {
41 public:
42 NewFD(io_context* context, int fd, file_descriptor* descriptor)
44 FDTraceEntry(descriptor),
45 fContext(context),
46 fFD(fd)
48 Initialized();
51 virtual void AddDump(TraceOutput& out)
53 out.Print("fd new: descriptor: %p (%" B_PRId32 "), context: %p, "
54 "fd: %d", fDescriptor, fReferenceCount, fContext, fFD);
57 private:
58 io_context* fContext;
59 int fFD;
63 class PutFD : public FDTraceEntry {
64 public:
65 PutFD(file_descriptor* descriptor)
67 FDTraceEntry(descriptor)
69 Initialized();
72 virtual void AddDump(TraceOutput& out)
74 out.Print("fd put: descriptor: %p (%" B_PRId32 ")", fDescriptor,
75 fReferenceCount);
80 class GetFD : public FDTraceEntry {
81 public:
82 GetFD(io_context* context, int fd, file_descriptor* descriptor)
84 FDTraceEntry(descriptor),
85 fContext(context),
86 fFD(fd)
88 Initialized();
91 virtual void AddDump(TraceOutput& out)
93 out.Print("fd get: descriptor: %p (%" B_PRId32 "), context: %p, "
94 "fd: %d", fDescriptor, fReferenceCount, fContext, fFD);
97 private:
98 io_context* fContext;
99 int fFD;
103 class RemoveFD : public FDTraceEntry {
104 public:
105 RemoveFD(io_context* context, int fd, file_descriptor* descriptor)
107 FDTraceEntry(descriptor),
108 fContext(context),
109 fFD(fd)
111 Initialized();
114 virtual void AddDump(TraceOutput& out)
116 out.Print("fd remove: descriptor: %p (%" B_PRId32 "), context: %p, "
117 "fd: %d", fDescriptor, fReferenceCount, fContext, fFD);
120 private:
121 io_context* fContext;
122 int fFD;
126 class Dup2FD : public FDTraceEntry {
127 public:
128 Dup2FD(io_context* context, int oldFD, int newFD)
130 FDTraceEntry(context->fds[oldFD]),
131 fContext(context),
132 fEvictedDescriptor(context->fds[newFD]),
133 fEvictedReferenceCount(
134 fEvictedDescriptor != NULL ? fEvictedDescriptor->ref_count : 0),
135 fOldFD(oldFD),
136 fNewFD(newFD)
138 Initialized();
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);
149 private:
150 io_context* fContext;
151 file_descriptor* fEvictedDescriptor;
152 int32 fEvictedReferenceCount;
153 int fOldFD;
154 int fNewFD;
158 class InheritFD : public FDTraceEntry {
159 public:
160 InheritFD(io_context* context, int fd, file_descriptor* descriptor,
161 io_context* parentContext)
163 FDTraceEntry(descriptor),
164 fContext(context),
165 fParentContext(parentContext),
166 fFD(fd)
168 Initialized();
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);
178 private:
179 io_context* fContext;
180 io_context* fParentContext;
181 int fFD;
185 } // namespace FileDescriptorTracing
187 # define TFD(x) new(std::nothrow) FileDescriptorTracing::x
189 #else
190 # define TFD(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 {
204 public:
205 IOContextTraceEntry(io_context* context)
207 fContext(context)
209 #if IO_CONTEXT_TRACING_STACK_TRACE
210 fStackTrace = capture_tracing_stack_trace(
211 IO_CONTEXT_TRACING_STACK_TRACE, 0, false);
212 #endif
215 #if IO_CONTEXT_TRACING_STACK_TRACE
216 virtual void DumpStackTrace(TraceOutput& out)
218 out.PrintStackTrace(fStackTrace);
220 #endif
222 protected:
223 io_context* fContext;
224 #if IO_CONTEXT_TRACING_STACK_TRACE
225 tracing_stack_trace* fStackTrace;
226 #endif
230 class NewIOContext : public IOContextTraceEntry {
231 public:
232 NewIOContext(io_context* context, io_context* parentContext)
234 IOContextTraceEntry(context),
235 fParentContext(parentContext)
237 Initialized();
240 virtual void AddDump(TraceOutput& out)
242 out.Print("iocontext new: context: %p, parent: %p", fContext,
243 fParentContext);
246 private:
247 io_context* fParentContext;
251 class FreeIOContext : public IOContextTraceEntry {
252 public:
253 FreeIOContext(io_context* context)
255 IOContextTraceEntry(context)
257 Initialized();
260 virtual void AddDump(TraceOutput& out)
262 out.Print("iocontext free: context: %p", fContext);
267 class ResizeIOContext : public IOContextTraceEntry {
268 public:
269 ResizeIOContext(io_context* context, uint32 newTableSize)
271 IOContextTraceEntry(context),
272 fOldTableSize(context->table_size),
273 fNewTableSize(newTableSize)
275 Initialized();
278 virtual void AddDump(TraceOutput& out)
280 out.Print("iocontext resize: context: %p, size: %" B_PRIu32 " -> %"
281 B_PRIu32, fContext, fOldTableSize, fNewTableSize);
284 private:
285 uint32 fOldTableSize;
286 uint32 fNewTableSize;
290 } // namespace IOContextTracing
292 # define TIOC(x) new(std::nothrow) IOContextTracing::x
294 #else
295 # define TIOC(x)
296 #endif // IO_CONTEXT_TRACING
299 #endif // VFS_TRACING_H