From: Zack Rusin Date: Wed, 24 Aug 2011 03:02:10 +0000 (-0400) Subject: Merge branch 'master' into compression X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=93dfad1dc7e20d694e2c8b63515bff8ae91f3700 Merge branch 'master' into compression Conflicts: trace_writer.cpp --- 93dfad1dc7e20d694e2c8b63515bff8ae91f3700 diff --cc trace_writer.cpp index 7511d31,7fcd0e6..057e395 --- a/trace_writer.cpp +++ b/trace_writer.cpp @@@ -77,51 -79,12 +77,9 @@@ Writer::open(const char *filename) return true; } - void - Writer::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); - - open(szFileName); - } - void inline Writer::_write(const void *sBuffer, size_t dwBytesToWrite) { - if (g_gzFile == NULL) - return; - - gzwrite(g_gzFile, sBuffer, dwBytesToWrite); + m_file->write(sBuffer, dwBytesToWrite); } void inline @@@ -350,5 -303,76 +298,75 @@@ void Writer::writeOpaque(const void *ad _writeUInt((size_t)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) { ++ if (!m_file->isOpened()) { + 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); ++ m_file->flush(); + OS::ReleaseMutex(); + } + + } /* namespace Trace */