1// Copyright 2011 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include <stdio.h>
16#include <stdlib.h>
17
18#include "depfile_parser.h"
19#include "util.h"
20#include "metrics.h"
21
22using namespace std;
23
24int main(int argc, char* argv[]) {
25 if (argc < 2) {
26 printf("usage: %s <file1> <file2...>\n", argv[0]);
27 return 1;
28 }
29
30 vector<float> times;
31 for (int i = 1; i < argc; ++i) {
32 const char* filename = argv[i];
33
34 for (int limit = 1 << 10; limit < (1<<20); limit *= 2) {
35 int64_t start = GetTimeMillis();
36 for (int rep = 0; rep < limit; ++rep) {
37 string buf;
38 string err;
39 if (ReadFile(filename, &buf, &err) < 0) {
40 printf("%s: %s\n", filename, err.c_str());
41 return 1;
42 }
43
44 DepfileParser parser;
45 if (!parser.Parse(&buf, &err)) {
46 printf("%s: %s\n", filename, err.c_str());
47 return 1;
48 }
49 }
50 int64_t end = GetTimeMillis();
51
52 if (end - start > 100) {
53 int delta = (int)(end - start);
54 float time = delta*1000 / (float)limit;
55 printf("%s: %.1fus\n", filename, time);
56 times.push_back(time);
57 break;
58 }
59 }
60 }
61
62 if (!times.empty()) {
63 float min = times[0];
64 float max = times[0];
65 float total = 0;
66 for (size_t i = 0; i < times.size(); ++i) {
67 total += times[i];
68 if (times[i] < min)
69 min = times[i];
70 else if (times[i] > max)
71 max = times[i];
72 }
73
74 printf("min %.1fus max %.1fus avg %.1fus\n",
75 min, max, total / times.size());
76 }
77
78 return 0;
79}
80