|
Ninja
|
Store a log of every command ran for every build. More...
#include <build_log.h>
Classes | |
| struct | LogEntry |
Public Types | |
| typedef ExternalStringHashMap< std::unique_ptr< LogEntry > >::Type | Entries |
Public Member Functions | |
| BuildLog () | |
| void | Close () |
| const Entries & | entries () const |
| LoadStatus | Load (const std::string &path, std::string *err) |
| Load the on-disk log. More... | |
| LogEntry * | LookupByOutput (const std::string &path) |
| Lookup a previously-run command by its output path. More... | |
| bool | OpenForWrite (const std::string &path, const BuildLogUser &user, std::string *err) |
| Prepares writing to the log file without actually opening it - that will happen when/if it's needed. More... | |
| bool | Recompact (const std::string &path, const BuildLogUser &user, std::string *err) |
| Rewrite the known log entries, throwing away old data. More... | |
| bool | RecordCommand (Edge *edge, int start_time, int end_time, TimeStamp mtime=0) |
| bool | Restat (StringPiece path, const DiskInterface &disk_interface, int output_count, char **outputs, std::string *err) |
| Restat all outputs in the log. More... | |
| bool | WriteEntry (FILE *f, const LogEntry &entry) |
| Serialize an entry into a log file. More... | |
| ~BuildLog () | |
Private Member Functions | |
| bool | OpenForWriteIfNeeded () |
| Should be called before using log_file_. More... | |
Private Attributes | |
| Entries | entries_ |
| FILE * | log_file_ = nullptr |
| std::string | log_file_path_ |
| bool | needs_recompaction_ = false |
Store a log of every command ran for every build.
It has a few uses:
1) (hashes of) command lines for existing output files, so we know when we need to rebuild due to the command changing 2) timing information, perhaps for generating reports 3) restat information
Definition at line 45 of file build_log.h.
| typedef ExternalStringHashMap<std::unique_ptr<LogEntry> >::Type BuildLog::Entries |
Definition at line 95 of file build_log.h.
|
default |
| BuildLog::~BuildLog | ( | ) |
Definition at line 73 of file build_log.cc.
References Close().
| void BuildLog::Close | ( | ) |
Definition at line 125 of file build_log.cc.
References log_file_, and OpenForWriteIfNeeded().
Referenced by Builder::Build(), Recompact(), Restat(), and ~BuildLog().
|
inline |
Definition at line 96 of file build_log.h.
References entries_.
| LoadStatus BuildLog::Load | ( | const std::string & | path, |
| std::string * | err | ||
| ) |
Load the on-disk log.
Definition at line 208 of file build_log.cc.
References BuildLog::LogEntry::command_hash, BuildLog::LogEntry::end_time, entries_, kCurrentVersion, kFileSignature, LOAD_ERROR, LOAD_NOT_FOUND, LOAD_SUCCESS, METRIC_RECORD, BuildLog::LogEntry::mtime, needs_recompaction_, BuildLog::LogEntry::output, platformAwareUnlink(), LineReader::ReadLine(), and BuildLog::LogEntry::start_time.
Referenced by main(), BuildTest::RebuildTarget(), and TEST_F().
| BuildLog::LogEntry * BuildLog::LookupByOutput | ( | const std::string & | path | ) |
Lookup a previously-run command by its output path.
Definition at line 327 of file build_log.cc.
References entries_.
Referenced by TEST_F().
| bool BuildLog::OpenForWrite | ( | const std::string & | path, |
| const BuildLogUser & | user, | ||
| std::string * | err | ||
| ) |
Prepares writing to the log file without actually opening it - that will happen when/if it's needed.
Definition at line 77 of file build_log.cc.
References log_file_, log_file_path_, needs_recompaction_, and Recompact().
Referenced by BuildTest::RebuildTarget(), TEST_F(), and WriteTestData().
|
private |
Should be called before using log_file_.
When false is returned, errno will be set.
Definition at line 132 of file build_log.cc.
References kCurrentVersion, kFileSignature, log_file_, log_file_path_, and SetCloseOnExec().
Referenced by Close(), and RecordCommand().
| bool BuildLog::Recompact | ( | const std::string & | path, |
| const BuildLogUser & | user, | ||
| std::string * | err | ||
| ) |
Rewrite the known log entries, throwing away old data.
Definition at line 340 of file build_log.cc.
References Close(), entries_, BuildLogUser::IsPathDead(), kCurrentVersion, kFileSignature, METRIC_RECORD, platformAwareUnlink(), and WriteEntry().
Referenced by OpenForWrite().
Definition at line 90 of file build_log.cc.
References BuildLog::LogEntry::command_hash, BuildLog::LogEntry::end_time, entries_, Edge::EvaluateCommand(), BuildLog::LogEntry::HashCommand(), log_file_, BuildLog::LogEntry::mtime, OpenForWriteIfNeeded(), BuildLog::LogEntry::output, Edge::outputs_, BuildLog::LogEntry::start_time, and WriteEntry().
Referenced by Builder::FinishCommand(), and WriteTestData().
| bool BuildLog::Restat | ( | StringPiece | path, |
| const DiskInterface & | disk_interface, | ||
| int | output_count, | ||
| char ** | outputs, | ||
| std::string * | err | ||
| ) |
Restat all outputs in the log.
Definition at line 389 of file build_log.cc.
References StringPiece::AsString(), Close(), entries_, kCurrentVersion, kFileSignature, METRIC_RECORD, platformAwareUnlink(), DiskInterface::Stat(), StringPiece::str_, and WriteEntry().
| bool BuildLog::WriteEntry | ( | FILE * | f, |
| const LogEntry & | entry | ||
| ) |
Serialize an entry into a log file.
Definition at line 334 of file build_log.cc.
References BuildLog::LogEntry::command_hash, BuildLog::LogEntry::end_time, BuildLog::LogEntry::mtime, BuildLog::LogEntry::output, PRId64, PRIx64, and BuildLog::LogEntry::start_time.
Referenced by Recompact(), RecordCommand(), and Restat().
|
private |
Definition at line 103 of file build_log.h.
Referenced by entries(), Load(), LookupByOutput(), Recompact(), RecordCommand(), and Restat().
|
private |
Definition at line 104 of file build_log.h.
Referenced by Close(), OpenForWrite(), OpenForWriteIfNeeded(), and RecordCommand().
|
private |
Definition at line 105 of file build_log.h.
Referenced by OpenForWrite(), and OpenForWriteIfNeeded().
|
private |
Definition at line 106 of file build_log.h.
Referenced by Load(), and OpenForWrite().