| Than McIntosh | 7e2f4e9 | 2015-03-05 11:05:02 -0500 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2015, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 18 | #ifndef SYSTEM_EXTRAS_PERFPROFD_PERFPROFDCORE_H_ |
| 19 | #define SYSTEM_EXTRAS_PERFPROFD_PERFPROFDCORE_H_ |
| 20 | |
| Andreas Gampe | 577e646 | 2018-01-10 20:02:20 -0800 | [diff] [blame] | 21 | #include <functional> |
| 22 | #include <memory> |
| 23 | |
| Andreas Gampe | 0c09e0e | 2018-03-13 16:04:01 -0700 | [diff] [blame] | 24 | #include "perfprofd_record-fwd.h" |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 25 | |
| Andreas Gampe | 0c09e0e | 2018-03-13 16:04:01 -0700 | [diff] [blame] | 26 | struct Config; |
| Andreas Gampe | 577e646 | 2018-01-10 20:02:20 -0800 | [diff] [blame] | 27 | |
| Andreas Gampe | f9a3561 | 2018-01-04 14:22:50 -0800 | [diff] [blame] | 28 | namespace perfprofd { |
| 29 | struct Symbolizer; |
| 30 | } |
| 31 | |
| Andreas Gampe | 04672dd | 2018-03-28 14:28:18 -0700 | [diff] [blame] | 32 | void CommonInit(uint32_t use_fixed_seed, const char* dest_dir); |
| Than McIntosh | 7e2f4e9 | 2015-03-05 11:05:02 -0500 | [diff] [blame] | 33 | |
| 34 | // |
| 35 | // This enumeration holds the results of what happened when on an |
| 36 | // attempted perf profiling run. |
| 37 | // |
| 38 | typedef enum { |
| 39 | |
| 40 | // Success |
| 41 | OK_PROFILE_COLLECTION, |
| 42 | |
| 43 | // Fork system call failed (lo mem?) |
| 44 | ERR_FORK_FAILED, |
| 45 | |
| 46 | // Perf ran but crashed or returned a bad exit status |
| 47 | ERR_PERF_RECORD_FAILED, |
| 48 | |
| 49 | // The perf.data encoding process failed somehow |
| 50 | ERR_PERF_ENCODE_FAILED, |
| 51 | |
| 52 | // We tried to open the output file perf.data.encoded but the open failed |
| 53 | ERR_OPEN_ENCODED_FILE_FAILED, |
| 54 | |
| 55 | // Error while writing perf.data.encoded |
| 56 | ERR_WRITE_ENCODED_FILE_FAILED |
| 57 | } PROFILE_RESULT; |
| 58 | |
| 59 | // |
| 60 | // Given a full path to a perf.data file specified by "data_file_path", |
| 61 | // read/summarize/encode the contents into a new file specified |
| 62 | // by "encoded_file_path". Return status indicates whether the operation |
| 63 | // was successful (either OK_PROFILE_COLLECTION or an error of some sort). |
| 64 | // |
| 65 | PROFILE_RESULT encode_to_proto(const std::string &data_file_path, |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 66 | const char *encoded_file_path, |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 67 | const Config& config, |
| Andreas Gampe | f9a3561 | 2018-01-04 14:22:50 -0800 | [diff] [blame] | 68 | unsigned cpu_utilization, |
| 69 | perfprofd::Symbolizer* symbolizer); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 70 | |
| Andreas Gampe | 0c09e0e | 2018-03-13 16:04:01 -0700 | [diff] [blame] | 71 | using HandlerFn = std::function<bool(android::perfprofd::PerfprofdRecord* proto, |
| Andreas Gampe | 577e646 | 2018-01-10 20:02:20 -0800 | [diff] [blame] | 72 | Config* config)>; |
| 73 | |
| 74 | void ProfilingLoop(Config& config, HandlerFn handler); |
| Andreas Gampe | 04672dd | 2018-03-28 14:28:18 -0700 | [diff] [blame] | 75 | void ProfilingLoop(std::function<Config*()> config_fn, |
| 76 | std::function<void()> update_fn, |
| 77 | HandlerFn handler); |
| Andreas Gampe | 84a77f7 | 2017-12-21 18:15:37 -0800 | [diff] [blame] | 78 | |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 79 | // |
| 80 | // Exposed for unit testing |
| 81 | // |
| 82 | extern unsigned collect_cpu_utilization(); |
| 83 | extern bool get_booting(); |
| 84 | extern bool get_charging(); |
| 85 | extern bool get_camera_active(); |
| 86 | |
| Andreas Gampe | 04672dd | 2018-03-28 14:28:18 -0700 | [diff] [blame] | 87 | bool IsDebugBuild(); |
| 88 | |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 89 | #endif |