xref: /haiku/headers/private/kernel/tracing.h (revision ed6250c95736c0b55da79d6e9dd01369532260c0)
1 #ifndef KERNEL_TRACING_H
2 #define KERNEL_TRACING_H
3 
4 
5 #include <SupportDefs.h>
6 #include <KernelExport.h>
7 
8 #include <stdio.h>
9 
10 #include <tracing_config.h>
11 
12 
13 struct trace_entry {
14 	uint32	size			: 14;		// actual size is *4
15 	uint32	previous_size	: 14;		// actual size is *4
16 	uint32	flags			: 4;
17 };
18 
19 #ifdef __cplusplus
20 
21 #include <new>
22 
23 
24 // trace output flags
25 #define TRACE_OUTPUT_TEAM_ID	0x01
26 	// print the team ID
27 #define TRACE_OUTPUT_DIFF_TIME	0x02
28 	// print the difference time to the previously printed entry instead of the
29 	// absolute time
30 
31 
32 class TraceOutput {
33 	public:
34 		TraceOutput(char* buffer, size_t bufferSize, uint32 flags);
35 
36 		void Clear();
37 		void Print(const char* format,...);
38 		bool IsFull() const	{ return fSize >= fCapacity; }
39 
40 		char* Buffer() const	{ return fBuffer; }
41 		size_t Capacity() const	{ return fCapacity; }
42 		size_t Size() const		{ return fSize; }
43 
44 		uint32 Flags() const	{ return fFlags; }
45 
46 		void SetLastEntryTime(bigtime_t time);
47 		bigtime_t LastEntryTime() const;
48 
49 	private:
50 		char*		fBuffer;
51 		size_t		fCapacity;
52 		size_t		fSize;
53 		uint32		fFlags;
54 		bigtime_t	fLastEntryTime;
55 };
56 
57 class TraceEntry : public trace_entry {
58 	public:
59 		TraceEntry();
60 		virtual ~TraceEntry();
61 
62 		virtual void Dump(TraceOutput& out);
63 
64 		size_t Size() const { return size; }
65 		uint16 Flags() const { return flags; }
66 
67 		void Initialized();
68 
69 		void* operator new(size_t size, const std::nothrow_t&) throw();
70 };
71 
72 class AbstractTraceEntry : public TraceEntry {
73 	public:
74 		AbstractTraceEntry();
75 		virtual ~AbstractTraceEntry();
76 
77 		virtual void Dump(TraceOutput& out);
78 
79 		virtual void AddDump(TraceOutput& out);
80 
81 		thread_id Thread() const { return fThread; }
82 		thread_id Team() const { return fTeam; }
83 		bigtime_t Time() const { return fTime; }
84 
85 	protected:
86 		thread_id	fThread;
87 		team_id		fTeam;
88 		bigtime_t	fTime;
89 };
90 
91 #endif	// __cplusplus
92 
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96 
97 uint8* alloc_tracing_buffer(size_t size);
98 uint8* alloc_tracing_buffer_memcpy(const void* source, size_t size, bool user);
99 char* alloc_tracing_buffer_strcpy(const char* source, size_t maxSize,
100 			bool user);
101 status_t tracing_init(void);
102 
103 void _user_ktrace_output(const char *message);
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif	/* KERNEL_TRACING_H */
110