/**************************************************************************
*
- * Copyright 2007-2010 VMware, Inc.
+ * Copyright 2007-2013 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
**************************************************************************/
/*
- * Trace writing functions.
+ * Trace writing functions, used to trace calls in the current process.
*/
#ifndef _TRACE_WRITER_LOCAL_HPP_
#define _TRACE_WRITER_LOCAL_HPP_
+#include <stdint.h>
+
#include "os_thread.hpp"
+#include "os_process.hpp"
#include "trace_writer.hpp"
class LocalWriter : public Writer {
protected:
/**
- * We need a recursive mutex so that it doesn't dead lock when a segfault happens when the mutex is held.
+ * This mutex guarantees that only one thread writes to the trace file
+ * at one given instance.
+ *
+ * We need a recursive mutex so that we dont't dead lock in the event
+ * of a segfault happens while the mutex is held.
+ *
+ * To prevent deadlocks, the call for the real function (the one being
+ * traced) should not be done with the mutex held. That is, it should
+ * be done outside the beginEnter/endEnter and beginLeave/endLeave
+ * pairs. Preferably between these two pairs.
*/
os::recursive_mutex mutex;
int acquired;
+ /**
+ * ID of the processed that opened the trace file.
+ */
+ os::ProcessId pid;
+
+ void checkProcessId();
+
public:
/**
- * Should never called directly -- use localWriter singleton below instead.
+ * Should never called directly -- use localWriter singleton below
+ * instead.
*/
LocalWriter();
~LocalWriter();
void open(void);
- unsigned beginEnter(const FunctionSig *sig);
+ /**
+ * It will acquire the mutex.
+ */
+ unsigned beginEnter(const FunctionSig *sig, bool fake = false);
+
+ /**
+ * It will release the mutex.
+ */
void endEnter(void);
+ /**
+ * It will acquire the mutex.
+ */
void beginLeave(unsigned call);
+
+ /**
+ * It will release the mutex.
+ */
void endLeave(void);
void flush(void);