1 // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROMIUMOS_WIDE_PROFILING_PERF_RECORDER_H_ 6 #define CHROMIUMOS_WIDE_PROFILING_PERF_RECORDER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/macros.h" 12 13 #include "compat/string.h" 14 #include "perf_reader.h" 15 16 namespace quipper { 17 18 class PerfRecorder { 19 public: 20 PerfRecorder(); 21 22 // Mostly for testing. 23 // Security critical: No user-provided strings should be used! 24 explicit PerfRecorder(const std::vector<string>& perf_binary_command); 25 26 // Runs the perf command specified in |perf_args| for |time_sec| seconds. The 27 // output is returned as a serialized protobuf in |output_string|. The 28 // protobuf format depends on the provided perf command. 29 bool RunCommandAndGetSerializedOutput(const std::vector<string>& perf_args, 30 const double time_sec, 31 string* output_string); 32 33 // The command prefix for running perf. e.g., "perf", or "/usr/bin/perf", 34 // or perhaps {"sudo", "/usr/bin/perf"}. perf_binary_command()35 const std::vector<string>& perf_binary_command() const { 36 return perf_binary_command_; 37 } 38 39 private: 40 const std::vector<string> perf_binary_command_; 41 42 DISALLOW_COPY_AND_ASSIGN(PerfRecorder); 43 }; 44 45 } // namespace quipper 46 47 #endif // CHROMIUMOS_WIDE_PROFILING_PERF_RECORDER_H_ 48