Ahmad Sharif | ae1714d | 2013-01-17 11:29:37 -0800 | [diff] [blame] | 1 | // 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 Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 5 | #ifndef DEBUGD_SRC_PERF_TOOL_H_ |
| 6 | #define DEBUGD_SRC_PERF_TOOL_H_ |
Ahmad Sharif | ae1714d | 2013-01-17 11:29:37 -0800 | [diff] [blame] | 7 | |
Ben Chan | 49d264c | 2014-08-06 17:38:16 -0700 | [diff] [blame] | 8 | #include <stdint.h> |
David Sharp | 0001e25 | 2015-08-27 15:59:31 -0700 | [diff] [blame] | 9 | #include <sys/utsname.h> |
Ben Chan | 49d264c | 2014-08-06 17:38:16 -0700 | [diff] [blame] | 10 | |
Ahmad Sharif | ae1714d | 2013-01-17 11:29:37 -0800 | [diff] [blame] | 11 | #include <string> |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 12 | #include <vector> |
Ahmad Sharif | ae1714d | 2013-01-17 11:29:37 -0800 | [diff] [blame] | 13 | |
Ben Chan | 657bed8 | 2014-09-02 20:40:51 -0700 | [diff] [blame] | 14 | #include <base/macros.h> |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 15 | #include <brillo/errors/error.h> |
| 16 | #include <dbus/file_descriptor.h> |
Ahmad Sharif | ae1714d | 2013-01-17 11:29:37 -0800 | [diff] [blame] | 17 | |
| 18 | namespace debugd { |
| 19 | |
| 20 | class PerfTool { |
| 21 | public: |
| 22 | PerfTool(); |
Ben Chan | 78f8953 | 2014-08-29 09:35:09 -0700 | [diff] [blame] | 23 | ~PerfTool() = default; |
Ahmad Sharif | ae1714d | 2013-01-17 11:29:37 -0800 | [diff] [blame] | 24 | |
David Sharp | 4324e9a | 2015-08-05 14:23:41 -0700 | [diff] [blame] | 25 | // 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 Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 31 | brillo::ErrorPtr* error); |
Simon Que | 795327b | 2015-03-16 17:42:35 -0700 | [diff] [blame] | 32 | |
David Sharp | 16d3565 | 2016-04-05 17:20:08 -0700 | [diff] [blame] | 33 | // 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 Caruso | 8fe49c7 | 2017-04-25 10:43:59 -0700 | [diff] [blame] | 37 | bool GetPerfOutputFd(const uint32_t& duration_secs, |
David Sharp | 16d3565 | 2016-04-05 17:20:08 -0700 | [diff] [blame] | 38 | const std::vector<std::string>& perf_args, |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 39 | const dbus::FileDescriptor& stdout_fd, |
| 40 | brillo::ErrorPtr* error); |
David Sharp | 16d3565 | 2016-04-05 17:20:08 -0700 | [diff] [blame] | 41 | |
Ahmad Sharif | ae1714d | 2013-01-17 11:29:37 -0800 | [diff] [blame] | 42 | private: |
Ahmad Sharif | f5597f6 | 2013-04-25 12:25:41 -0700 | [diff] [blame] | 43 | // Helper function that runs perf for a given |duration_secs| returning the |
Simon Que | ac5f9cf | 2015-06-20 13:50:22 -0700 | [diff] [blame] | 44 | // 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 Que | ac5f9cf | 2015-06-20 13:50:22 -0700 | [diff] [blame] | 48 | std::string* data_string); |
Ahmad Sharif | f5597f6 | 2013-04-25 12:25:41 -0700 | [diff] [blame] | 49 | |
Ahmad Sharif | ae1714d | 2013-01-17 11:29:37 -0800 | [diff] [blame] | 50 | DISALLOW_COPY_AND_ASSIGN(PerfTool); |
| 51 | }; |
| 52 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 53 | } // namespace debugd |
Ahmad Sharif | ae1714d | 2013-01-17 11:29:37 -0800 | [diff] [blame] | 54 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 55 | #endif // DEBUGD_SRC_PERF_TOOL_H_ |