#ifndef TOOLS_GN_TRACE_H_
#define TOOLS_GN_TRACE_H_
#include <string>
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
class Label;
class TraceItem {
public:
enum Type {
TRACE_FILE_LOAD,
TRACE_FILE_PARSE,
TRACE_FILE_EXECUTE,
TRACE_FILE_WRITE,
TRACE_SCRIPT_EXECUTE,
TRACE_DEFINE_TARGET
};
TraceItem(Type type,
const std::string& name,
base::PlatformThreadId thread_id);
~TraceItem();
Type type() const { return type_; }
const std::string& name() const { return name_; }
base::PlatformThreadId thread_id() const { return thread_id_; }
base::TimeTicks begin() const { return begin_; }
void set_begin(base::TimeTicks b) { begin_ = b; }
base::TimeTicks end() const { return end_; }
void set_end(base::TimeTicks e) { end_ = e; }
base::TimeDelta delta() const { return end_ - begin_; }
const std::string& toolchain() const { return toolchain_; }
void set_toolchain(const std::string& t) { toolchain_ = t; }
const std::string& cmdline() const { return cmdline_; }
void set_cmdline(const std::string& c) { cmdline_ = c; }
private:
Type type_;
std::string name_;
base::PlatformThreadId thread_id_;
base::TimeTicks begin_;
base::TimeTicks end_;
std::string toolchain_;
std::string cmdline_;
};
class ScopedTrace {
public:
ScopedTrace(TraceItem::Type t, const std::string& name);
ScopedTrace(TraceItem::Type t, const Label& label);
~ScopedTrace();
void SetToolchain(const Label& label);
void SetCommandLine(const base::CommandLine& cmdline);
void Done();
private:
TraceItem* item_;
bool done_;
};
void EnableTracing();
void AddTrace(TraceItem* item);
std::string SummarizeTraces();
void SaveTraces(const base::FilePath& file_name);
#endif