xref: /haiku/headers/private/kernel/tracing.h (revision 020cbad9d40235a2c50a81a42d69912a5ff8fbc4)
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 class TraceOutput {
24 	public:
25 		TraceOutput(char* buffer, size_t bufferSize);
26 
27 		void Clear();
28 		void Print(const char* format,...);
29 		bool IsFull() const	{ return fSize >= fCapacity; }
30 
31 		char* Buffer() const	{ return fBuffer; }
32 		size_t Capacity() const	{ return fCapacity; }
33 		size_t Size() const		{ return fSize; }
34 
35 	private:
36 		char*	fBuffer;
37 		size_t	fCapacity;
38 		size_t	fSize;
39 };
40 
41 class TraceEntry : public trace_entry {
42 	public:
43 		TraceEntry();
44 		virtual ~TraceEntry();
45 
46 		virtual void Dump(TraceOutput& out);
47 
48 		size_t Size() const { return size; }
49 		uint16 Flags() const { return flags; }
50 
51 		void Initialized();
52 
53 		void* operator new(size_t size, const std::nothrow_t&) throw();
54 };
55 
56 class AbstractTraceEntry : public TraceEntry {
57 	public:
58 		AbstractTraceEntry();
59 		virtual ~AbstractTraceEntry();
60 
61 		virtual void Dump(TraceOutput& out);
62 
63 		virtual void AddDump(TraceOutput& out);
64 
65 		thread_id Thread() const { return fThread; }
66 		thread_id Team() const { return fTeam; }
67 		bigtime_t Time() const { return fTime; }
68 
69 	public:
70 		static bool	sPrintTeamID;
71 
72 	protected:
73 		thread_id	fThread;
74 		team_id		fTeam;
75 		bigtime_t	fTime;
76 };
77 
78 #endif	// __cplusplus
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
84 uint8* alloc_tracing_buffer(size_t size);
85 uint8* alloc_tracing_buffer_memcpy(const void* source, size_t size, bool user);
86 char* alloc_tracing_buffer_strcpy(const char* source, size_t maxSize,
87 			bool user);
88 status_t tracing_init(void);
89 
90 void _user_ktrace_output(const char *message);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 #endif	/* KERNEL_TRACING_H */
97