blob: 03ee71ec744100985678a3c98c3d813756ff7c6d [file] [log] [blame]
Ahmad Sharifae1714d2013-01-17 11:29:37 -08001// 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
Alex Vakulenko262be3f2014-07-30 15:25:50 -07005#ifndef DEBUGD_SRC_PERF_TOOL_H_
6#define DEBUGD_SRC_PERF_TOOL_H_
Ahmad Sharifae1714d2013-01-17 11:29:37 -08007
Ben Chan49d264c2014-08-06 17:38:16 -07008#include <stdint.h>
David Sharp0001e252015-08-27 15:59:31 -07009#include <sys/utsname.h>
Ben Chan49d264c2014-08-06 17:38:16 -070010
Ahmad Sharifae1714d2013-01-17 11:29:37 -080011#include <string>
Ben Chana0011d82014-05-13 00:19:29 -070012#include <vector>
Ahmad Sharifae1714d2013-01-17 11:29:37 -080013
Ben Chan657bed82014-09-02 20:40:51 -070014#include <base/macros.h>
Ahmad Sharifae1714d2013-01-17 11:29:37 -080015#include <dbus-c++/dbus.h>
16
17namespace debugd {
18
19class PerfTool {
20 public:
21 PerfTool();
Ben Chan78f89532014-08-29 09:35:09 -070022 ~PerfTool() = default;
Ahmad Sharifae1714d2013-01-17 11:29:37 -080023
David Sharp4324e9a2015-08-05 14:23:41 -070024 // Runs the perf tool with the request command for |duration_secs| seconds
25 // and returns either a perf_data or perf_stat protobuf in serialized form.
26 int GetPerfOutput(const uint32_t& duration_secs,
27 const std::vector<std::string>& perf_args,
28 std::vector<uint8_t>* perf_data,
29 std::vector<uint8_t>* perf_stat,
30 DBus::Error* error);
Simon Que795327b2015-03-16 17:42:35 -070031
David Sharp16d35652016-04-05 17:20:08 -070032 // Runs the perf tool with the request command for |duration_secs| seconds
33 // and returns either a perf_data or perf_stat protobuf in serialized form
34 // over the passed stdout_fd file descriptor, or nothing if there was an
35 // error.
Eric Caruso8fe49c72017-04-25 10:43:59 -070036 bool GetPerfOutputFd(const uint32_t& duration_secs,
David Sharp16d35652016-04-05 17:20:08 -070037 const std::vector<std::string>& perf_args,
38 const DBus::FileDescriptor& stdout_fd,
39 DBus::Error* error);
40
Ahmad Sharifae1714d2013-01-17 11:29:37 -080041 private:
Ahmad Shariff5597f62013-04-25 12:25:41 -070042 // Helper function that runs perf for a given |duration_secs| returning the
Simon Queac5f9cf2015-06-20 13:50:22 -070043 // collected data in |data_string|. Return value is the status from running
44 // perf.
45 int GetPerfOutputHelper(const uint32_t& duration_secs,
46 const std::vector<std::string>& perf_args,
47 DBus::Error* error,
48 std::string* data_string);
Ahmad Shariff5597f62013-04-25 12:25:41 -070049
Ahmad Sharifae1714d2013-01-17 11:29:37 -080050 DISALLOW_COPY_AND_ASSIGN(PerfTool);
51};
52
Ben Chana0011d82014-05-13 00:19:29 -070053} // namespace debugd
Ahmad Sharifae1714d2013-01-17 11:29:37 -080054
Alex Vakulenko262be3f2014-07-30 15:25:50 -070055#endif // DEBUGD_SRC_PERF_TOOL_H_