• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
main(int argc,char * argv[])22 int main(int argc, char* argv[]) {
23   if (argc < 2) {
24     printf("usage: %s <file1> <file2...>\n", argv[0]);
25     return 1;
26   }
27 
28   vector<float> times;
29   for (int i = 1; i < argc; ++i) {
30     const char* filename = argv[i];
31 
32     for (int limit = 1 << 10; limit < (1<<20); limit *= 2) {
33       int64_t start = GetTimeMillis();
34       for (int rep = 0; rep < limit; ++rep) {
35         string buf;
36         string err;
37         if (ReadFile(filename, &buf, &err) < 0) {
38           printf("%s: %s\n", filename, err.c_str());
39           return 1;
40         }
41 
42         DepfileParser parser;
43         if (!parser.Parse(&buf, &err)) {
44           printf("%s: %s\n", filename, err.c_str());
45           return 1;
46         }
47       }
48       int64_t end = GetTimeMillis();
49 
50       if (end - start > 100) {
51         int delta = (int)(end - start);
52         float time = delta*1000 / (float)limit;
53         printf("%s: %.1fus\n", filename, time);
54         times.push_back(time);
55         break;
56       }
57     }
58   }
59 
60   if (!times.empty()) {
61     float min = times[0];
62     float max = times[0];
63     float total = 0;
64     for (size_t i = 0; i < times.size(); ++i) {
65       total += times[i];
66       if (times[i] < min)
67         min = times[i];
68       else if (times[i] > max)
69         max = times[i];
70     }
71 
72     printf("min %.1fus  max %.1fus  avg %.1fus\n",
73            min, max, total / times.size());
74   }
75 
76   return 0;
77 }
78