]> git.cworth.org Git - apitrace/blobdiff - trace_writer.hpp
Merge branch 'master' into compression
[apitrace] / trace_writer.hpp
index 5e7416b0696959ca87f6285fe781277228be7ba2..4d46f739f8f231fcdee4e39de053b21949193448 100644 (file)
 #ifndef _TRACE_WRITER_HPP_
 #define _TRACE_WRITER_HPP_
 
+
 #include <stddef.h>
 
 #include <vector>
 
-namespace Trace {
-
-    typedef unsigned Id;
-
-    struct FunctionSig {
-        Id id;
-        const char *name;
-        unsigned num_args;
-        const char **args;
-    };
-
-    struct StructSig {
-        Id id;
-        const char *name;
-        unsigned num_members;
-        const char **members;
-    };
-
-    struct EnumSig {
-        Id id;
-        const char *name;
-        signed long long value;
-    };
+#include "trace_model.hpp"
 
-    struct BitmaskVal {
-        const char *name;
-        unsigned long long value;
-    };
 
-    struct BitmaskSig {
-        Id id;
-        unsigned count;
-        const BitmaskVal *values;
-    };
+namespace Trace {
+    class File;
 
     class Writer {
     protected:
-        void *g_gzFile;
+        File *m_file;
         unsigned call_no;
 
         std::vector<bool> functions;
@@ -83,11 +55,10 @@ namespace Trace {
         Writer();
         ~Writer();
 
-        void open(void);
         bool open(const char *filename);
         void close(void);
 
-        unsigned beginEnter(const FunctionSig &function);
+        unsigned beginEnter(const FunctionSig *sig);
         void endEnter(void);
 
         void beginLeave(unsigned call);
@@ -118,10 +89,12 @@ namespace Trace {
         void writeWString(const wchar_t *str);
         void writeBlob(const void *data, size_t size);
         void writeEnum(const EnumSig *sig);
-        void writeBitmask(const BitmaskSig &bitmask, unsigned long long value);
+        void writeBitmask(const BitmaskSig *sig, unsigned long long value);
         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,27 @@ 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:
+    public:
+        void open(void);
+
+        unsigned beginEnter(const FunctionSig *sig);
+        void endEnter(void);
+
+        void beginLeave(unsigned call);
+        void endLeave(void);
+    };
 }
 
 #endif /* _TRACE_WRITER_HPP_ */