40 virtual bool ReadFile(
const string& path,
string* content,
string* err) {
47 if (disk_interface.
Stat(dir +
"/build.ninja") > 0)
50 printf(
"Creating manifest data..."); fflush(stdout);
51 int err = system((
"python misc/write_fake_manifests.py " + dir).c_str());
58 RealFileReader file_reader;
61 if (!parser.
Load(
"build.ninja", &err)) {
62 fprintf(stderr,
"Failed to read test data: %s\n", err.c_str());
68 int optimization_guard = 0;
69 if (measure_command_evaluation)
70 for (
size_t i = 0; i < state.
edges_.size(); ++i)
71 optimization_guard += state.
edges_[i]->EvaluateCommand().size();
72 return optimization_guard;
75 int main(
int argc,
char* argv[]) {
76 bool measure_command_evaluation =
true;
78 while ((opt =
getopt(argc, argv, const_cast<char*>(
"fh"))) != -1) {
81 measure_command_evaluation =
false;
85 printf(
"usage: manifest_parser_perftest\n" 88 " -f only measure manifest load time, not command evaluation time\n" 94 const char kManifestDir[] =
"build/manifest_perftest";
97 fprintf(stderr,
"Failed to write test data\n");
101 if (chdir(kManifestDir) < 0)
102 Fatal(
"chdir: %s", strerror(errno));
104 const int kNumRepetitions = 5;
106 for (
int i = 0; i < kNumRepetitions; ++i) {
108 int optimization_guard =
LoadManifests(measure_command_evaluation);
110 printf(
"%dms (hash: %x)\n", delta, optimization_guard);
111 times.push_back(delta);
114 int min = *min_element(times.begin(), times.end());
115 int max = *max_element(times.begin(), times.end());
116 float total = accumulate(times.begin(), times.end(), 0.0f);
117 printf(
"min %dms max %dms avg %.1fms\n", min, max, total / times.size());
bool Load(const string &filename, string *err, Lexer *parent=NULL)
Load and parse a file.
vector< Edge * > edges_
All the edges of the graph.
int64_t GetTimeMillis()
Get the current time as relative to some epoch.
virtual TimeStamp Stat(const string &path) const
stat() a file, returning the mtime, or 0 if missing and -1 on other errors.
signed long long int64_t
A 64-bit integer type.
Implementation of DiskInterface that actually hits the disk.
int getopt(int argc, char **argv, char *optstring)
int LoadManifests(bool measure_command_evaluation)
int ReadFile(const string &path, string *contents, string *err)
Read a file to a string (in text mode: with CRLF conversion on Windows).
int main(int argc, char *argv[])
virtual bool ReadFile(const string &path, string *content, string *err)
void Fatal(const char *msg,...)
Log a fatal message and exit.
Global state (file status, loaded rules) for a single run.
bool WriteFakeManifests(const string &dir)