X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=trace_writer.hpp;h=dfb76b2508a4bac02f455b9d570cc733c5492f9a;hb=da7579b25c6bba1c6406d8b9382df126aca077f3;hp=3b7955e62ef222840b75b85a55381710f461c12d;hpb=466753b9c94f4ea5c771c791e64c575da4b01701;p=apitrace diff --git a/trace_writer.hpp b/trace_writer.hpp index 3b7955e..dfb76b2 100644 --- a/trace_writer.hpp +++ b/trace_writer.hpp @@ -30,48 +30,20 @@ #ifndef _TRACE_WRITER_HPP_ #define _TRACE_WRITER_HPP_ + #include #include -namespace Trace { - - typedef unsigned Id; - - struct FunctionSig { - Id id; - const char *name; - unsigned num_args; - const char **arg_names; - }; - - struct StructSig { - Id id; - const char *name; - unsigned num_members; - const char **member_names; - }; +#include "trace_model.hpp" - struct EnumSig { - Id id; - const char *name; - signed long long value; - }; - struct BitmaskFlag { - const char *name; - unsigned long long value; - }; - - struct BitmaskSig { - Id id; - unsigned num_flags; - const BitmaskFlag *flags; - }; +namespace Trace { + class File; class Writer { protected: - void *g_gzFile; + File *m_file; unsigned call_no; std::vector functions; @@ -83,7 +55,6 @@ namespace Trace { Writer(); ~Writer(); - void open(void); bool open(const char *filename); void close(void); @@ -122,6 +93,8 @@ namespace Trace { void writeNull(void); void writeOpaque(const void *ptr); + void writeCall(Call *call); + protected: void inline _write(const void *sBuffer, size_t dwBytesToWrite); void inline _writeByte(char c); @@ -131,6 +104,42 @@ namespace Trace { void inline _writeString(const char *str); }; + + /** + * A specialized Writer class, mean to trace the current process. + * + * In particular: + * - it creates a trace file based on the current process name + * - uses mutexes to allow tracing from multiple threades + * - flushes the output to ensure the last call is traced in event of + * abnormal termination + */ + class LocalWriter : public Writer { + protected: + int acquired; + + public: + /** + * Should never called directly -- use localWriter singleton below instead. + */ + LocalWriter(); + ~LocalWriter(); + + void open(void); + + unsigned beginEnter(const FunctionSig *sig); + void endEnter(void); + + void beginLeave(unsigned call); + void endLeave(void); + + void flush(void); + }; + + /** + * Singleton. + */ + extern LocalWriter localWriter; } #endif /* _TRACE_WRITER_HPP_ */