1695b41eeSopenharmony_ci// Copyright 2011 Google Inc. All Rights Reserved. 2695b41eeSopenharmony_ci// 3695b41eeSopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4695b41eeSopenharmony_ci// you may not use this file except in compliance with the License. 5695b41eeSopenharmony_ci// You may obtain a copy of the License at 6695b41eeSopenharmony_ci// 7695b41eeSopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8695b41eeSopenharmony_ci// 9695b41eeSopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10695b41eeSopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS, 11695b41eeSopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12695b41eeSopenharmony_ci// See the License for the specific language governing permissions and 13695b41eeSopenharmony_ci// limitations under the License. 14695b41eeSopenharmony_ci 15695b41eeSopenharmony_ci#include <stdio.h> 16695b41eeSopenharmony_ci#include <stdlib.h> 17695b41eeSopenharmony_ci 18695b41eeSopenharmony_ci#include "depfile_parser.h" 19695b41eeSopenharmony_ci#include "util.h" 20695b41eeSopenharmony_ci#include "metrics.h" 21695b41eeSopenharmony_ci 22695b41eeSopenharmony_ciusing namespace std; 23695b41eeSopenharmony_ci 24695b41eeSopenharmony_ciint main(int argc, char* argv[]) { 25695b41eeSopenharmony_ci if (argc < 2) { 26695b41eeSopenharmony_ci printf("usage: %s <file1> <file2...>\n", argv[0]); 27695b41eeSopenharmony_ci return 1; 28695b41eeSopenharmony_ci } 29695b41eeSopenharmony_ci 30695b41eeSopenharmony_ci vector<float> times; 31695b41eeSopenharmony_ci for (int i = 1; i < argc; ++i) { 32695b41eeSopenharmony_ci const char* filename = argv[i]; 33695b41eeSopenharmony_ci 34695b41eeSopenharmony_ci for (int limit = 1 << 10; limit < (1<<20); limit *= 2) { 35695b41eeSopenharmony_ci int64_t start = GetTimeMillis(); 36695b41eeSopenharmony_ci for (int rep = 0; rep < limit; ++rep) { 37695b41eeSopenharmony_ci string buf; 38695b41eeSopenharmony_ci string err; 39695b41eeSopenharmony_ci if (ReadFile(filename, &buf, &err) < 0) { 40695b41eeSopenharmony_ci printf("%s: %s\n", filename, err.c_str()); 41695b41eeSopenharmony_ci return 1; 42695b41eeSopenharmony_ci } 43695b41eeSopenharmony_ci 44695b41eeSopenharmony_ci DepfileParser parser; 45695b41eeSopenharmony_ci if (!parser.Parse(&buf, &err)) { 46695b41eeSopenharmony_ci printf("%s: %s\n", filename, err.c_str()); 47695b41eeSopenharmony_ci return 1; 48695b41eeSopenharmony_ci } 49695b41eeSopenharmony_ci } 50695b41eeSopenharmony_ci int64_t end = GetTimeMillis(); 51695b41eeSopenharmony_ci 52695b41eeSopenharmony_ci if (end - start > 100) { 53695b41eeSopenharmony_ci int delta = (int)(end - start); 54695b41eeSopenharmony_ci float time = delta*1000 / (float)limit; 55695b41eeSopenharmony_ci printf("%s: %.1fus\n", filename, time); 56695b41eeSopenharmony_ci times.push_back(time); 57695b41eeSopenharmony_ci break; 58695b41eeSopenharmony_ci } 59695b41eeSopenharmony_ci } 60695b41eeSopenharmony_ci } 61695b41eeSopenharmony_ci 62695b41eeSopenharmony_ci if (!times.empty()) { 63695b41eeSopenharmony_ci float min = times[0]; 64695b41eeSopenharmony_ci float max = times[0]; 65695b41eeSopenharmony_ci float total = 0; 66695b41eeSopenharmony_ci for (size_t i = 0; i < times.size(); ++i) { 67695b41eeSopenharmony_ci total += times[i]; 68695b41eeSopenharmony_ci if (times[i] < min) 69695b41eeSopenharmony_ci min = times[i]; 70695b41eeSopenharmony_ci else if (times[i] > max) 71695b41eeSopenharmony_ci max = times[i]; 72695b41eeSopenharmony_ci } 73695b41eeSopenharmony_ci 74695b41eeSopenharmony_ci printf("min %.1fus max %.1fus avg %.1fus\n", 75695b41eeSopenharmony_ci min, max, total / times.size()); 76695b41eeSopenharmony_ci } 77695b41eeSopenharmony_ci 78695b41eeSopenharmony_ci return 0; 79695b41eeSopenharmony_ci} 80