lin
2025-08-01 633231e833e21d5b8b1c00cb15aedb62b3b78e8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
 
#include <sstream>
#include <string>
 
#include "base/logging.h"
 
#include "compat/string.h"
#include "file_utils.h"
#include "perf_recorder.h"
 
namespace {
 
const char kDefaultOutputFile[] = "/dev/stdout";
 
int StringToInt(const string& s) {
  int r;
  std::stringstream ss;
  ss << s;
  ss >> r;
  return r;
}
 
bool ParseArguments(int argc, char* argv[], std::vector<string>* perf_args,
                    int* duration) {
  if (argc < 3) {
    LOG(ERROR) << "Invalid command line.";
    LOG(ERROR) << "Usage: " << argv[0] << " <duration in seconds>"
               << " <path to perf>"
               << " <perf arguments>";
    return false;
  }
 
  *duration = StringToInt(argv[1]);
 
  for (int i = 2; i < argc; i++) {
    perf_args->emplace_back(argv[i]);
  }
  return true;
}
 
}  // namespace
 
// Usage is:
// <exe> <duration in seconds> <perf command line>
int main(int argc, char* argv[]) {
  std::vector<string> perf_args;
  int perf_duration;
 
  if (!ParseArguments(argc, argv, &perf_args, &perf_duration)) return 1;
 
  quipper::PerfRecorder perf_recorder;
  string output_string;
  if (!perf_recorder.RunCommandAndGetSerializedOutput(perf_args, perf_duration,
                                                      &output_string)) {
    return 1;
  }
 
  if (!quipper::BufferToFile(kDefaultOutputFile, output_string)) return 1;
 
  return 0;
}