]> git.cworth.org Git - apitrace/blobdiff - trace_writer.hpp
Merge branch 'master' into compression
[apitrace] / trace_writer.hpp
index 9d07150055140bb941333bd2a4d05bdb8a4f0171..dfb76b2508a4bac02f455b9d570cc733c5492f9a 100644 (file)
 
 
 namespace Trace {
+    class File;
 
     class Writer {
     protected:
-        void *g_gzFile;
+        File *m_file;
         unsigned call_no;
 
         std::vector<bool> functions;
@@ -54,7 +55,6 @@ namespace Trace {
         Writer();
         ~Writer();
 
-        void open(void);
         bool open(const char *filename);
         void close(void);
 
@@ -93,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);
@@ -102,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_ */