1 /*
2 * Copyright (c) 2016, Google Inc.
3 * All rights reserved.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "perf_to_profile_lib.h"
9
10 #include "base/logging.h"
11 #include "perf_data_converter.h"
12
main(int argc,char ** argv)13 int main(int argc, char** argv) {
14 string input, output;
15 bool overwriteOutput = false;
16 if (!ParseArguments(argc, const_cast<const char**>(argv), &input, &output,
17 &overwriteOutput)) {
18 PrintUsage();
19 return EXIT_FAILURE;
20 }
21
22 const auto perf_data = ReadFileToString(input);
23 const auto raw_perf_data = static_cast<const void*>(perf_data.data());
24
25 const auto profiles = perftools::RawPerfDataToProfiles(
26 raw_perf_data, perf_data.length(), {}, perftools::kNoLabels,
27 perftools::kNoOptions);
28 // With kNoOptions, all of the PID profiles should be merged into a
29 // single one.
30 if (profiles.size() != 1) {
31 LOG(FATAL) << "Expected profile vector to have one element.";
32 }
33 const auto& profile = profiles[0]->data;
34 std::ofstream outFile;
35 CreateFile(output, &outFile, overwriteOutput);
36 profile.SerializeToOstream(&outFile);
37 return EXIT_SUCCESS;
38 }
39