blob: 2d287f2f3d327fcb42dfb2f14ff0c7ebef39ace8 [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
Ahmad Sharifae1714d2013-01-17 11:29:37 -080033 private:
Ahmad Shariff5597f62013-04-25 12:25:41 -070034 // Helper function that runs perf for a given |duration_secs| returning the
Simon Queac5f9cf2015-06-20 13:50:22 -070035 // collected data in |data_string|. Return value is the status from running
36 // perf.
37 int GetPerfOutputHelper(const uint32_t& duration_secs,
38 const std::vector<std::string>& perf_args,
39 DBus::Error* error,
40 std::string* data_string);
Ahmad Shariff5597f62013-04-25 12:25:41 -070041
Ahmad Sharifae1714d2013-01-17 11:29:37 -080042 DISALLOW_COPY_AND_ASSIGN(PerfTool);
43};
44
Ben Chana0011d82014-05-13 00:19:29 -070045} // namespace debugd
Ahmad Sharifae1714d2013-01-17 11:29:37 -080046
Alex Vakulenko262be3f2014-07-30 15:25:50 -070047#endif // DEBUGD_SRC_PERF_TOOL_H_