From 52f0c2507638fb623088c9def5b2cc0bf652478e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 24 Aug 2011 16:45:40 +0100 Subject: [PATCH] Move LocalWriter into its own source file. --- CMakeLists.txt | 1 + trace_local_writer.cpp | 114 +++++++++++++++++++++++++++++++++++++++++ trace_writer.cpp | 70 ------------------------- 3 files changed, 115 insertions(+), 70 deletions(-) create mode 100644 trace_local_writer.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d7e4a28..4dfbbb7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,6 +176,7 @@ add_library (common trace_model.cpp trace_parser.cpp trace_writer.cpp + trace_local_writer.cpp trace_model_writer.cpp image.cpp image_bmp.cpp diff --git a/trace_local_writer.cpp b/trace_local_writer.cpp new file mode 100644 index 0000000..062f088 --- /dev/null +++ b/trace_local_writer.cpp @@ -0,0 +1,114 @@ +/************************************************************************** + * + * 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 +#include +#include +#include +#include + +#include + +#include "os.hpp" +#include "trace_writer.hpp" +#include "trace_format.hpp" + + +namespace Trace { + + +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); +} + +unsigned LocalWriter::beginEnter(const FunctionSig *sig) { + OS::AcquireMutex(); + + if (!g_gzFile) { + open(); + } + + return Writer::beginEnter(sig); +} + +void LocalWriter::endEnter(void) { + Writer::endEnter(); + gzflush(g_gzFile, Z_SYNC_FLUSH); + OS::ReleaseMutex(); +} + +void LocalWriter::beginLeave(unsigned call) { + OS::AcquireMutex(); + Writer::beginLeave(call); +} + +void LocalWriter::endLeave(void) { + Writer::endLeave(); + gzflush(g_gzFile, Z_SYNC_FLUSH); + OS::ReleaseMutex(); +} + + +} /* namespace Trace */ + diff --git a/trace_writer.cpp b/trace_writer.cpp index 7fcd0e6..fc47f0d 100644 --- a/trace_writer.cpp +++ b/trace_writer.cpp @@ -304,75 +304,5 @@ void Writer::writeOpaque(const void *addr) { } -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); -} - -unsigned LocalWriter::beginEnter(const FunctionSig *sig) { - OS::AcquireMutex(); - - if (!g_gzFile) { - open(); - } - - return Writer::beginEnter(sig); -} - -void LocalWriter::endEnter(void) { - Writer::endEnter(); - gzflush(g_gzFile, Z_SYNC_FLUSH); - OS::ReleaseMutex(); -} - -void LocalWriter::beginLeave(unsigned call) { - OS::AcquireMutex(); - Writer::beginLeave(call); -} - -void LocalWriter::endLeave(void) { - Writer::endLeave(); - gzflush(g_gzFile, Z_SYNC_FLUSH); - OS::ReleaseMutex(); -} - - } /* namespace Trace */ -- 2.43.0