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 18 #ifndef SYSTEM_EXTRAS_PERFPROFD_PERFPROFDCORE_H_ 19 #define SYSTEM_EXTRAS_PERFPROFD_PERFPROFDCORE_H_ 20 21 #include <functional> 22 #include <memory> 23 #include <string> 24 25 #include "perfprofd_record-fwd.h" 26 27 struct Config; 28 29 namespace perfprofd { 30 struct Symbolizer; 31 } 32 33 void CommonInit(uint32_t use_fixed_seed, const char* dest_dir); 34 void GlobalInit(const std::string& perf_path); 35 36 // 37 // This enumeration holds the results of what happened when on an 38 // attempted perf profiling run. 39 // 40 typedef enum { 41 42 // Success 43 OK_PROFILE_COLLECTION, 44 45 // Fork system call failed (lo mem?) 46 ERR_FORK_FAILED, 47 48 // Perf ran but crashed or returned a bad exit status 49 ERR_PERF_RECORD_FAILED, 50 51 // The perf.data encoding process failed somehow 52 ERR_PERF_ENCODE_FAILED, 53 54 // We tried to open the output file perf.data.encoded but the open failed 55 ERR_OPEN_ENCODED_FILE_FAILED, 56 57 // Error while writing perf.data.encoded 58 ERR_WRITE_ENCODED_FILE_FAILED 59 } PROFILE_RESULT; 60 61 // 62 // Given a full path to a perf.data file specified by "data_file_path", 63 // read/summarize/encode the contents into a new file specified 64 // by "encoded_file_path". Return status indicates whether the operation 65 // was successful (either OK_PROFILE_COLLECTION or an error of some sort). 66 // 67 PROFILE_RESULT encode_to_proto(const std::string &data_file_path, 68 const char *encoded_file_path, 69 const Config& config, 70 unsigned cpu_utilization, 71 perfprofd::Symbolizer* symbolizer); 72 73 using HandlerFn = std::function<bool(android::perfprofd::PerfprofdRecord* proto, 74 Config* config)>; 75 76 void ProfilingLoop(Config& config, HandlerFn handler); 77 void ProfilingLoop(std::function<Config*()> config_fn, 78 std::function<void()> update_fn, 79 HandlerFn handler); 80 81 // 82 // Exposed for unit testing 83 // 84 extern unsigned collect_cpu_utilization(); 85 extern bool get_booting(); 86 extern bool get_charging(); 87 extern bool get_camera_active(); 88 89 bool IsDebugBuild(); 90 91 #endif 92