blob: 24fa06f042e7e5d2f694028458bbe0c1ae416d8a [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.
Eric Caruso56eacb22017-08-04 11:00:37 -070027 bool GetPerfOutput(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 int32_t* status,
32 brillo::ErrorPtr* error);
Simon Que795327b2015-03-16 17:42:35 -070033
David Sharp16d35652016-04-05 17:20:08 -070034 // Runs the perf tool with the request command for |duration_secs| seconds
35 // and returns either a perf_data or perf_stat protobuf in serialized form
36 // over the passed stdout_fd file descriptor, or nothing if there was an
37 // error.
Eric Caruso56eacb22017-08-04 11:00:37 -070038 bool GetPerfOutputFd(uint32_t duration_secs,
David Sharp16d35652016-04-05 17:20:08 -070039 const std::vector<std::string>& perf_args,
Eric Carusocc7106c2017-04-27 14:22:42 -070040 const dbus::FileDescriptor& stdout_fd,
41 brillo::ErrorPtr* error);
David Sharp16d35652016-04-05 17:20:08 -070042
Ahmad Sharifae1714d2013-01-17 11:29:37 -080043 private:
Ahmad Sharifae1714d2013-01-17 11:29:37 -080044 DISALLOW_COPY_AND_ASSIGN(PerfTool);
45};
46
Ben Chana0011d82014-05-13 00:19:29 -070047} // namespace debugd
Ahmad Sharifae1714d2013-01-17 11:29:37 -080048
Alex Vakulenko262be3f2014-07-30 15:25:50 -070049#endif // DEBUGD_SRC_PERF_TOOL_H_