]> git.cworth.org Git - apitrace/commitdiff
Rename trace writer files to group nicely.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 26 Oct 2011 22:39:16 +0000 (23:39 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 26 Oct 2011 22:39:16 +0000 (23:39 +0100)
CMakeLists.txt
common/trace_local_writer.cpp [deleted file]
common/trace_model_writer.cpp [deleted file]
common/trace_writer_local.cpp [new file with mode: 0644]
common/trace_writer_model.cpp [new file with mode: 0644]

index 3499fe4f478967d928ab21cd3766804b4affa856..3066b62c3d06c90f8cf92bf7dc82a409ddc63eb1 100755 (executable)
@@ -213,8 +213,8 @@ add_library (common STATIC
     common/trace_model.cpp
     common/trace_parser.cpp
     common/trace_writer.cpp
-    common/trace_local_writer.cpp
-    common/trace_model_writer.cpp
+    common/trace_writer_local.cpp
+    common/trace_writer_model.cpp
     common/trace_loader.cpp
     common/image.cpp
     common/image_bmp.cpp
diff --git a/common/trace_local_writer.cpp b/common/trace_local_writer.cpp
deleted file mode 100644 (file)
index e560e49..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2007-2011 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- **************************************************************************/
-
-
-#include <assert.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "os.hpp"
-#include "trace_file.hpp"
-#include "trace_writer.hpp"
-#include "trace_format.hpp"
-
-
-namespace Trace {
-
-
-static const char *memcpy_args[3] = {"dest", "src", "n"};
-const FunctionSig memcpy_sig = {0, "memcpy", 3, memcpy_args};
-
-static const char *malloc_args[1] = {"size"};
-const FunctionSig malloc_sig = {1, "malloc", 1, malloc_args};
-
-static const char *free_args[1] = {"ptr"};
-const FunctionSig free_sig = {2, "free", 1, free_args};
-
-static const char *realloc_args[2] = {"ptr", "size"};
-const FunctionSig realloc_sig = {3, "realloc", 2, realloc_args};
-
-
-static void exceptionCallback(void)
-{
-    localWriter.flush();
-}
-
-
-LocalWriter::LocalWriter() :
-    acquired(0)
-{
-    // Install the signal handlers as early as possible, to prevent
-    // interfering with the application's signal handling.
-    OS::SetExceptionCallback(exceptionCallback);
-}
-
-LocalWriter::~LocalWriter()
-{
-    OS::ResetExceptionCallback();
-}
-
-void
-LocalWriter::open(void) {
-
-    static unsigned dwCounter = 0;
-
-    const char *szExtension = "trace";
-    char szFileName[PATH_MAX];
-    const char *lpFileName;
-
-    lpFileName = getenv("TRACE_FILE");
-    if (lpFileName) {
-        strncpy(szFileName, lpFileName, PATH_MAX);
-    }
-    else {
-        char szProcessName[PATH_MAX];
-        char szCurrentDir[PATH_MAX];
-        OS::GetProcessName(szProcessName, PATH_MAX);
-        OS::GetCurrentDir(szCurrentDir, PATH_MAX);
-
-        for (;;) {
-            FILE *file;
-
-            if (dwCounter)
-                snprintf(szFileName, PATH_MAX, "%s%c%s.%u.%s", szCurrentDir, PATH_SEP, szProcessName, dwCounter, szExtension);
-            else
-                snprintf(szFileName, PATH_MAX, "%s%c%s.%s", szCurrentDir, PATH_SEP, szProcessName, szExtension);
-
-            file = fopen(szFileName, "rb");
-            if (file == NULL)
-                break;
-
-            fclose(file);
-
-            ++dwCounter;
-        }
-    }
-
-    OS::DebugMessage("apitrace: tracing to %s\n", szFileName);
-
-    Writer::open(szFileName);
-
-#if 0
-    // For debugging the exception handler
-    *((int *)0) = 0;
-#endif
-}
-
-unsigned LocalWriter::beginEnter(const FunctionSig *sig) {
-    OS::AcquireMutex();
-    ++acquired;
-
-    if (!m_file->isOpened()) {
-        open();
-    }
-
-    return Writer::beginEnter(sig);
-}
-
-void LocalWriter::endEnter(void) {
-    Writer::endEnter();
-    --acquired;
-    OS::ReleaseMutex();
-}
-
-void LocalWriter::beginLeave(unsigned call) {
-    OS::AcquireMutex();
-    ++acquired;
-    Writer::beginLeave(call);
-}
-
-void LocalWriter::endLeave(void) {
-    Writer::endLeave();
-    --acquired;
-    OS::ReleaseMutex();
-}
-
-void LocalWriter::flush(void) {
-    /*
-     * Do nothing if the mutex is already acquired (e.g., if a segfault happen
-     * while writing the file) to prevent dead-lock.
-     */
-
-    if (!acquired) {
-        OS::AcquireMutex();
-        if (m_file->isOpened()) {
-            OS::DebugMessage("apitrace: flushing trace due to an exception\n");
-            m_file->flush();
-        }
-        OS::ReleaseMutex();
-    }
-}
-
-
-LocalWriter localWriter;
-
-
-} /* namespace Trace */
-
diff --git a/common/trace_model_writer.cpp b/common/trace_model_writer.cpp
deleted file mode 100644 (file)
index dcfcf86..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2011 Jose Fonseca
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- **************************************************************************/
-
-
-#include "trace_writer.hpp"
-
-
-namespace Trace {
-
-
-class ModelWriter : public Visitor
-{
-protected:
-    Writer &writer;
-
-public:
-    ModelWriter(Writer &_writer) :
-        writer(_writer) {
-    }
-
-    void visit(Null *) {
-        writer.writeNull();
-    }
-
-    void visit(Bool *node) {
-        writer.writeBool(node->value);
-    }
-
-    void visit(SInt *node) {
-        writer.writeSInt(node->value);
-    }
-
-    void visit(UInt *node) {
-        writer.writeUInt(node->value);
-    }
-
-    void visit(Float *node) {
-        writer.writeFloat(node->value);
-    }
-
-    void visit(String *node) {
-        writer.writeString(node->value);
-    }
-
-    void visit(Enum *node) {
-        writer.writeEnum(node->sig);
-    }
-
-    void visit(Bitmask *node) {
-        writer.writeBitmask(node->sig, node->value);
-    }
-
-    void visit(Struct *node) {
-        writer.beginStruct(node->sig);
-        for (unsigned i = 0; i < node->sig->num_members; ++i) {
-            _visit(node->members[i]);
-        }
-        writer.endStruct();
-    }
-
-    void visit(Array *node) {
-        writer.beginArray(node->values.size());
-        for (std::vector<Value *>::iterator it = node->values.begin(); it != node->values.end(); ++it) {
-            _visit(*it);
-        }
-        writer.endArray();
-    }
-
-    void visit(Blob *node) {
-        writer.writeBlob(node->buf, node->size);
-    }
-
-    void visit(Pointer *node) {
-        writer.writeOpaque((const void *) (size_t) node->value);
-    }
-
-    void visit(Call *call) {
-        unsigned call_no = writer.beginEnter(call->sig);
-        for (unsigned i = 0; i < call->args.size(); ++i) {
-            if (call->args[i]) {
-                writer.beginArg(i);
-                _visit(call->args[i]);
-                writer.endArg();
-            }
-        }
-        writer.endEnter();
-        writer.beginLeave(call_no);
-        if (call->ret) {
-            writer.beginReturn();
-            _visit(call->ret);
-            writer.endReturn();
-        }
-        writer.endLeave();
-    }
-};
-
-
-void Writer::writeCall(Call *call) {
-    ModelWriter visitor(*this);
-    visitor.visit(call);
-}
-
-
-} /* namespace Trace */
-
diff --git a/common/trace_writer_local.cpp b/common/trace_writer_local.cpp
new file mode 100644 (file)
index 0000000..e560e49
--- /dev/null
@@ -0,0 +1,171 @@
+/**************************************************************************
+ *
+ * Copyright 2007-2011 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "os.hpp"
+#include "trace_file.hpp"
+#include "trace_writer.hpp"
+#include "trace_format.hpp"
+
+
+namespace Trace {
+
+
+static const char *memcpy_args[3] = {"dest", "src", "n"};
+const FunctionSig memcpy_sig = {0, "memcpy", 3, memcpy_args};
+
+static const char *malloc_args[1] = {"size"};
+const FunctionSig malloc_sig = {1, "malloc", 1, malloc_args};
+
+static const char *free_args[1] = {"ptr"};
+const FunctionSig free_sig = {2, "free", 1, free_args};
+
+static const char *realloc_args[2] = {"ptr", "size"};
+const FunctionSig realloc_sig = {3, "realloc", 2, realloc_args};
+
+
+static void exceptionCallback(void)
+{
+    localWriter.flush();
+}
+
+
+LocalWriter::LocalWriter() :
+    acquired(0)
+{
+    // Install the signal handlers as early as possible, to prevent
+    // interfering with the application's signal handling.
+    OS::SetExceptionCallback(exceptionCallback);
+}
+
+LocalWriter::~LocalWriter()
+{
+    OS::ResetExceptionCallback();
+}
+
+void
+LocalWriter::open(void) {
+
+    static unsigned dwCounter = 0;
+
+    const char *szExtension = "trace";
+    char szFileName[PATH_MAX];
+    const char *lpFileName;
+
+    lpFileName = getenv("TRACE_FILE");
+    if (lpFileName) {
+        strncpy(szFileName, lpFileName, PATH_MAX);
+    }
+    else {
+        char szProcessName[PATH_MAX];
+        char szCurrentDir[PATH_MAX];
+        OS::GetProcessName(szProcessName, PATH_MAX);
+        OS::GetCurrentDir(szCurrentDir, PATH_MAX);
+
+        for (;;) {
+            FILE *file;
+
+            if (dwCounter)
+                snprintf(szFileName, PATH_MAX, "%s%c%s.%u.%s", szCurrentDir, PATH_SEP, szProcessName, dwCounter, szExtension);
+            else
+                snprintf(szFileName, PATH_MAX, "%s%c%s.%s", szCurrentDir, PATH_SEP, szProcessName, szExtension);
+
+            file = fopen(szFileName, "rb");
+            if (file == NULL)
+                break;
+
+            fclose(file);
+
+            ++dwCounter;
+        }
+    }
+
+    OS::DebugMessage("apitrace: tracing to %s\n", szFileName);
+
+    Writer::open(szFileName);
+
+#if 0
+    // For debugging the exception handler
+    *((int *)0) = 0;
+#endif
+}
+
+unsigned LocalWriter::beginEnter(const FunctionSig *sig) {
+    OS::AcquireMutex();
+    ++acquired;
+
+    if (!m_file->isOpened()) {
+        open();
+    }
+
+    return Writer::beginEnter(sig);
+}
+
+void LocalWriter::endEnter(void) {
+    Writer::endEnter();
+    --acquired;
+    OS::ReleaseMutex();
+}
+
+void LocalWriter::beginLeave(unsigned call) {
+    OS::AcquireMutex();
+    ++acquired;
+    Writer::beginLeave(call);
+}
+
+void LocalWriter::endLeave(void) {
+    Writer::endLeave();
+    --acquired;
+    OS::ReleaseMutex();
+}
+
+void LocalWriter::flush(void) {
+    /*
+     * Do nothing if the mutex is already acquired (e.g., if a segfault happen
+     * while writing the file) to prevent dead-lock.
+     */
+
+    if (!acquired) {
+        OS::AcquireMutex();
+        if (m_file->isOpened()) {
+            OS::DebugMessage("apitrace: flushing trace due to an exception\n");
+            m_file->flush();
+        }
+        OS::ReleaseMutex();
+    }
+}
+
+
+LocalWriter localWriter;
+
+
+} /* namespace Trace */
+
diff --git a/common/trace_writer_model.cpp b/common/trace_writer_model.cpp
new file mode 100644 (file)
index 0000000..dcfcf86
--- /dev/null
@@ -0,0 +1,127 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include "trace_writer.hpp"
+
+
+namespace Trace {
+
+
+class ModelWriter : public Visitor
+{
+protected:
+    Writer &writer;
+
+public:
+    ModelWriter(Writer &_writer) :
+        writer(_writer) {
+    }
+
+    void visit(Null *) {
+        writer.writeNull();
+    }
+
+    void visit(Bool *node) {
+        writer.writeBool(node->value);
+    }
+
+    void visit(SInt *node) {
+        writer.writeSInt(node->value);
+    }
+
+    void visit(UInt *node) {
+        writer.writeUInt(node->value);
+    }
+
+    void visit(Float *node) {
+        writer.writeFloat(node->value);
+    }
+
+    void visit(String *node) {
+        writer.writeString(node->value);
+    }
+
+    void visit(Enum *node) {
+        writer.writeEnum(node->sig);
+    }
+
+    void visit(Bitmask *node) {
+        writer.writeBitmask(node->sig, node->value);
+    }
+
+    void visit(Struct *node) {
+        writer.beginStruct(node->sig);
+        for (unsigned i = 0; i < node->sig->num_members; ++i) {
+            _visit(node->members[i]);
+        }
+        writer.endStruct();
+    }
+
+    void visit(Array *node) {
+        writer.beginArray(node->values.size());
+        for (std::vector<Value *>::iterator it = node->values.begin(); it != node->values.end(); ++it) {
+            _visit(*it);
+        }
+        writer.endArray();
+    }
+
+    void visit(Blob *node) {
+        writer.writeBlob(node->buf, node->size);
+    }
+
+    void visit(Pointer *node) {
+        writer.writeOpaque((const void *) (size_t) node->value);
+    }
+
+    void visit(Call *call) {
+        unsigned call_no = writer.beginEnter(call->sig);
+        for (unsigned i = 0; i < call->args.size(); ++i) {
+            if (call->args[i]) {
+                writer.beginArg(i);
+                _visit(call->args[i]);
+                writer.endArg();
+            }
+        }
+        writer.endEnter();
+        writer.beginLeave(call_no);
+        if (call->ret) {
+            writer.beginReturn();
+            _visit(call->ret);
+            writer.endReturn();
+        }
+        writer.endLeave();
+    }
+};
+
+
+void Writer::writeCall(Call *call) {
+    ModelWriter visitor(*this);
+    visitor.visit(call);
+}
+
+
+} /* namespace Trace */
+