2008-05-06 07:30:48 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
|
|
|
|
* Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2008-01-19 20:24:34 +03:00
|
|
|
#ifndef KERNEL_TRACING_H
|
|
|
|
#define KERNEL_TRACING_H
|
2008-01-12 21:41:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
#include <SupportDefs.h>
|
2008-01-13 02:55:53 +03:00
|
|
|
#include <KernelExport.h>
|
2008-01-12 21:41:35 +03:00
|
|
|
|
2008-01-13 05:50:32 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2008-03-28 01:01:38 +03:00
|
|
|
#include "tracing_config.h"
|
2008-01-12 21:41:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
struct trace_entry {
|
2008-01-21 03:41:45 +03:00
|
|
|
uint32 size : 14; // actual size is *4
|
|
|
|
uint32 previous_size : 14; // actual size is *4
|
|
|
|
uint32 flags : 4;
|
2008-01-12 21:41:35 +03:00
|
|
|
};
|
|
|
|
|
2008-04-27 07:02:01 +04:00
|
|
|
struct tracing_stack_trace;
|
|
|
|
|
2008-01-12 21:41:35 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
#include <new>
|
|
|
|
|
2008-02-04 20:54:40 +03:00
|
|
|
|
|
|
|
// trace output flags
|
|
|
|
#define TRACE_OUTPUT_TEAM_ID 0x01
|
|
|
|
// print the team ID
|
|
|
|
#define TRACE_OUTPUT_DIFF_TIME 0x02
|
|
|
|
// print the difference time to the previously printed entry instead of the
|
|
|
|
// absolute time
|
|
|
|
|
|
|
|
|
2008-01-19 01:15:30 +03:00
|
|
|
class TraceOutput {
|
|
|
|
public:
|
2008-02-04 20:54:40 +03:00
|
|
|
TraceOutput(char* buffer, size_t bufferSize, uint32 flags);
|
2008-01-19 01:15:30 +03:00
|
|
|
|
2008-01-20 01:23:32 +03:00
|
|
|
void Clear();
|
2008-07-20 16:30:22 +04:00
|
|
|
void Print(const char* format,...)
|
|
|
|
__attribute__ ((format (__printf__, 2, 3)));
|
2008-04-27 07:02:01 +04:00
|
|
|
void PrintStackTrace(tracing_stack_trace* stackTrace);
|
2008-01-19 01:15:30 +03:00
|
|
|
bool IsFull() const { return fSize >= fCapacity; }
|
|
|
|
|
2008-01-20 03:34:37 +03:00
|
|
|
char* Buffer() const { return fBuffer; }
|
|
|
|
size_t Capacity() const { return fCapacity; }
|
|
|
|
size_t Size() const { return fSize; }
|
|
|
|
|
2008-02-04 20:54:40 +03:00
|
|
|
uint32 Flags() const { return fFlags; }
|
|
|
|
|
|
|
|
void SetLastEntryTime(bigtime_t time);
|
|
|
|
bigtime_t LastEntryTime() const;
|
|
|
|
|
2008-01-19 01:15:30 +03:00
|
|
|
private:
|
2008-02-04 20:54:40 +03:00
|
|
|
char* fBuffer;
|
|
|
|
size_t fCapacity;
|
|
|
|
size_t fSize;
|
|
|
|
uint32 fFlags;
|
|
|
|
bigtime_t fLastEntryTime;
|
2008-01-19 01:15:30 +03:00
|
|
|
};
|
|
|
|
|
2008-05-17 22:59:19 +04:00
|
|
|
class TraceEntry {
|
2008-01-12 21:41:35 +03:00
|
|
|
public:
|
|
|
|
TraceEntry();
|
|
|
|
virtual ~TraceEntry();
|
|
|
|
|
2008-01-20 01:23:32 +03:00
|
|
|
virtual void Dump(TraceOutput& out);
|
2008-04-27 07:02:01 +04:00
|
|
|
virtual void DumpStackTrace(TraceOutput& out);
|
2008-01-12 21:41:35 +03:00
|
|
|
|
2008-05-17 22:59:19 +04:00
|
|
|
size_t Size() const { return ToTraceEntry()->size; }
|
|
|
|
uint16 Flags() const { return ToTraceEntry()->flags; }
|
2008-01-12 21:41:35 +03:00
|
|
|
|
|
|
|
void Initialized();
|
|
|
|
|
2008-01-13 02:55:53 +03:00
|
|
|
void* operator new(size_t size, const std::nothrow_t&) throw();
|
2008-05-17 22:59:19 +04:00
|
|
|
|
|
|
|
trace_entry* ToTraceEntry() const
|
|
|
|
{
|
|
|
|
return (trace_entry*)this - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TraceEntry* FromTraceEntry(trace_entry* entry)
|
|
|
|
{
|
|
|
|
return (TraceEntry*)(entry + 1);
|
|
|
|
}
|
2008-01-13 02:55:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class AbstractTraceEntry : public TraceEntry {
|
|
|
|
public:
|
2008-01-21 16:31:27 +03:00
|
|
|
AbstractTraceEntry();
|
2008-01-19 01:15:30 +03:00
|
|
|
virtual ~AbstractTraceEntry();
|
2008-01-13 05:50:32 +03:00
|
|
|
|
2008-01-20 01:23:32 +03:00
|
|
|
virtual void Dump(TraceOutput& out);
|
2008-01-19 01:15:30 +03:00
|
|
|
|
|
|
|
virtual void AddDump(TraceOutput& out);
|
2008-01-13 02:55:53 +03:00
|
|
|
|
|
|
|
thread_id Thread() const { return fThread; }
|
2008-01-21 16:31:27 +03:00
|
|
|
thread_id Team() const { return fTeam; }
|
2008-01-13 02:55:53 +03:00
|
|
|
bigtime_t Time() const { return fTime; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
thread_id fThread;
|
2008-01-21 16:31:27 +03:00
|
|
|
team_id fTeam;
|
2008-01-13 02:55:53 +03:00
|
|
|
bigtime_t fTime;
|
2008-01-12 21:41:35 +03:00
|
|
|
};
|
|
|
|
|
2008-04-22 18:52:48 +04:00
|
|
|
class LazyTraceOutput : public TraceOutput {
|
|
|
|
public:
|
|
|
|
LazyTraceOutput(char* buffer, size_t bufferSize, uint32 flags)
|
|
|
|
: TraceOutput(buffer, bufferSize, flags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* DumpEntry(const TraceEntry* entry)
|
|
|
|
{
|
|
|
|
if (Size() == 0) {
|
|
|
|
const_cast<TraceEntry*>(entry)->Dump(*this);
|
|
|
|
// Dump() should probably be const
|
|
|
|
}
|
|
|
|
|
|
|
|
return Buffer();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class TraceFilter {
|
|
|
|
public:
|
|
|
|
virtual ~TraceFilter();
|
|
|
|
|
|
|
|
virtual bool Filter(const TraceEntry* entry, LazyTraceOutput& out);
|
|
|
|
|
|
|
|
public:
|
|
|
|
union {
|
|
|
|
thread_id fThread;
|
|
|
|
team_id fTeam;
|
|
|
|
const char* fString;
|
|
|
|
uint64 fValue;
|
|
|
|
struct {
|
|
|
|
TraceFilter* first;
|
|
|
|
TraceFilter* second;
|
|
|
|
} fSubFilters;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
class WrapperTraceFilter : public TraceFilter {
|
|
|
|
public:
|
|
|
|
virtual void Init(TraceFilter* filter, int direction, bool continued) = 0;
|
|
|
|
};
|
|
|
|
|
2008-01-12 21:41:35 +03:00
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2008-01-13 05:50:32 +03:00
|
|
|
extern "C" {
|
2008-01-12 21:41:35 +03:00
|
|
|
#endif
|
2008-01-13 05:50:32 +03:00
|
|
|
|
|
|
|
uint8* alloc_tracing_buffer(size_t size);
|
2008-01-17 04:58:08 +03:00
|
|
|
uint8* alloc_tracing_buffer_memcpy(const void* source, size_t size, bool user);
|
|
|
|
char* alloc_tracing_buffer_strcpy(const char* source, size_t maxSize,
|
|
|
|
bool user);
|
2008-04-27 07:02:01 +04:00
|
|
|
tracing_stack_trace* capture_tracing_stack_trace(int32 maxCount,
|
|
|
|
int32 skipFrames, bool userOnly);
|
2008-04-22 18:52:48 +04:00
|
|
|
int dump_tracing(int argc, char** argv, WrapperTraceFilter* wrapperFilter);
|
2008-01-12 21:41:35 +03:00
|
|
|
status_t tracing_init(void);
|
|
|
|
|
2008-01-21 18:10:05 +03:00
|
|
|
void _user_ktrace_output(const char *message);
|
|
|
|
|
2008-01-13 05:50:32 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-19 20:24:34 +03:00
|
|
|
#endif /* KERNEL_TRACING_H */
|