#include <string.h>
#include "os.hpp"
+#include "os_thread.hpp"
+#include "os_string.hpp"
#include "trace_file.hpp"
#include "trace_writer.hpp"
#include "trace_format.hpp"
void
LocalWriter::open(void) {
+ os::String szFileName;
- 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 {
- os::Path szProcessName = os::getProcessName();
- os::Path szCurrentDir = os::getCurrentDir();
+ if (!lpFileName) {
+ static unsigned dwCounter = 0;
+
+ os::String process = os::getProcessName();
+#ifdef _WIN32
+ process.trimExtension();
+#endif
+ process.trimDirectory();
+
+ os::String prefix = os::getCurrentDir();
+ prefix.join(process);
for (;;) {
FILE *file;
if (dwCounter)
- snprintf(szFileName, PATH_MAX, "%s%c%s.%u.%s", szCurrentDir.str(), PATH_SEP, szProcessName.str(), dwCounter, szExtension);
+ szFileName = os::String::format("%s.%u.trace", prefix.str(), dwCounter);
else
- snprintf(szFileName, PATH_MAX, "%s%c%s.%s", szCurrentDir.str(), PATH_SEP, szProcessName.str(), szExtension);
+ szFileName = os::String::format("%s.trace", prefix.str());
- file = fopen(szFileName, "rb");
+ lpFileName = szFileName;
+ file = fopen(lpFileName, "rb");
if (file == NULL)
break;
}
}
- os::log("apitrace: tracing to %s\n", szFileName);
+ os::log("apitrace: tracing to %s\n", lpFileName);
- Writer::open(szFileName);
+ if (!Writer::open(lpFileName)) {
+ os::log("apitrace: error: failed to open %s\n", lpFileName);
+ os::abort();
+ }
#if 0
// For debugging the exception handler
open();
}
- return Writer::beginEnter(sig);
+ os::thread::id id = os::this_thread::get_id();
+
+ return Writer::beginEnter(sig, static_cast<unsigned>(id));
}
void LocalWriter::endEnter(void) {