blob: f9ce8f0d43fadde542c79c8acefaf617fd5b2f03 [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>
Eric Carusocc7106c2017-04-27 14:22:42 -070015#include <brillo/errors/error.h>
16#include <dbus/file_descriptor.h>
Ahmad Sharifae1714d2013-01-17 11:29:37 -080017
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,
Eric Carusocc7106c2017-04-27 14:22:42 -070031 brillo::ErrorPtr* 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.
Eric Caruso8fe49c72017-04-25 10:43:59 -070037 bool GetPerfOutputFd(const uint32_t& duration_secs,
David Sharp16d35652016-04-05 17:20:08 -070038 const std::vector<std::string>& perf_args,
Eric Carusocc7106c2017-04-27 14:22:42 -070039 const dbus::FileDescriptor& stdout_fd,
40 brillo::ErrorPtr* error);
David Sharp16d35652016-04-05 17:20:08 -070041
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,
Simon Queac5f9cf2015-06-20 13:50:22 -070048 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_