| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [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 | |
| Dan Albert | 18bfe42 | 2016-09-21 14:06:39 -0700 | [diff] [blame] | 18 | #include <assert.h> |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| Andreas Gampe | dfd6794 | 2017-12-05 09:19:56 -0800 | [diff] [blame] | 21 | |
| 22 | #include <algorithm> |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 23 | #include <cstring> |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 24 | #include <sstream> |
| 25 | |
| Elliott Hughes | 66dd09e | 2015-12-04 14:00:57 -0800 | [diff] [blame] | 26 | #include <android-base/file.h> |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 27 | #include <android-base/logging.h> |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 28 | |
| 29 | #include "configreader.h" |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 30 | |
| 31 | // |
| 32 | // Config file path |
| 33 | // |
| 34 | static const char *config_file_path = |
| 35 | "/data/data/com.google.android.gms/files/perfprofd.conf"; |
| 36 | |
| 37 | ConfigReader::ConfigReader() |
| 38 | : trace_config_read(false) |
| 39 | { |
| 40 | addDefaultEntries(); |
| 41 | } |
| 42 | |
| 43 | ConfigReader::~ConfigReader() |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | const char *ConfigReader::getConfigFilePath() |
| 48 | { |
| 49 | return config_file_path; |
| 50 | } |
| 51 | |
| 52 | void ConfigReader::setConfigFilePath(const char *path) |
| 53 | { |
| 54 | config_file_path = strdup(path); |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 55 | LOG(INFO) << "config file path set to " << config_file_path; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | // |
| 59 | // Populate the reader with the set of allowable entries |
| 60 | // |
| 61 | void ConfigReader::addDefaultEntries() |
| 62 | { |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 63 | struct DummyConfig : public Config { |
| 64 | void Sleep(size_t seconds) override {} |
| 65 | bool IsProfilingEnabled() const override { return false; } |
| 66 | }; |
| 67 | DummyConfig config; |
| 68 | |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 69 | // Average number of seconds between perf profile collections (if |
| 70 | // set to 100, then over time we want to see a perf profile |
| 71 | // collected every 100 seconds). The actual time within the interval |
| 72 | // for the collection is chosen randomly. |
| Andreas Gampe | 59a1821 | 2018-04-30 16:55:15 -0700 | [diff] [blame] | 73 | addUnsignedEntry("collection_interval", config.collection_interval_in_s, 0, UINT32_MAX); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 74 | |
| 75 | // Use the specified fixed seed for random number generation (unit |
| 76 | // testing) |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 77 | addUnsignedEntry("use_fixed_seed", config.use_fixed_seed, 0, UINT32_MAX); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 78 | |
| 79 | // For testing purposes, number of times to iterate through main |
| 80 | // loop. Value of zero indicates that we should loop forever. |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 81 | addUnsignedEntry("main_loop_iterations", config.main_loop_iterations, 0, UINT32_MAX); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 82 | |
| Andreas Gampe | 35dc175 | 2018-05-11 12:40:59 -0700 | [diff] [blame] | 83 | // Destination directory (where to write profiles). |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 84 | addStringEntry("destination_directory", config.destination_directory.c_str()); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 85 | |
| 86 | // Config directory (where to read configs). |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 87 | addStringEntry("config_directory", config.config_directory.c_str()); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 88 | |
| 89 | // Full path to 'perf' executable. |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 90 | addStringEntry("perf_path", config.perf_path.c_str()); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 91 | |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 92 | // Desired sampling period (passed to perf -c option). |
| Andreas Gampe | e4b2ed9 | 2018-04-04 21:06:26 -0700 | [diff] [blame] | 93 | addUnsignedEntry("sampling_period", config.sampling_period, 0, UINT32_MAX); |
| 94 | // Desired sampling frequency (passed to perf -f option). |
| 95 | addUnsignedEntry("sampling_frequency", config.sampling_frequency, 0, UINT32_MAX); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 96 | |
| 97 | // Length of time to collect samples (number of seconds for 'perf |
| 98 | // record -a' run). |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 99 | addUnsignedEntry("sample_duration", config.sample_duration_in_s, 1, 600); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 100 | |
| 101 | // If this parameter is non-zero it will cause perfprofd to |
| 102 | // exit immediately if the build type is not userdebug or eng. |
| 103 | // Currently defaults to 1 (true). |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 104 | addUnsignedEntry("only_debug_build", config.only_debug_build ? 1 : 0, 0, 1); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 105 | |
| 106 | // If the "mpdecision" service is running at the point we are ready |
| 107 | // to kick off a profiling run, then temporarily disable the service |
| 108 | // and hard-wire all cores on prior to the collection run, provided |
| 109 | // that the duration of the recording is less than or equal to the value of |
| 110 | // 'hardwire_cpus_max_duration'. |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 111 | addUnsignedEntry("hardwire_cpus", config.hardwire_cpus, 0, 1); |
| 112 | addUnsignedEntry("hardwire_cpus_max_duration", |
| 113 | config.hardwire_cpus_max_duration_in_s, |
| 114 | 1, |
| 115 | UINT32_MAX); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 116 | |
| 117 | // Maximum number of unprocessed profiles we can accumulate in the |
| 118 | // destination directory. Once we reach this limit, we continue |
| 119 | // to collect, but we just overwrite the most recent profile. |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 120 | addUnsignedEntry("max_unprocessed_profiles", config.max_unprocessed_profiles, 1, UINT32_MAX); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 121 | |
| 122 | // If set to 1, pass the -g option when invoking 'perf' (requests |
| 123 | // stack traces as opposed to flat profile). |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 124 | addUnsignedEntry("stack_profile", config.stack_profile ? 1 : 0, 0, 1); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 125 | |
| 126 | // For unit testing only: if set to 1, emit info messages on config |
| 127 | // file parsing. |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 128 | addUnsignedEntry("trace_config_read", config.trace_config_read ? 1 : 0, 0, 1); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 129 | |
| 130 | // Control collection of various additional profile tags |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 131 | addUnsignedEntry("collect_cpu_utilization", config.collect_cpu_utilization ? 1 : 0, 0, 1); |
| 132 | addUnsignedEntry("collect_charging_state", config.collect_charging_state ? 1 : 0, 0, 1); |
| 133 | addUnsignedEntry("collect_booting", config.collect_booting ? 1 : 0, 0, 1); |
| 134 | addUnsignedEntry("collect_camera_active", config.collect_camera_active ? 1 : 0, 0, 1); |
| Andreas Gampe | e303374 | 2018-01-18 21:19:06 -0800 | [diff] [blame] | 135 | |
| 136 | // If true, use an ELF symbolizer to on-device symbolize. |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 137 | addUnsignedEntry("use_elf_symbolizer", config.use_elf_symbolizer ? 1 : 0, 0, 1); |
| Andreas Gampe | 894b3f9 | 2018-03-22 19:48:48 -0700 | [diff] [blame] | 138 | |
| 139 | // If true, use libz to compress the output proto. |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 140 | addUnsignedEntry("compress", config.compress ? 1 : 0, 0, 1); |
| Andreas Gampe | 7f85bff | 2018-03-29 10:08:19 -0700 | [diff] [blame] | 141 | |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 142 | // If true, send the proto to dropbox instead of to a file. |
| 143 | addUnsignedEntry("dropbox", config.send_to_dropbox ? 1 : 0, 0, 1); |
| Andreas Gampe | abc5727 | 2018-04-19 10:16:30 -0700 | [diff] [blame] | 144 | |
| 145 | // The pid of the process to profile. May be negative, in which case |
| 146 | // the whole system will be profiled. |
| 147 | addUnsignedEntry("process", static_cast<uint32_t>(-1), 0, UINT32_MAX); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void ConfigReader::addUnsignedEntry(const char *key, |
| 151 | unsigned default_value, |
| 152 | unsigned min_value, |
| 153 | unsigned max_value) |
| 154 | { |
| 155 | std::string ks(key); |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 156 | CHECK(u_entries.find(ks) == u_entries.end() && |
| 157 | s_entries.find(ks) == s_entries.end()) |
| 158 | << "internal error -- duplicate entry for key " << key; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 159 | values vals; |
| 160 | vals.minv = min_value; |
| 161 | vals.maxv = max_value; |
| 162 | u_info[ks] = vals; |
| 163 | u_entries[ks] = default_value; |
| 164 | } |
| 165 | |
| 166 | void ConfigReader::addStringEntry(const char *key, const char *default_value) |
| 167 | { |
| 168 | std::string ks(key); |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 169 | CHECK(u_entries.find(ks) == u_entries.end() && |
| 170 | s_entries.find(ks) == s_entries.end()) |
| 171 | << "internal error -- duplicate entry for key " << key; |
| 172 | CHECK(default_value != nullptr) << "internal error -- bad default value for key " << key; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 173 | s_entries[ks] = std::string(default_value); |
| 174 | } |
| 175 | |
| 176 | unsigned ConfigReader::getUnsignedValue(const char *key) const |
| 177 | { |
| 178 | std::string ks(key); |
| 179 | auto it = u_entries.find(ks); |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 180 | CHECK(it != u_entries.end()); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 181 | return it->second; |
| 182 | } |
| 183 | |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 184 | bool ConfigReader::getBoolValue(const char *key) const |
| 185 | { |
| 186 | std::string ks(key); |
| 187 | auto it = u_entries.find(ks); |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 188 | CHECK(it != u_entries.end()); |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 189 | return it->second != 0; |
| 190 | } |
| 191 | |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 192 | std::string ConfigReader::getStringValue(const char *key) const |
| 193 | { |
| 194 | std::string ks(key); |
| 195 | auto it = s_entries.find(ks); |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 196 | CHECK(it != s_entries.end()); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 197 | return it->second; |
| 198 | } |
| 199 | |
| 200 | void ConfigReader::overrideUnsignedEntry(const char *key, unsigned new_value) |
| 201 | { |
| 202 | std::string ks(key); |
| 203 | auto it = u_entries.find(ks); |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 204 | CHECK(it != u_entries.end()); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 205 | values vals; |
| 206 | auto iit = u_info.find(key); |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 207 | CHECK(iit != u_info.end()); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 208 | vals = iit->second; |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 209 | CHECK(new_value >= vals.minv && new_value <= vals.maxv); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 210 | it->second = new_value; |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 211 | LOG(INFO) << "option " << key << " overridden to " << new_value; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | |
| 215 | // |
| 216 | // Parse a key=value pair read from the config file. This will issue |
| 217 | // warnings or errors to the system logs if the line can't be |
| 218 | // interpreted properly. |
| 219 | // |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 220 | bool ConfigReader::parseLine(const char *key, |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 221 | const char *value, |
| 222 | unsigned linecount) |
| 223 | { |
| 224 | assert(key); |
| 225 | assert(value); |
| 226 | |
| 227 | auto uit = u_entries.find(key); |
| 228 | if (uit != u_entries.end()) { |
| 229 | unsigned uvalue = 0; |
| 230 | if (isdigit(value[0]) == 0 || sscanf(value, "%u", &uvalue) != 1) { |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 231 | LOG(WARNING) << "line " << linecount << ": malformed unsigned value (ignored)"; |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 232 | return false; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 233 | } else { |
| 234 | values vals; |
| 235 | auto iit = u_info.find(key); |
| 236 | assert(iit != u_info.end()); |
| 237 | vals = iit->second; |
| 238 | if (uvalue < vals.minv || uvalue > vals.maxv) { |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 239 | LOG(WARNING) << "line " << linecount << ": " |
| 240 | << "specified value " << uvalue << " for '" << key << "' " |
| 241 | << "outside permitted range [" << vals.minv << " " << vals.maxv |
| 242 | << "] (ignored)"; |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 243 | return false; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 244 | } else { |
| 245 | if (trace_config_read) { |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 246 | LOG(INFO) << "option " << key << " set to " << uvalue; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 247 | } |
| 248 | uit->second = uvalue; |
| 249 | } |
| 250 | } |
| 251 | trace_config_read = (getUnsignedValue("trace_config_read") != 0); |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 252 | return true; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | auto sit = s_entries.find(key); |
| 256 | if (sit != s_entries.end()) { |
| 257 | if (trace_config_read) { |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 258 | LOG(INFO) << "option " << key << " set to " << value; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 259 | } |
| 260 | sit->second = std::string(value); |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 261 | return true; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 262 | } |
| 263 | |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 264 | LOG(WARNING) << "line " << linecount << ": unknown option '" << key << "' ignored"; |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 265 | return false; |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static bool isblank(const std::string &line) |
| 269 | { |
| Andreas Gampe | dfd6794 | 2017-12-05 09:19:56 -0800 | [diff] [blame] | 270 | auto non_space = [](char c) { return isspace(c) == 0; }; |
| 271 | return std::find_if(line.begin(), line.end(), non_space) == line.end(); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 272 | } |
| 273 | |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 274 | |
| 275 | |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 276 | bool ConfigReader::readFile() |
| 277 | { |
| 278 | std::string contents; |
| 279 | if (! android::base::ReadFileToString(config_file_path, &contents)) { |
| 280 | return false; |
| 281 | } |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 282 | return Read(contents, /* fail_on_error */ false); |
| 283 | } |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 284 | |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 285 | bool ConfigReader::Read(const std::string& content, bool fail_on_error) { |
| 286 | std::stringstream ss(content); |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 287 | std::string line; |
| 288 | for (unsigned linecount = 1; |
| 289 | std::getline(ss,line,'\n'); |
| 290 | linecount += 1) |
| 291 | { |
| 292 | |
| 293 | // comment line? |
| 294 | if (line[0] == '#') { |
| 295 | continue; |
| 296 | } |
| 297 | |
| 298 | // blank line? |
| 299 | if (isblank(line.c_str())) { |
| 300 | continue; |
| 301 | } |
| 302 | |
| 303 | // look for X=Y assignment |
| 304 | auto efound = line.find('='); |
| 305 | if (efound == std::string::npos) { |
| Andreas Gampe | d9084f6 | 2018-01-10 11:37:20 -0800 | [diff] [blame] | 306 | LOG(WARNING) << "line " << linecount << ": line malformed (no '=' found)"; |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 307 | if (fail_on_error) { |
| 308 | return false; |
| 309 | } |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 310 | continue; |
| 311 | } |
| 312 | |
| 313 | std::string key(line.substr(0, efound)); |
| 314 | std::string value(line.substr(efound+1, std::string::npos)); |
| 315 | |
| Andreas Gampe | f73ddfa | 2018-03-29 14:52:57 -0700 | [diff] [blame] | 316 | bool parse_success = parseLine(key.c_str(), value.c_str(), linecount); |
| 317 | if (fail_on_error && !parse_success) { |
| 318 | return false; |
| 319 | } |
| Than McIntosh | 8c7c7db | 2015-09-03 15:16:04 -0400 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | return true; |
| 323 | } |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 324 | |
| 325 | void ConfigReader::FillConfig(Config* config) { |
| 326 | config->collection_interval_in_s = getUnsignedValue("collection_interval"); |
| 327 | |
| 328 | config->use_fixed_seed = getUnsignedValue("use_fixed_seed"); |
| 329 | |
| 330 | config->main_loop_iterations = getUnsignedValue("main_loop_iterations"); |
| 331 | |
| 332 | config->destination_directory = getStringValue("destination_directory"); |
| 333 | |
| 334 | config->config_directory = getStringValue("config_directory"); |
| 335 | |
| 336 | config->perf_path = getStringValue("perf_path"); |
| 337 | |
| 338 | config->sampling_period = getUnsignedValue("sampling_period"); |
| Andreas Gampe | 59a1821 | 2018-04-30 16:55:15 -0700 | [diff] [blame] | 339 | config->sampling_frequency = getUnsignedValue("sampling_frequency"); |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 340 | |
| 341 | config->sample_duration_in_s = getUnsignedValue("sample_duration"); |
| 342 | |
| 343 | config->only_debug_build = getBoolValue("only_debug_build"); |
| 344 | |
| 345 | config->hardwire_cpus = getBoolValue("hardwire_cpus"); |
| 346 | config->hardwire_cpus_max_duration_in_s = getUnsignedValue("hardwire_cpus_max_duration"); |
| 347 | |
| 348 | config->max_unprocessed_profiles = getUnsignedValue("max_unprocessed_profiles"); |
| 349 | |
| 350 | config->stack_profile = getBoolValue("stack_profile"); |
| 351 | |
| 352 | config->trace_config_read = getBoolValue("trace_config_read"); |
| 353 | |
| 354 | config->collect_cpu_utilization = getBoolValue("collect_cpu_utilization"); |
| 355 | config->collect_charging_state = getBoolValue("collect_charging_state"); |
| 356 | config->collect_booting = getBoolValue("collect_booting"); |
| 357 | config->collect_camera_active = getBoolValue("collect_camera_active"); |
| Andreas Gampe | 9543854 | 2018-01-09 16:18:35 -0800 | [diff] [blame] | 358 | |
| Andreas Gampe | abc5727 | 2018-04-19 10:16:30 -0700 | [diff] [blame] | 359 | config->process = static_cast<int32_t>(getUnsignedValue("process")); |
| Andreas Gampe | e303374 | 2018-01-18 21:19:06 -0800 | [diff] [blame] | 360 | config->use_elf_symbolizer = getBoolValue("use_elf_symbolizer"); |
| Andreas Gampe | 894b3f9 | 2018-03-22 19:48:48 -0700 | [diff] [blame] | 361 | config->compress = getBoolValue("compress"); |
| Andreas Gampe | 7f85bff | 2018-03-29 10:08:19 -0700 | [diff] [blame] | 362 | config->send_to_dropbox = getBoolValue("dropbox"); |
| Andreas Gampe | e44ae14 | 2017-12-21 10:02:23 -0800 | [diff] [blame] | 363 | } |