LocalWriter::~LocalWriter()
{
os::resetExceptionCallback();
+ checkProcessId();
}
void
static OS_THREAD_SPECIFIC_PTR(void)
thread_num;
+void LocalWriter::checkProcessId(void) {
+ if (m_file->isOpened() &&
+ os::getCurrentProcessId() != pid) {
+ // We are a forked child process that inherited the trace file, so
+ // create a new file. We can't call any method of the current
+ // file, as it may cause it to flush and corrupt the parent's
+ // trace, so we effectively leak the old file object.
+ m_file = File::createSnappy();
+ // Don't want to open the same file again
+ os::unsetEnvironment("TRACE_FILE");
+ open();
+ }
+}
+
unsigned LocalWriter::beginEnter(const FunctionSig *sig) {
mutex.lock();
++acquired;
+ checkProcessId();
if (!m_file->isOpened()) {
open();
- } else {
- if (os::getCurrentProcessId() != pid) {
- // We are a forked child process that inherited the trace file, so
- // create a new file. We can't call any method of the current
- // file, as it may cause it to flush and corrupt the parent's
- // trace, so we effectively leak the old file object.
- m_file = File::createSnappy();
- // Don't want to open the same file again
- os::unsetEnvironment("TRACE_FILE");
- open();
- }
}
// Although thread_num is a void *, we actually use it as a uintptr_t
}
void LocalWriter::flush(void) {
- if (os::getCurrentProcessId() != pid) {
- os::log("apitrace: ignoring exception in child process\n");
- return;
- }
-
/*
* Do nothing if the mutex is already acquired (e.g., if a segfault happen
* while writing the file) as state could be inconsistent, therefore yield
} else {
++acquired;
if (m_file->isOpened()) {
- os::log("apitrace: flushing trace due to an exception\n");
- m_file->flush();
+ if (os::getCurrentProcessId() != pid) {
+ os::log("apitrace: ignoring exception in child process\n");
+ } else {
+ os::log("apitrace: flushing trace due to an exception\n");
+ m_file->flush();
+ }
}
--acquired;
}