| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [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 | |
| 18 | #ifndef SYSTEM_EXTRAS_PERFPROFD_CONFIG_H_ |
| 19 | #define SYSTEM_EXTRAS_PERFPROFD_CONFIG_H_ |
| 20 | |
| 21 | #include <cstdint> |
| 22 | #include <string> |
| 23 | |
| 24 | #include <unistd.h> |
| 25 | |
| 26 | struct Config { |
| 27 | virtual ~Config() {} |
| 28 | |
| 29 | // Average number of seconds between perf profile collections (if |
| 30 | // set to 100, then over time we want to see a perf profile |
| 31 | // collected every 100 seconds). The actual time within the interval |
| 32 | // for the collection is chosen randomly. |
| 33 | uint32_t collection_interval_in_s = 14400; |
| 34 | // Use the specified fixed seed for random number generation (unit |
| 35 | // testing) |
| 36 | uint32_t use_fixed_seed = 0; |
| 37 | // For testing purposes, number of times to iterate through main |
| 38 | // loop. Value of zero indicates that we should loop forever. |
| 39 | uint32_t main_loop_iterations = 0; |
| 40 | |
| Andreas Gampe | 9217681 | 2017-12-27 19:20:45 -0800 | [diff] [blame] | 41 | // The pid of the process to profile. May be negative, in which case |
| 42 | // the whole system will be profiled. |
| 43 | int32_t process = -1; |
| 44 | |
| Andreas Gampe | 35dc175 | 2018-05-11 12:40:59 -0700 | [diff] [blame] | 45 | // Destination directory (where to write profiles). |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 46 | std::string destination_directory = "/data/misc/perfprofd"; |
| 47 | // Config directory (where to read configs). |
| 48 | std::string config_directory = "/data/data/com.google.android.gms/files"; |
| 49 | // Full path to 'perf' executable. |
| 50 | std::string perf_path = "/system/xbin/simpleperf"; |
| 51 | |
| 52 | // Desired sampling period (passed to perf -c option). Small |
| 53 | // sampling periods can perturb the collected profiles, so enforce |
| Andreas Gampe | e4b2ed9 | 2018-04-04 21:06:26 -0700 | [diff] [blame] | 54 | // min/max. A value of 0 means perf default. sampling_frequency |
| 55 | // takes priority. |
| 56 | uint32_t sampling_period = 0; |
| 57 | // Desired sampling frequency (passed to perf -f option). A value of 0 |
| 58 | // means using sampling_period or default. |
| 59 | uint32_t sampling_frequency = 0; |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 60 | // Length of time to collect samples (number of seconds for 'perf |
| 61 | // record -a' run). |
| 62 | uint32_t sample_duration_in_s = 2; |
| 63 | |
| 64 | // If this parameter is non-zero it will cause perfprofd to |
| 65 | // exit immediately if the build type is not userdebug or eng. |
| 66 | // Currently defaults to 1 (true). |
| 67 | bool only_debug_build = true; |
| 68 | |
| 69 | // If the "mpdecision" service is running at the point we are ready |
| 70 | // to kick off a profiling run, then temporarily disable the service |
| 71 | // and hard-wire all cores on prior to the collection run, provided |
| 72 | // that the duration of the recording is less than or equal to the value of |
| 73 | // 'hardwire_cpus_max_duration'. |
| 74 | bool hardwire_cpus = true; |
| 75 | uint32_t hardwire_cpus_max_duration_in_s = 5; |
| 76 | |
| 77 | // Maximum number of unprocessed profiles we can accumulate in the |
| 78 | // destination directory. Once we reach this limit, we continue |
| 79 | // to collect, but we just overwrite the most recent profile. |
| 80 | uint32_t max_unprocessed_profiles = 10; |
| 81 | |
| 82 | // If set to 1, pass the -g option when invoking 'perf' (requests |
| 83 | // stack traces as opposed to flat profile). |
| 84 | bool stack_profile = false; |
| 85 | |
| 86 | // For unit testing only: if set to 1, emit info messages on config |
| 87 | // file parsing. |
| 88 | bool trace_config_read = false; |
| 89 | |
| 90 | // Control collection of various additional profile tags |
| 91 | bool collect_cpu_utilization = true; |
| 92 | bool collect_charging_state = true; |
| 93 | bool collect_booting = true; |
| 94 | bool collect_camera_active = false; |
| Andreas Gampe | 517f4e9 | 2017-12-21 10:26:36 -0800 | [diff] [blame] | 95 | |
| Andreas Gampe | a6c3913 | 2018-01-08 12:39:38 -0800 | [diff] [blame] | 96 | // If true, use an ELF symbolizer to on-device symbolize. |
| 97 | bool use_elf_symbolizer = true; |
| 98 | |
| Andreas Gampe | 894b3f9 | 2018-03-22 19:48:48 -0700 | [diff] [blame] | 99 | // If true, use libz to compress the output proto. |
| 100 | bool compress = true; |
| 101 | |
| Andreas Gampe | 7f85bff | 2018-03-29 10:08:19 -0700 | [diff] [blame] | 102 | // If true, send the proto to dropbox instead to a file. |
| 103 | bool send_to_dropbox = false; |
| 104 | |
| Andreas Gampe | 517f4e9 | 2017-12-21 10:26:36 -0800 | [diff] [blame] | 105 | // Sleep for the given number of seconds. |
| 106 | virtual void Sleep(size_t seconds) = 0; |
| Andreas Gampe | 90fd001 | 2017-12-22 10:32:16 -0800 | [diff] [blame] | 107 | |
| 108 | // Should the profiling be stopped immediately? |
| 109 | virtual bool ShouldStopProfiling() { |
| 110 | return false; |
| 111 | } |
| Andreas Gampe | a349850 | 2017-12-27 11:23:41 -0800 | [diff] [blame] | 112 | |
| 113 | // Is profiling enabled? |
| 114 | virtual bool IsProfilingEnabled() const = 0; |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | #endif // SYSTEM_EXTRAS_PERFPROFD_CONFIG_H_ |