blob: fe73ce556bcc3eb6373e5be29d5ace6a5f2b8f47 [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
Simon Que795327b2015-03-16 17:42:35 -070011#include <memory>
Ahmad Sharifae1714d2013-01-17 11:29:37 -080012#include <string>
Ben Chana0011d82014-05-13 00:19:29 -070013#include <vector>
Ahmad Sharifae1714d2013-01-17 11:29:37 -080014
Ben Chan657bed82014-09-02 20:40:51 -070015#include <base/macros.h>
Ahmad Sharifae1714d2013-01-17 11:29:37 -080016#include <dbus-c++/dbus.h>
17
18namespace debugd {
19
20class PerfTool {
21 public:
22 PerfTool();
Ben Chan78f89532014-08-29 09:35:09 -070023 ~PerfTool() = default;
Ahmad Sharifae1714d2013-01-17 11:29:37 -080024
David Sharp4324e9a2015-08-05 14:23:41 -070025 // Runs the perf tool with the request command for |duration_secs| seconds
26 // and returns either a perf_data or perf_stat protobuf in serialized form.
27 int GetPerfOutput(const uint32_t& duration_secs,
28 const std::vector<std::string>& perf_args,
29 std::vector<uint8_t>* perf_data,
30 std::vector<uint8_t>* perf_stat,
31 DBus::Error* error);
Simon Que795327b2015-03-16 17:42:35 -070032
David Sharp16d35652016-04-05 17:20:08 -070033 // Runs the perf tool with the request command for |duration_secs| seconds
34 // and returns either a perf_data or perf_stat protobuf in serialized form
35 // over the passed stdout_fd file descriptor, or nothing if there was an
36 // error.
37 void GetPerfOutputFd(const uint32_t& duration_secs,
38 const std::vector<std::string>& perf_args,
39 const DBus::FileDescriptor& stdout_fd,
40 DBus::Error* error);
41
Ahmad Sharifae1714d2013-01-17 11:29:37 -080042 private:
Ahmad Shariff5597f62013-04-25 12:25:41 -070043 // Helper function that runs perf for a given |duration_secs| returning the
Simon Queac5f9cf2015-06-20 13:50:22 -070044 // collected data in |data_string|. Return value is the status from running
45 // perf.
46 int GetPerfOutputHelper(const uint32_t& duration_secs,
47 const std::vector<std::string>& perf_args,
48 DBus::Error* error,
49 std::string* data_string);
Ahmad Shariff5597f62013-04-25 12:25:41 -070050
Ahmad Sharifae1714d2013-01-17 11:29:37 -080051 DISALLOW_COPY_AND_ASSIGN(PerfTool);
52};
53
Ben Chana0011d82014-05-13 00:19:29 -070054} // namespace debugd
Ahmad Sharifae1714d2013-01-17 11:29:37 -080055
Alex Vakulenko262be3f2014-07-30 15:25:50 -070056#endif // DEBUGD_SRC_PERF_TOOL_H_