Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 17 | #include <errno.h> |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <sys/file.h> |
| 21 | #include <sys/stat.h> |
| 22 | #include <unistd.h> |
| 23 | |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 24 | #include <fstream> |
Calin Juravle | 876f350 | 2016-03-24 16:16:34 +0000 | [diff] [blame] | 25 | #include <iostream> |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 26 | #include <set> |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 27 | #include <string> |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 28 | #include <unordered_set> |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 29 | #include <vector> |
| 30 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 31 | #include "android-base/stringprintf.h" |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 32 | #include "android-base/strings.h" |
| 33 | |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 34 | #include "base/dumpable.h" |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 35 | #include "base/logging.h" // For InitLogging. |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 36 | #include "base/scoped_flock.h" |
| 37 | #include "base/stringpiece.h" |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 38 | #include "base/time_utils.h" |
| 39 | #include "base/unix_file/fd_file.h" |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 40 | #include "boot_image_profile.h" |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 41 | #include "bytecode_utils.h" |
David Sehr | 013fd80 | 2018-01-11 22:55:24 -0800 | [diff] [blame] | 42 | #include "dex/art_dex_file_loader.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 43 | #include "dex/code_item_accessors-inl.h" |
| 44 | #include "dex/dex_file.h" |
| 45 | #include "dex/dex_file_loader.h" |
| 46 | #include "dex/dex_file_types.h" |
Calin Juravle | 33083d6 | 2017-01-18 15:29:12 -0800 | [diff] [blame] | 47 | #include "jit/profile_compilation_info.h" |
Mathieu Chartier | dbddc22 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 48 | #include "profile_assistant.h" |
David Sehr | f57589f | 2016-10-17 10:09:33 -0700 | [diff] [blame] | 49 | #include "runtime.h" |
Mathieu Chartier | dbddc22 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 50 | #include "type_reference.h" |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 51 | #include "utils.h" |
David Sehr | 546d24f | 2016-06-02 10:46:19 -0700 | [diff] [blame] | 52 | #include "zip_archive.h" |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 53 | |
| 54 | namespace art { |
| 55 | |
| 56 | static int original_argc; |
| 57 | static char** original_argv; |
| 58 | |
| 59 | static std::string CommandLine() { |
| 60 | std::vector<std::string> command; |
| 61 | for (int i = 0; i < original_argc; ++i) { |
| 62 | command.push_back(original_argv[i]); |
| 63 | } |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 64 | return android::base::Join(command, ' '); |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 65 | } |
| 66 | |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 67 | static constexpr int kInvalidFd = -1; |
| 68 | |
| 69 | static bool FdIsValid(int fd) { |
| 70 | return fd != kInvalidFd; |
| 71 | } |
| 72 | |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 73 | static void UsageErrorV(const char* fmt, va_list ap) { |
| 74 | std::string error; |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 75 | android::base::StringAppendV(&error, fmt, ap); |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 76 | LOG(ERROR) << error; |
| 77 | } |
| 78 | |
| 79 | static void UsageError(const char* fmt, ...) { |
| 80 | va_list ap; |
| 81 | va_start(ap, fmt); |
| 82 | UsageErrorV(fmt, ap); |
| 83 | va_end(ap); |
| 84 | } |
| 85 | |
| 86 | NO_RETURN static void Usage(const char *fmt, ...) { |
| 87 | va_list ap; |
| 88 | va_start(ap, fmt); |
| 89 | UsageErrorV(fmt, ap); |
| 90 | va_end(ap); |
| 91 | |
| 92 | UsageError("Command: %s", CommandLine().c_str()); |
| 93 | UsageError("Usage: profman [options]..."); |
| 94 | UsageError(""); |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 95 | UsageError(" --dump-only: dumps the content of the specified profile files"); |
| 96 | UsageError(" to standard output (default) in a human readable form."); |
| 97 | UsageError(""); |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 98 | UsageError(" --dump-output-to-fd=<number>: redirects --dump-only output to a file descriptor."); |
| 99 | UsageError(""); |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 100 | UsageError(" --dump-classes-and-methods: dumps a sorted list of classes and methods that are"); |
| 101 | UsageError(" in the specified profile file to standard output (default) in a human"); |
| 102 | UsageError(" readable form. The output is valid input for --create-profile-from"); |
Calin Juravle | 876f350 | 2016-03-24 16:16:34 +0000 | [diff] [blame] | 103 | UsageError(""); |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 104 | UsageError(" --profile-file=<filename>: specify profiler output file to use for compilation."); |
| 105 | UsageError(" Can be specified multiple time, in which case the data from the different"); |
| 106 | UsageError(" profiles will be aggregated."); |
| 107 | UsageError(""); |
| 108 | UsageError(" --profile-file-fd=<number>: same as --profile-file but accepts a file descriptor."); |
| 109 | UsageError(" Cannot be used together with --profile-file."); |
| 110 | UsageError(""); |
| 111 | UsageError(" --reference-profile-file=<filename>: specify a reference profile."); |
| 112 | UsageError(" The data in this file will be compared with the data obtained by merging"); |
| 113 | UsageError(" all the files specified with --profile-file or --profile-file-fd."); |
| 114 | UsageError(" If the exit code is EXIT_COMPILE then all --profile-file will be merged into"); |
| 115 | UsageError(" --reference-profile-file. "); |
| 116 | UsageError(""); |
| 117 | UsageError(" --reference-profile-file-fd=<number>: same as --reference-profile-file but"); |
| 118 | UsageError(" accepts a file descriptor. Cannot be used together with"); |
| 119 | UsageError(" --reference-profile-file."); |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 120 | UsageError(""); |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 121 | UsageError(" --generate-test-profile=<filename>: generates a random profile file for testing."); |
| 122 | UsageError(" --generate-test-profile-num-dex=<number>: number of dex files that should be"); |
| 123 | UsageError(" included in the generated profile. Defaults to 20."); |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 124 | UsageError(" --generate-test-profile-method-percentage=<number>: the percentage from the maximum"); |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 125 | UsageError(" number of methods that should be generated. Defaults to 5."); |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 126 | UsageError(" --generate-test-profile-class-percentage=<number>: the percentage from the maximum"); |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 127 | UsageError(" number of classes that should be generated. Defaults to 5."); |
Jeff Hao | f0a31f8 | 2017-03-27 15:50:37 -0700 | [diff] [blame] | 128 | UsageError(" --generate-test-profile-seed=<number>: seed for random number generator used when"); |
| 129 | UsageError(" generating random test profiles. Defaults to using NanoTime."); |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 130 | UsageError(""); |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 131 | UsageError(" --create-profile-from=<filename>: creates a profile from a list of classes and"); |
| 132 | UsageError(" methods."); |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 133 | UsageError(""); |
David Sehr | 546d24f | 2016-06-02 10:46:19 -0700 | [diff] [blame] | 134 | UsageError(" --dex-location=<string>: location string to use with corresponding"); |
| 135 | UsageError(" apk-fd to find dex files"); |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 136 | UsageError(""); |
David Sehr | 546d24f | 2016-06-02 10:46:19 -0700 | [diff] [blame] | 137 | UsageError(" --apk-fd=<number>: file descriptor containing an open APK to"); |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 138 | UsageError(" search for dex files"); |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 139 | UsageError(" --apk-=<filename>: an APK to search for dex files"); |
David Brazdil | f13ac7c | 2018-01-30 10:09:08 +0000 | [diff] [blame^] | 140 | UsageError(" --skip-apk-verification: do not attempt to verify APKs"); |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 141 | UsageError(""); |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 142 | UsageError(" --generate-boot-image-profile: Generate a boot image profile based on input"); |
| 143 | UsageError(" profiles. Requires passing in dex files to inspect properties of classes."); |
| 144 | UsageError(" --boot-image-class-threshold=<value>: specify minimum number of class occurrences"); |
| 145 | UsageError(" to include a class in the boot image profile. Default is 10."); |
| 146 | UsageError(" --boot-image-clean-class-threshold=<value>: specify minimum number of clean class"); |
| 147 | UsageError(" occurrences to include a class in the boot image profile. A clean class is a"); |
| 148 | UsageError(" class that doesn't have any static fields or native methods and is likely to"); |
| 149 | UsageError(" remain clean in the image. Default is 3."); |
Mathieu Chartier | 8eecddf | 2017-07-12 16:05:54 -0700 | [diff] [blame] | 150 | UsageError(" --boot-image-sampled-method-threshold=<value>: minimum number of profiles a"); |
| 151 | UsageError(" non-hot method needs to be in order to be hot in the output profile. The"); |
| 152 | UsageError(" default is max int."); |
Calin Juravle | 2dba0ab | 2018-01-22 19:22:24 -0800 | [diff] [blame] | 153 | UsageError(" --copy-and-update-profile-key: if present, profman will copy the profile from"); |
| 154 | UsageError(" the file passed with --profile-fd(file) to the profile passed with"); |
| 155 | UsageError(" --reference-profile-fd(file) and update at the same time the profile-key"); |
| 156 | UsageError(" of entries corresponding to the apks passed with --apk(-fd)."); |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 157 | UsageError(""); |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 158 | |
| 159 | exit(EXIT_FAILURE); |
| 160 | } |
| 161 | |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 162 | // Note: make sure you update the Usage if you change these values. |
| 163 | static constexpr uint16_t kDefaultTestProfileNumDex = 20; |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 164 | static constexpr uint16_t kDefaultTestProfileMethodPercentage = 5; |
| 165 | static constexpr uint16_t kDefaultTestProfileClassPercentage = 5; |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 166 | |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 167 | // Separators used when parsing human friendly representation of profiles. |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 168 | static const std::string kMethodSep = "->"; // NOLINT [runtime/string] [4] |
| 169 | static const std::string kMissingTypesMarker = "missing_types"; // NOLINT [runtime/string] [4] |
| 170 | static const std::string kInvalidClassDescriptor = "invalid_class"; // NOLINT [runtime/string] [4] |
| 171 | static const std::string kInvalidMethod = "invalid_method"; // NOLINT [runtime/string] [4] |
| 172 | static const std::string kClassAllMethods = "*"; // NOLINT [runtime/string] [4] |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 173 | static constexpr char kProfileParsingInlineChacheSep = '+'; |
| 174 | static constexpr char kProfileParsingTypeSep = ','; |
| 175 | static constexpr char kProfileParsingFirstCharInSignature = '('; |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 176 | static constexpr char kMethodFlagStringHot = 'H'; |
| 177 | static constexpr char kMethodFlagStringStartup = 'S'; |
| 178 | static constexpr char kMethodFlagStringPostStartup = 'P'; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 179 | |
| 180 | // TODO(calin): This class has grown too much from its initial design. Split the functionality |
| 181 | // into smaller, more contained pieces. |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 182 | class ProfMan FINAL { |
| 183 | public: |
| 184 | ProfMan() : |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 185 | reference_profile_file_fd_(kInvalidFd), |
| 186 | dump_only_(false), |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 187 | dump_classes_and_methods_(false), |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 188 | generate_boot_image_profile_(false), |
David Brazdil | f13ac7c | 2018-01-30 10:09:08 +0000 | [diff] [blame^] | 189 | skip_apk_verification_(false), |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 190 | dump_output_to_fd_(kInvalidFd), |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 191 | test_profile_num_dex_(kDefaultTestProfileNumDex), |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 192 | test_profile_method_percerntage_(kDefaultTestProfileMethodPercentage), |
| 193 | test_profile_class_percentage_(kDefaultTestProfileClassPercentage), |
Jeff Hao | f0a31f8 | 2017-03-27 15:50:37 -0700 | [diff] [blame] | 194 | test_profile_seed_(NanoTime()), |
Calin Juravle | 2dba0ab | 2018-01-22 19:22:24 -0800 | [diff] [blame] | 195 | start_ns_(NanoTime()), |
| 196 | copy_and_update_profile_key_(false) {} |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 197 | |
| 198 | ~ProfMan() { |
| 199 | LogCompletionTime(); |
| 200 | } |
| 201 | |
| 202 | void ParseArgs(int argc, char **argv) { |
| 203 | original_argc = argc; |
| 204 | original_argv = argv; |
| 205 | |
Andreas Gampe | 51d80cc | 2017-06-21 21:05:13 -0700 | [diff] [blame] | 206 | InitLogging(argv, Runtime::Abort); |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 207 | |
| 208 | // Skip over the command name. |
| 209 | argv++; |
| 210 | argc--; |
| 211 | |
| 212 | if (argc == 0) { |
| 213 | Usage("No arguments specified"); |
| 214 | } |
| 215 | |
| 216 | for (int i = 0; i < argc; ++i) { |
| 217 | const StringPiece option(argv[i]); |
| 218 | const bool log_options = false; |
| 219 | if (log_options) { |
Calin Juravle | 876f350 | 2016-03-24 16:16:34 +0000 | [diff] [blame] | 220 | LOG(INFO) << "profman: option[" << i << "]=" << argv[i]; |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 221 | } |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 222 | if (option == "--dump-only") { |
| 223 | dump_only_ = true; |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 224 | } else if (option == "--dump-classes-and-methods") { |
| 225 | dump_classes_and_methods_ = true; |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 226 | } else if (option.starts_with("--create-profile-from=")) { |
| 227 | create_profile_from_file_ = option.substr(strlen("--create-profile-from=")).ToString(); |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 228 | } else if (option.starts_with("--dump-output-to-fd=")) { |
| 229 | ParseUintOption(option, "--dump-output-to-fd", &dump_output_to_fd_, Usage); |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 230 | } else if (option == "--generate-boot-image-profile") { |
| 231 | generate_boot_image_profile_ = true; |
David Brazdil | f13ac7c | 2018-01-30 10:09:08 +0000 | [diff] [blame^] | 232 | } else if (option == "--skip-apk-verification") { |
| 233 | skip_apk_verification_ = true; |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 234 | } else if (option.starts_with("--boot-image-class-threshold=")) { |
| 235 | ParseUintOption(option, |
| 236 | "--boot-image-class-threshold", |
| 237 | &boot_image_options_.image_class_theshold, |
| 238 | Usage); |
| 239 | } else if (option.starts_with("--boot-image-clean-class-threshold=")) { |
| 240 | ParseUintOption(option, |
| 241 | "--boot-image-clean-class-threshold", |
| 242 | &boot_image_options_.image_class_clean_theshold, |
| 243 | Usage); |
Mathieu Chartier | 8eecddf | 2017-07-12 16:05:54 -0700 | [diff] [blame] | 244 | } else if (option.starts_with("--boot-image-sampled-method-threshold=")) { |
| 245 | ParseUintOption(option, |
| 246 | "--boot-image-sampled-method-threshold", |
| 247 | &boot_image_options_.compiled_method_threshold, |
| 248 | Usage); |
Calin Juravle | 876f350 | 2016-03-24 16:16:34 +0000 | [diff] [blame] | 249 | } else if (option.starts_with("--profile-file=")) { |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 250 | profile_files_.push_back(option.substr(strlen("--profile-file=")).ToString()); |
| 251 | } else if (option.starts_with("--profile-file-fd=")) { |
| 252 | ParseFdForCollection(option, "--profile-file-fd", &profile_files_fd_); |
| 253 | } else if (option.starts_with("--reference-profile-file=")) { |
| 254 | reference_profile_file_ = option.substr(strlen("--reference-profile-file=")).ToString(); |
| 255 | } else if (option.starts_with("--reference-profile-file-fd=")) { |
| 256 | ParseUintOption(option, "--reference-profile-file-fd", &reference_profile_file_fd_, Usage); |
David Sehr | 546d24f | 2016-06-02 10:46:19 -0700 | [diff] [blame] | 257 | } else if (option.starts_with("--dex-location=")) { |
| 258 | dex_locations_.push_back(option.substr(strlen("--dex-location=")).ToString()); |
| 259 | } else if (option.starts_with("--apk-fd=")) { |
| 260 | ParseFdForCollection(option, "--apk-fd", &apks_fd_); |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 261 | } else if (option.starts_with("--apk=")) { |
| 262 | apk_files_.push_back(option.substr(strlen("--apk=")).ToString()); |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 263 | } else if (option.starts_with("--generate-test-profile=")) { |
| 264 | test_profile_ = option.substr(strlen("--generate-test-profile=")).ToString(); |
| 265 | } else if (option.starts_with("--generate-test-profile-num-dex=")) { |
| 266 | ParseUintOption(option, |
| 267 | "--generate-test-profile-num-dex", |
| 268 | &test_profile_num_dex_, |
| 269 | Usage); |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 270 | } else if (option.starts_with("--generate-test-profile-method-percentage")) { |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 271 | ParseUintOption(option, |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 272 | "--generate-test-profile-method-percentage", |
| 273 | &test_profile_method_percerntage_, |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 274 | Usage); |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 275 | } else if (option.starts_with("--generate-test-profile-class-percentage")) { |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 276 | ParseUintOption(option, |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 277 | "--generate-test-profile-class-percentage", |
| 278 | &test_profile_class_percentage_, |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 279 | Usage); |
Jeff Hao | f0a31f8 | 2017-03-27 15:50:37 -0700 | [diff] [blame] | 280 | } else if (option.starts_with("--generate-test-profile-seed=")) { |
| 281 | ParseUintOption(option, "--generate-test-profile-seed", &test_profile_seed_, Usage); |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 282 | } else { |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 283 | Usage("Unknown argument '%s'", option.data()); |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 287 | // Validate global consistency between file/fd options. |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 288 | if (!profile_files_.empty() && !profile_files_fd_.empty()) { |
| 289 | Usage("Profile files should not be specified with both --profile-file-fd and --profile-file"); |
| 290 | } |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 291 | if (!reference_profile_file_.empty() && FdIsValid(reference_profile_file_fd_)) { |
| 292 | Usage("Reference profile should not be specified with both " |
| 293 | "--reference-profile-file-fd and --reference-profile-file"); |
| 294 | } |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 295 | if (!apk_files_.empty() && !apks_fd_.empty()) { |
| 296 | Usage("APK files should not be specified with both --apk-fd and --apk"); |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
| 300 | ProfileAssistant::ProcessingResult ProcessProfiles() { |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 301 | // Validate that at least one profile file was passed, as well as a reference profile. |
| 302 | if (profile_files_.empty() && profile_files_fd_.empty()) { |
| 303 | Usage("No profile files specified."); |
| 304 | } |
| 305 | if (reference_profile_file_.empty() && !FdIsValid(reference_profile_file_fd_)) { |
| 306 | Usage("No reference profile file specified."); |
| 307 | } |
| 308 | if ((!profile_files_.empty() && FdIsValid(reference_profile_file_fd_)) || |
| 309 | (!profile_files_fd_.empty() && !FdIsValid(reference_profile_file_fd_))) { |
| 310 | Usage("Options --profile-file-fd and --reference-profile-file-fd " |
| 311 | "should only be used together"); |
| 312 | } |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 313 | ProfileAssistant::ProcessingResult result; |
Calin Juravle | 2dba0ab | 2018-01-22 19:22:24 -0800 | [diff] [blame] | 314 | |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 315 | if (profile_files_.empty()) { |
| 316 | // The file doesn't need to be flushed here (ProcessProfiles will do it) |
| 317 | // so don't check the usage. |
| 318 | File file(reference_profile_file_fd_, false); |
Calin Juravle | 2dba0ab | 2018-01-22 19:22:24 -0800 | [diff] [blame] | 319 | result = ProfileAssistant::ProcessProfiles(profile_files_fd_, |
| 320 | reference_profile_file_fd_); |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 321 | CloseAllFds(profile_files_fd_, "profile_files_fd_"); |
| 322 | } else { |
| 323 | result = ProfileAssistant::ProcessProfiles(profile_files_, reference_profile_file_); |
| 324 | } |
| 325 | return result; |
| 326 | } |
| 327 | |
David Brazdil | f13ac7c | 2018-01-30 10:09:08 +0000 | [diff] [blame^] | 328 | bool ShouldSkipApkVerification() const { |
| 329 | return skip_apk_verification_; |
| 330 | } |
| 331 | |
Calin Juravle | 2dba0ab | 2018-01-22 19:22:24 -0800 | [diff] [blame] | 332 | void OpenApkFilesFromLocations(std::vector<std::unique_ptr<const DexFile>>* dex_files) const { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 333 | bool use_apk_fd_list = !apks_fd_.empty(); |
| 334 | if (use_apk_fd_list) { |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 335 | // Get the APKs from the collection of FDs. |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 336 | CHECK_EQ(dex_locations_.size(), apks_fd_.size()); |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 337 | } else if (!apk_files_.empty()) { |
| 338 | // Get the APKs from the collection of filenames. |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 339 | CHECK_EQ(dex_locations_.size(), apk_files_.size()); |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 340 | } else { |
| 341 | // No APKs were specified. |
| 342 | CHECK(dex_locations_.empty()); |
| 343 | return; |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 344 | } |
| 345 | static constexpr bool kVerifyChecksum = true; |
| 346 | for (size_t i = 0; i < dex_locations_.size(); ++i) { |
| 347 | std::string error_msg; |
David Sehr | 013fd80 | 2018-01-11 22:55:24 -0800 | [diff] [blame] | 348 | const ArtDexFileLoader dex_file_loader; |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 349 | std::vector<std::unique_ptr<const DexFile>> dex_files_for_location; |
| 350 | if (use_apk_fd_list) { |
David Sehr | 013fd80 | 2018-01-11 22:55:24 -0800 | [diff] [blame] | 351 | if (dex_file_loader.OpenZip(apks_fd_[i], |
| 352 | dex_locations_[i], |
David Brazdil | f13ac7c | 2018-01-30 10:09:08 +0000 | [diff] [blame^] | 353 | /* verify */ !ShouldSkipApkVerification(), |
David Sehr | 013fd80 | 2018-01-11 22:55:24 -0800 | [diff] [blame] | 354 | kVerifyChecksum, |
| 355 | &error_msg, |
| 356 | &dex_files_for_location)) { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 357 | } else { |
| 358 | LOG(WARNING) << "OpenZip failed for '" << dex_locations_[i] << "' " << error_msg; |
| 359 | continue; |
| 360 | } |
| 361 | } else { |
David Sehr | 013fd80 | 2018-01-11 22:55:24 -0800 | [diff] [blame] | 362 | if (dex_file_loader.Open(apk_files_[i].c_str(), |
| 363 | dex_locations_[i], |
David Brazdil | f13ac7c | 2018-01-30 10:09:08 +0000 | [diff] [blame^] | 364 | /* verify */ !ShouldSkipApkVerification(), |
David Sehr | 013fd80 | 2018-01-11 22:55:24 -0800 | [diff] [blame] | 365 | kVerifyChecksum, |
| 366 | &error_msg, |
| 367 | &dex_files_for_location)) { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 368 | } else { |
| 369 | LOG(WARNING) << "Open failed for '" << dex_locations_[i] << "' " << error_msg; |
| 370 | continue; |
| 371 | } |
| 372 | } |
| 373 | for (std::unique_ptr<const DexFile>& dex_file : dex_files_for_location) { |
| 374 | dex_files->emplace_back(std::move(dex_file)); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 379 | std::unique_ptr<const ProfileCompilationInfo> LoadProfile(const std::string& filename, int fd) { |
| 380 | if (!filename.empty()) { |
| 381 | fd = open(filename.c_str(), O_RDWR); |
| 382 | if (fd < 0) { |
| 383 | LOG(ERROR) << "Cannot open " << filename << strerror(errno); |
| 384 | return nullptr; |
| 385 | } |
| 386 | } |
| 387 | std::unique_ptr<ProfileCompilationInfo> info(new ProfileCompilationInfo); |
| 388 | if (!info->Load(fd)) { |
| 389 | LOG(ERROR) << "Cannot load profile info from fd=" << fd << "\n"; |
| 390 | return nullptr; |
| 391 | } |
| 392 | return info; |
| 393 | } |
| 394 | |
David Sehr | b18991b | 2017-02-08 20:58:10 -0800 | [diff] [blame] | 395 | int DumpOneProfile(const std::string& banner, |
| 396 | const std::string& filename, |
| 397 | int fd, |
| 398 | const std::vector<std::unique_ptr<const DexFile>>* dex_files, |
| 399 | std::string* dump) { |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 400 | std::unique_ptr<const ProfileCompilationInfo> info(LoadProfile(filename, fd)); |
| 401 | if (info == nullptr) { |
| 402 | LOG(ERROR) << "Cannot load profile info from filename=" << filename << " fd=" << fd; |
Calin Juravle | 876f350 | 2016-03-24 16:16:34 +0000 | [diff] [blame] | 403 | return -1; |
| 404 | } |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 405 | *dump += banner + "\n" + info->DumpInfo(dex_files) + "\n"; |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | int DumpProfileInfo() { |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 410 | // Validate that at least one profile file or reference was specified. |
| 411 | if (profile_files_.empty() && profile_files_fd_.empty() && |
| 412 | reference_profile_file_.empty() && !FdIsValid(reference_profile_file_fd_)) { |
| 413 | Usage("No profile files or reference profile specified."); |
| 414 | } |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 415 | static const char* kEmptyString = ""; |
David Sehr | 546d24f | 2016-06-02 10:46:19 -0700 | [diff] [blame] | 416 | static const char* kOrdinaryProfile = "=== profile ==="; |
| 417 | static const char* kReferenceProfile = "=== reference profile ==="; |
| 418 | |
| 419 | // Open apk/zip files and and read dex files. |
| 420 | MemMap::Init(); // for ZipArchive::OpenFromFd |
David Sehr | b18991b | 2017-02-08 20:58:10 -0800 | [diff] [blame] | 421 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 422 | OpenApkFilesFromLocations(&dex_files); |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 423 | std::string dump; |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 424 | // Dump individual profile files. |
| 425 | if (!profile_files_fd_.empty()) { |
| 426 | for (int profile_file_fd : profile_files_fd_) { |
David Sehr | 546d24f | 2016-06-02 10:46:19 -0700 | [diff] [blame] | 427 | int ret = DumpOneProfile(kOrdinaryProfile, |
| 428 | kEmptyString, |
| 429 | profile_file_fd, |
| 430 | &dex_files, |
| 431 | &dump); |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 432 | if (ret != 0) { |
| 433 | return ret; |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | if (!profile_files_.empty()) { |
| 438 | for (const std::string& profile_file : profile_files_) { |
David Sehr | 546d24f | 2016-06-02 10:46:19 -0700 | [diff] [blame] | 439 | int ret = DumpOneProfile(kOrdinaryProfile, profile_file, kInvalidFd, &dex_files, &dump); |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 440 | if (ret != 0) { |
| 441 | return ret; |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | // Dump reference profile file. |
| 446 | if (FdIsValid(reference_profile_file_fd_)) { |
David Sehr | 546d24f | 2016-06-02 10:46:19 -0700 | [diff] [blame] | 447 | int ret = DumpOneProfile(kReferenceProfile, |
| 448 | kEmptyString, |
| 449 | reference_profile_file_fd_, |
| 450 | &dex_files, |
| 451 | &dump); |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 452 | if (ret != 0) { |
| 453 | return ret; |
| 454 | } |
| 455 | } |
| 456 | if (!reference_profile_file_.empty()) { |
David Sehr | 546d24f | 2016-06-02 10:46:19 -0700 | [diff] [blame] | 457 | int ret = DumpOneProfile(kReferenceProfile, |
| 458 | reference_profile_file_, |
| 459 | kInvalidFd, |
| 460 | &dex_files, |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 461 | &dump); |
| 462 | if (ret != 0) { |
| 463 | return ret; |
| 464 | } |
| 465 | } |
| 466 | if (!FdIsValid(dump_output_to_fd_)) { |
| 467 | std::cout << dump; |
| 468 | } else { |
| 469 | unix_file::FdFile out_fd(dump_output_to_fd_, false /*check_usage*/); |
| 470 | if (!out_fd.WriteFully(dump.c_str(), dump.length())) { |
| 471 | return -1; |
| 472 | } |
| 473 | } |
Calin Juravle | 876f350 | 2016-03-24 16:16:34 +0000 | [diff] [blame] | 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | bool ShouldOnlyDumpProfile() { |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 478 | return dump_only_; |
Calin Juravle | 876f350 | 2016-03-24 16:16:34 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 481 | bool GetClassNamesAndMethods(int fd, |
| 482 | std::vector<std::unique_ptr<const DexFile>>* dex_files, |
| 483 | std::set<std::string>* out_lines) { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 484 | ProfileCompilationInfo profile_info; |
| 485 | if (!profile_info.Load(fd)) { |
| 486 | LOG(ERROR) << "Cannot load profile info"; |
| 487 | return false; |
| 488 | } |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 489 | for (const std::unique_ptr<const DexFile>& dex_file : *dex_files) { |
| 490 | std::set<dex::TypeIndex> class_types; |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 491 | std::set<uint16_t> hot_methods; |
| 492 | std::set<uint16_t> startup_methods; |
| 493 | std::set<uint16_t> post_startup_methods; |
| 494 | std::set<uint16_t> combined_methods; |
| 495 | if (profile_info.GetClassesAndMethods(*dex_file.get(), |
| 496 | &class_types, |
| 497 | &hot_methods, |
| 498 | &startup_methods, |
| 499 | &post_startup_methods)) { |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 500 | for (const dex::TypeIndex& type_index : class_types) { |
| 501 | const DexFile::TypeId& type_id = dex_file->GetTypeId(type_index); |
| 502 | out_lines->insert(std::string(dex_file->GetTypeDescriptor(type_id))); |
| 503 | } |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 504 | combined_methods = hot_methods; |
| 505 | combined_methods.insert(startup_methods.begin(), startup_methods.end()); |
| 506 | combined_methods.insert(post_startup_methods.begin(), post_startup_methods.end()); |
| 507 | for (uint16_t dex_method_idx : combined_methods) { |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 508 | const DexFile::MethodId& id = dex_file->GetMethodId(dex_method_idx); |
| 509 | std::string signature_string(dex_file->GetMethodSignature(id).ToString()); |
| 510 | std::string type_string(dex_file->GetTypeDescriptor(dex_file->GetTypeId(id.class_idx_))); |
| 511 | std::string method_name(dex_file->GetMethodName(id)); |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 512 | std::string flags_string; |
| 513 | if (hot_methods.find(dex_method_idx) != hot_methods.end()) { |
| 514 | flags_string += kMethodFlagStringHot; |
| 515 | } |
| 516 | if (startup_methods.find(dex_method_idx) != startup_methods.end()) { |
| 517 | flags_string += kMethodFlagStringStartup; |
| 518 | } |
| 519 | if (post_startup_methods.find(dex_method_idx) != post_startup_methods.end()) { |
| 520 | flags_string += kMethodFlagStringPostStartup; |
| 521 | } |
| 522 | out_lines->insert(flags_string + |
| 523 | type_string + |
| 524 | kMethodSep + |
| 525 | method_name + |
| 526 | signature_string); |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | } |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 530 | return true; |
| 531 | } |
| 532 | |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 533 | bool GetClassNamesAndMethods(const std::string& profile_file, |
| 534 | std::vector<std::unique_ptr<const DexFile>>* dex_files, |
| 535 | std::set<std::string>* out_lines) { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 536 | int fd = open(profile_file.c_str(), O_RDONLY); |
| 537 | if (!FdIsValid(fd)) { |
| 538 | LOG(ERROR) << "Cannot open " << profile_file << strerror(errno); |
| 539 | return false; |
| 540 | } |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 541 | if (!GetClassNamesAndMethods(fd, dex_files, out_lines)) { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 542 | return false; |
| 543 | } |
| 544 | if (close(fd) < 0) { |
| 545 | PLOG(WARNING) << "Failed to close descriptor"; |
| 546 | } |
| 547 | return true; |
| 548 | } |
| 549 | |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 550 | int DumpClassesAndMethods() { |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 551 | // Validate that at least one profile file or reference was specified. |
| 552 | if (profile_files_.empty() && profile_files_fd_.empty() && |
| 553 | reference_profile_file_.empty() && !FdIsValid(reference_profile_file_fd_)) { |
| 554 | Usage("No profile files or reference profile specified."); |
| 555 | } |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 556 | // Open apk/zip files and and read dex files. |
| 557 | MemMap::Init(); // for ZipArchive::OpenFromFd |
| 558 | // Open the dex files to get the names for classes. |
| 559 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 560 | OpenApkFilesFromLocations(&dex_files); |
| 561 | // Build a vector of class names from individual profile files. |
| 562 | std::set<std::string> class_names; |
| 563 | if (!profile_files_fd_.empty()) { |
| 564 | for (int profile_file_fd : profile_files_fd_) { |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 565 | if (!GetClassNamesAndMethods(profile_file_fd, &dex_files, &class_names)) { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 566 | return -1; |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | if (!profile_files_.empty()) { |
| 571 | for (const std::string& profile_file : profile_files_) { |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 572 | if (!GetClassNamesAndMethods(profile_file, &dex_files, &class_names)) { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 573 | return -1; |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | // Concatenate class names from reference profile file. |
| 578 | if (FdIsValid(reference_profile_file_fd_)) { |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 579 | if (!GetClassNamesAndMethods(reference_profile_file_fd_, &dex_files, &class_names)) { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 580 | return -1; |
| 581 | } |
| 582 | } |
| 583 | if (!reference_profile_file_.empty()) { |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 584 | if (!GetClassNamesAndMethods(reference_profile_file_, &dex_files, &class_names)) { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 585 | return -1; |
| 586 | } |
| 587 | } |
| 588 | // Dump the class names. |
| 589 | std::string dump; |
| 590 | for (const std::string& class_name : class_names) { |
| 591 | dump += class_name + std::string("\n"); |
| 592 | } |
| 593 | if (!FdIsValid(dump_output_to_fd_)) { |
| 594 | std::cout << dump; |
| 595 | } else { |
| 596 | unix_file::FdFile out_fd(dump_output_to_fd_, false /*check_usage*/); |
| 597 | if (!out_fd.WriteFully(dump.c_str(), dump.length())) { |
| 598 | return -1; |
| 599 | } |
| 600 | } |
| 601 | return 0; |
| 602 | } |
| 603 | |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 604 | bool ShouldOnlyDumpClassesAndMethods() { |
| 605 | return dump_classes_and_methods_; |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | // Read lines from the given file, dropping comments and empty lines. Post-process each line with |
| 609 | // the given function. |
| 610 | template <typename T> |
| 611 | static T* ReadCommentedInputFromFile( |
| 612 | const char* input_filename, std::function<std::string(const char*)>* process) { |
| 613 | std::unique_ptr<std::ifstream> input_file(new std::ifstream(input_filename, std::ifstream::in)); |
| 614 | if (input_file.get() == nullptr) { |
| 615 | LOG(ERROR) << "Failed to open input file " << input_filename; |
| 616 | return nullptr; |
| 617 | } |
| 618 | std::unique_ptr<T> result( |
| 619 | ReadCommentedInputStream<T>(*input_file, process)); |
| 620 | input_file->close(); |
| 621 | return result.release(); |
| 622 | } |
| 623 | |
| 624 | // Read lines from the given stream, dropping comments and empty lines. Post-process each line |
| 625 | // with the given function. |
| 626 | template <typename T> |
| 627 | static T* ReadCommentedInputStream( |
| 628 | std::istream& in_stream, |
| 629 | std::function<std::string(const char*)>* process) { |
| 630 | std::unique_ptr<T> output(new T()); |
| 631 | while (in_stream.good()) { |
| 632 | std::string dot; |
| 633 | std::getline(in_stream, dot); |
| 634 | if (android::base::StartsWith(dot, "#") || dot.empty()) { |
| 635 | continue; |
| 636 | } |
| 637 | if (process != nullptr) { |
| 638 | std::string descriptor((*process)(dot.c_str())); |
| 639 | output->insert(output->end(), descriptor); |
| 640 | } else { |
| 641 | output->insert(output->end(), dot); |
| 642 | } |
| 643 | } |
| 644 | return output.release(); |
| 645 | } |
| 646 | |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 647 | // Find class klass_descriptor in the given dex_files and store its reference |
| 648 | // in the out parameter class_ref. |
| 649 | // Return true if the definition of the class was found in any of the dex_files. |
| 650 | bool FindClass(const std::vector<std::unique_ptr<const DexFile>>& dex_files, |
| 651 | const std::string& klass_descriptor, |
Mathieu Chartier | dbddc22 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 652 | /*out*/TypeReference* class_ref) { |
Calin Juravle | 0855688 | 2017-05-26 16:40:45 -0700 | [diff] [blame] | 653 | constexpr uint16_t kInvalidTypeIndex = std::numeric_limits<uint16_t>::max() - 1; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 654 | for (const std::unique_ptr<const DexFile>& dex_file_ptr : dex_files) { |
| 655 | const DexFile* dex_file = dex_file_ptr.get(); |
Calin Juravle | 0855688 | 2017-05-26 16:40:45 -0700 | [diff] [blame] | 656 | if (klass_descriptor == kInvalidClassDescriptor) { |
| 657 | if (kInvalidTypeIndex >= dex_file->NumTypeIds()) { |
| 658 | // The dex file does not contain all possible type ids which leaves us room |
| 659 | // to add an "invalid" type id. |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 660 | *class_ref = TypeReference(dex_file, dex::TypeIndex(kInvalidTypeIndex)); |
Calin Juravle | 0855688 | 2017-05-26 16:40:45 -0700 | [diff] [blame] | 661 | return true; |
| 662 | } else { |
| 663 | // The dex file contains all possible type ids. We don't have any free type id |
| 664 | // that we can use as invalid. |
| 665 | continue; |
| 666 | } |
| 667 | } |
| 668 | |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 669 | const DexFile::TypeId* type_id = dex_file->FindTypeId(klass_descriptor.c_str()); |
| 670 | if (type_id == nullptr) { |
| 671 | continue; |
| 672 | } |
| 673 | dex::TypeIndex type_index = dex_file->GetIndexForTypeId(*type_id); |
| 674 | if (dex_file->FindClassDef(type_index) == nullptr) { |
| 675 | // Class is only referenced in the current dex file but not defined in it. |
| 676 | continue; |
| 677 | } |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 678 | *class_ref = TypeReference(dex_file, type_index); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 679 | return true; |
| 680 | } |
| 681 | return false; |
| 682 | } |
| 683 | |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 684 | // Find the method specified by method_spec in the class class_ref. |
Calin Juravle | 0855688 | 2017-05-26 16:40:45 -0700 | [diff] [blame] | 685 | uint32_t FindMethodIndex(const TypeReference& class_ref, |
| 686 | const std::string& method_spec) { |
| 687 | const DexFile* dex_file = class_ref.dex_file; |
| 688 | if (method_spec == kInvalidMethod) { |
| 689 | constexpr uint16_t kInvalidMethodIndex = std::numeric_limits<uint16_t>::max() - 1; |
| 690 | return kInvalidMethodIndex >= dex_file->NumMethodIds() |
| 691 | ? kInvalidMethodIndex |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 692 | : dex::kDexNoIndex; |
Calin Juravle | 0855688 | 2017-05-26 16:40:45 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 695 | std::vector<std::string> name_and_signature; |
| 696 | Split(method_spec, kProfileParsingFirstCharInSignature, &name_and_signature); |
| 697 | if (name_and_signature.size() != 2) { |
| 698 | LOG(ERROR) << "Invalid method name and signature " << method_spec; |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 699 | return dex::kDexNoIndex; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 700 | } |
Calin Juravle | 0855688 | 2017-05-26 16:40:45 -0700 | [diff] [blame] | 701 | |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 702 | const std::string& name = name_and_signature[0]; |
| 703 | const std::string& signature = kProfileParsingFirstCharInSignature + name_and_signature[1]; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 704 | |
| 705 | const DexFile::StringId* name_id = dex_file->FindStringId(name.c_str()); |
| 706 | if (name_id == nullptr) { |
Mathieu Chartier | 66aae3b | 2017-05-18 10:38:28 -0700 | [diff] [blame] | 707 | LOG(WARNING) << "Could not find name: " << name; |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 708 | return dex::kDexNoIndex; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 709 | } |
| 710 | dex::TypeIndex return_type_idx; |
| 711 | std::vector<dex::TypeIndex> param_type_idxs; |
| 712 | if (!dex_file->CreateTypeList(signature, &return_type_idx, ¶m_type_idxs)) { |
Mathieu Chartier | 66aae3b | 2017-05-18 10:38:28 -0700 | [diff] [blame] | 713 | LOG(WARNING) << "Could not create type list" << signature; |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 714 | return dex::kDexNoIndex; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 715 | } |
| 716 | const DexFile::ProtoId* proto_id = dex_file->FindProtoId(return_type_idx, param_type_idxs); |
| 717 | if (proto_id == nullptr) { |
Mathieu Chartier | 66aae3b | 2017-05-18 10:38:28 -0700 | [diff] [blame] | 718 | LOG(WARNING) << "Could not find proto_id: " << name; |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 719 | return dex::kDexNoIndex; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 720 | } |
| 721 | const DexFile::MethodId* method_id = dex_file->FindMethodId( |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 722 | dex_file->GetTypeId(class_ref.TypeIndex()), *name_id, *proto_id); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 723 | if (method_id == nullptr) { |
Mathieu Chartier | 66aae3b | 2017-05-18 10:38:28 -0700 | [diff] [blame] | 724 | LOG(WARNING) << "Could not find method_id: " << name; |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 725 | return dex::kDexNoIndex; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 726 | } |
| 727 | |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 728 | return dex_file->GetIndexForMethodId(*method_id); |
| 729 | } |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 730 | |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 731 | // Given a method, return true if the method has a single INVOKE_VIRTUAL in its byte code. |
| 732 | // Upon success it returns true and stores the method index and the invoke dex pc |
| 733 | // in the output parameters. |
| 734 | // The format of the method spec is "inlinePolymorphic(LSuper;)I+LSubA;,LSubB;,LSubC;". |
| 735 | // |
| 736 | // TODO(calin): support INVOKE_INTERFACE and the range variants. |
Mathieu Chartier | dbddc22 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 737 | bool HasSingleInvoke(const TypeReference& class_ref, |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 738 | uint16_t method_index, |
| 739 | /*out*/uint32_t* dex_pc) { |
| 740 | const DexFile* dex_file = class_ref.dex_file; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 741 | uint32_t offset = dex_file->FindCodeItemOffset( |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 742 | *dex_file->FindClassDef(class_ref.TypeIndex()), |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 743 | method_index); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 744 | const DexFile::CodeItem* code_item = dex_file->GetCodeItem(offset); |
| 745 | |
| 746 | bool found_invoke = false; |
Mathieu Chartier | 698ebbc | 2018-01-05 11:00:42 -0800 | [diff] [blame] | 747 | for (const DexInstructionPcPair& inst : CodeItemInstructionAccessor(*dex_file, code_item)) { |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 748 | if (inst->Opcode() == Instruction::INVOKE_VIRTUAL) { |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 749 | if (found_invoke) { |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 750 | LOG(ERROR) << "Multiple invoke INVOKE_VIRTUAL found: " |
| 751 | << dex_file->PrettyMethod(method_index); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 752 | return false; |
| 753 | } |
| 754 | found_invoke = true; |
Mathieu Chartier | 0021feb | 2017-11-07 00:08:52 -0800 | [diff] [blame] | 755 | *dex_pc = inst.DexPc(); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | if (!found_invoke) { |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 759 | LOG(ERROR) << "Could not find any INVOKE_VIRTUAL: " << dex_file->PrettyMethod(method_index); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 760 | } |
| 761 | return found_invoke; |
| 762 | } |
| 763 | |
| 764 | // Process a line defining a class or a method and its inline caches. |
| 765 | // Upon success return true and add the class or the method info to profile. |
Calin Juravle | 589e71e | 2017-03-03 16:05:05 -0800 | [diff] [blame] | 766 | // The possible line formats are: |
| 767 | // "LJustTheCass;". |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 768 | // "LTestInline;->inlinePolymorphic(LSuper;)I+LSubA;,LSubB;,LSubC;". |
Calin Juravle | 0855688 | 2017-05-26 16:40:45 -0700 | [diff] [blame] | 769 | // "LTestInline;->inlinePolymorphic(LSuper;)I+LSubA;,LSubB;,invalid_class". |
Calin Juravle | 589e71e | 2017-03-03 16:05:05 -0800 | [diff] [blame] | 770 | // "LTestInline;->inlineMissingTypes(LSuper;)I+missing_types". |
| 771 | // "LTestInline;->inlineNoInlineCaches(LSuper;)I". |
Mathieu Chartier | d808e8b | 2017-03-21 13:37:41 -0700 | [diff] [blame] | 772 | // "LTestInline;->*". |
Calin Juravle | 0855688 | 2017-05-26 16:40:45 -0700 | [diff] [blame] | 773 | // "invalid_class". |
| 774 | // "LTestInline;->invalid_method". |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 775 | // The method and classes are searched only in the given dex files. |
| 776 | bool ProcessLine(const std::vector<std::unique_ptr<const DexFile>>& dex_files, |
| 777 | const std::string& line, |
| 778 | /*out*/ProfileCompilationInfo* profile) { |
| 779 | std::string klass; |
| 780 | std::string method_str; |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 781 | bool is_hot = false; |
| 782 | bool is_startup = false; |
| 783 | bool is_post_startup = false; |
| 784 | const size_t method_sep_index = line.find(kMethodSep, 0); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 785 | if (method_sep_index == std::string::npos) { |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 786 | klass = line.substr(0); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 787 | } else { |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 788 | // The method prefix flags are only valid for method strings. |
| 789 | size_t start_index = 0; |
| 790 | while (start_index < line.size() && line[start_index] != 'L') { |
| 791 | const char c = line[start_index]; |
| 792 | if (c == kMethodFlagStringHot) { |
| 793 | is_hot = true; |
| 794 | } else if (c == kMethodFlagStringStartup) { |
| 795 | is_startup = true; |
| 796 | } else if (c == kMethodFlagStringPostStartup) { |
| 797 | is_post_startup = true; |
| 798 | } else { |
| 799 | LOG(WARNING) << "Invalid flag " << c; |
| 800 | return false; |
| 801 | } |
| 802 | ++start_index; |
| 803 | } |
| 804 | klass = line.substr(start_index, method_sep_index - start_index); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 805 | method_str = line.substr(method_sep_index + kMethodSep.size()); |
| 806 | } |
| 807 | |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 808 | TypeReference class_ref(/* dex_file */ nullptr, dex::TypeIndex()); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 809 | if (!FindClass(dex_files, klass, &class_ref)) { |
Mathieu Chartier | 3f12134 | 2017-03-06 11:16:20 -0800 | [diff] [blame] | 810 | LOG(WARNING) << "Could not find class: " << klass; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 811 | return false; |
| 812 | } |
| 813 | |
Mathieu Chartier | d808e8b | 2017-03-21 13:37:41 -0700 | [diff] [blame] | 814 | if (method_str.empty() || method_str == kClassAllMethods) { |
| 815 | // Start by adding the class. |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 816 | std::set<DexCacheResolvedClasses> resolved_class_set; |
| 817 | const DexFile* dex_file = class_ref.dex_file; |
| 818 | const auto& dex_resolved_classes = resolved_class_set.emplace( |
| 819 | dex_file->GetLocation(), |
Mathieu Chartier | 79c87da | 2017-10-10 11:54:29 -0700 | [diff] [blame] | 820 | DexFileLoader::GetBaseLocation(dex_file->GetLocation()), |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 821 | dex_file->GetLocationChecksum(), |
| 822 | dex_file->NumMethodIds()); |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 823 | dex_resolved_classes.first->AddClass(class_ref.TypeIndex()); |
Mathieu Chartier | d808e8b | 2017-03-21 13:37:41 -0700 | [diff] [blame] | 824 | std::vector<ProfileMethodInfo> methods; |
| 825 | if (method_str == kClassAllMethods) { |
| 826 | // Add all of the methods. |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 827 | const DexFile::ClassDef* class_def = dex_file->FindClassDef(class_ref.TypeIndex()); |
Mathieu Chartier | d808e8b | 2017-03-21 13:37:41 -0700 | [diff] [blame] | 828 | const uint8_t* class_data = dex_file->GetClassData(*class_def); |
| 829 | if (class_data != nullptr) { |
| 830 | ClassDataItemIterator it(*dex_file, class_data); |
Mathieu Chartier | e17cf24 | 2017-06-19 11:05:51 -0700 | [diff] [blame] | 831 | it.SkipAllFields(); |
Mathieu Chartier | b7c273c | 2017-11-10 18:07:56 -0800 | [diff] [blame] | 832 | while (it.HasNextMethod()) { |
Mathieu Chartier | d808e8b | 2017-03-21 13:37:41 -0700 | [diff] [blame] | 833 | if (it.GetMethodCodeItemOffset() != 0) { |
| 834 | // Add all of the methods that have code to the profile. |
| 835 | const uint32_t method_idx = it.GetMemberIndex(); |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 836 | methods.push_back(ProfileMethodInfo(MethodReference(dex_file, method_idx))); |
Mathieu Chartier | d808e8b | 2017-03-21 13:37:41 -0700 | [diff] [blame] | 837 | } |
| 838 | it.Next(); |
| 839 | } |
| 840 | } |
| 841 | } |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 842 | // TODO: Check return values? |
| 843 | profile->AddMethods(methods); |
| 844 | profile->AddClasses(resolved_class_set); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 845 | return true; |
| 846 | } |
| 847 | |
| 848 | // Process the method. |
| 849 | std::string method_spec; |
| 850 | std::vector<std::string> inline_cache_elems; |
| 851 | |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 852 | // If none of the flags are set, default to hot. |
| 853 | is_hot = is_hot || (!is_hot && !is_startup && !is_post_startup); |
| 854 | |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 855 | std::vector<std::string> method_elems; |
Calin Juravle | 589e71e | 2017-03-03 16:05:05 -0800 | [diff] [blame] | 856 | bool is_missing_types = false; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 857 | Split(method_str, kProfileParsingInlineChacheSep, &method_elems); |
| 858 | if (method_elems.size() == 2) { |
| 859 | method_spec = method_elems[0]; |
Calin Juravle | 589e71e | 2017-03-03 16:05:05 -0800 | [diff] [blame] | 860 | is_missing_types = method_elems[1] == kMissingTypesMarker; |
| 861 | if (!is_missing_types) { |
| 862 | Split(method_elems[1], kProfileParsingTypeSep, &inline_cache_elems); |
| 863 | } |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 864 | } else if (method_elems.size() == 1) { |
| 865 | method_spec = method_elems[0]; |
| 866 | } else { |
| 867 | LOG(ERROR) << "Invalid method line: " << line; |
| 868 | return false; |
| 869 | } |
| 870 | |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 871 | const uint32_t method_index = FindMethodIndex(class_ref, method_spec); |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 872 | if (method_index == dex::kDexNoIndex) { |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 873 | return false; |
| 874 | } |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 875 | |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 876 | std::vector<ProfileMethodInfo::ProfileInlineCache> inline_caches; |
| 877 | if (is_missing_types || !inline_cache_elems.empty()) { |
| 878 | uint32_t dex_pc; |
| 879 | if (!HasSingleInvoke(class_ref, method_index, &dex_pc)) { |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 880 | return false; |
| 881 | } |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 882 | std::vector<TypeReference> classes(inline_cache_elems.size(), |
| 883 | TypeReference(/* dex_file */ nullptr, dex::TypeIndex())); |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 884 | size_t class_it = 0; |
| 885 | for (const std::string& ic_class : inline_cache_elems) { |
| 886 | if (!FindClass(dex_files, ic_class, &(classes[class_it++]))) { |
| 887 | LOG(ERROR) << "Could not find class: " << ic_class; |
| 888 | return false; |
| 889 | } |
| 890 | } |
| 891 | inline_caches.emplace_back(dex_pc, is_missing_types, classes); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 892 | } |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 893 | MethodReference ref(class_ref.dex_file, method_index); |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 894 | if (is_hot) { |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 895 | profile->AddMethod(ProfileMethodInfo(ref, inline_caches)); |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 896 | } |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 897 | uint32_t flags = 0; |
| 898 | using Hotness = ProfileCompilationInfo::MethodHotness; |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 899 | if (is_startup) { |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 900 | flags |= Hotness::kFlagStartup; |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 901 | } |
| 902 | if (is_post_startup) { |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 903 | flags |= Hotness::kFlagPostStartup; |
| 904 | } |
| 905 | if (flags != 0) { |
| 906 | if (!profile->AddMethodIndex(static_cast<Hotness::Flag>(flags), ref)) { |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 907 | return false; |
| 908 | } |
Mathieu Chartier | e46f3a8 | 2017-06-19 19:54:12 -0700 | [diff] [blame] | 909 | DCHECK(profile->GetMethodHotness(ref).IsInProfile()); |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 910 | } |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 911 | return true; |
| 912 | } |
| 913 | |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 914 | int OpenReferenceProfile() const { |
| 915 | int fd = reference_profile_file_fd_; |
| 916 | if (!FdIsValid(fd)) { |
| 917 | CHECK(!reference_profile_file_.empty()); |
| 918 | fd = open(reference_profile_file_.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0644); |
| 919 | if (fd < 0) { |
| 920 | LOG(ERROR) << "Cannot open " << reference_profile_file_ << strerror(errno); |
| 921 | return kInvalidFd; |
| 922 | } |
| 923 | } |
| 924 | return fd; |
| 925 | } |
| 926 | |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 927 | // Creates a profile from a human friendly textual representation. |
| 928 | // The expected input format is: |
| 929 | // # Classes |
| 930 | // Ljava/lang/Comparable; |
| 931 | // Ljava/lang/Math; |
| 932 | // # Methods with inline caches |
| 933 | // LTestInline;->inlinePolymorphic(LSuper;)I+LSubA;,LSubB;,LSubC; |
| 934 | // LTestInline;->noInlineCache(LSuper;)I |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 935 | int CreateProfile() { |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 936 | // Validate parameters for this command. |
| 937 | if (apk_files_.empty() && apks_fd_.empty()) { |
| 938 | Usage("APK files must be specified"); |
| 939 | } |
| 940 | if (dex_locations_.empty()) { |
| 941 | Usage("DEX locations must be specified"); |
| 942 | } |
| 943 | if (reference_profile_file_.empty() && !FdIsValid(reference_profile_file_fd_)) { |
| 944 | Usage("Reference profile must be specified with --reference-profile-file or " |
| 945 | "--reference-profile-file-fd"); |
| 946 | } |
| 947 | if (!profile_files_.empty() || !profile_files_fd_.empty()) { |
| 948 | Usage("Profile must be specified with --reference-profile-file or " |
| 949 | "--reference-profile-file-fd"); |
| 950 | } |
| 951 | // for ZipArchive::OpenFromFd |
| 952 | MemMap::Init(); |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 953 | // Open the profile output file if needed. |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 954 | int fd = OpenReferenceProfile(); |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 955 | if (!FdIsValid(fd)) { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 956 | return -1; |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 957 | } |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 958 | // Read the user-specified list of classes and methods. |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 959 | std::unique_ptr<std::unordered_set<std::string>> |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 960 | user_lines(ReadCommentedInputFromFile<std::unordered_set<std::string>>( |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 961 | create_profile_from_file_.c_str(), nullptr)); // No post-processing. |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 962 | |
| 963 | // Open the dex files to look up classes and methods. |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 964 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 965 | OpenApkFilesFromLocations(&dex_files); |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 966 | |
| 967 | // Process the lines one by one and add the successful ones to the profile. |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 968 | ProfileCompilationInfo info; |
Calin Juravle | e0ac115 | 2017-02-13 19:03:47 -0800 | [diff] [blame] | 969 | |
| 970 | for (const auto& line : *user_lines) { |
| 971 | ProcessLine(dex_files, line, &info); |
| 972 | } |
| 973 | |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 974 | // Write the profile file. |
| 975 | CHECK(info.Save(fd)); |
| 976 | if (close(fd) < 0) { |
| 977 | PLOG(WARNING) << "Failed to close descriptor"; |
| 978 | } |
| 979 | return 0; |
| 980 | } |
| 981 | |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 982 | bool ShouldCreateBootProfile() const { |
| 983 | return generate_boot_image_profile_; |
| 984 | } |
| 985 | |
| 986 | int CreateBootProfile() { |
| 987 | // Initialize memmap since it's required to open dex files. |
| 988 | MemMap::Init(); |
| 989 | // Open the profile output file. |
| 990 | const int reference_fd = OpenReferenceProfile(); |
| 991 | if (!FdIsValid(reference_fd)) { |
| 992 | PLOG(ERROR) << "Error opening reference profile"; |
| 993 | return -1; |
| 994 | } |
| 995 | // Open the dex files. |
| 996 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 997 | OpenApkFilesFromLocations(&dex_files); |
| 998 | if (dex_files.empty()) { |
| 999 | PLOG(ERROR) << "Expected dex files for creating boot profile"; |
| 1000 | return -2; |
| 1001 | } |
| 1002 | // Open the input profiles. |
| 1003 | std::vector<std::unique_ptr<const ProfileCompilationInfo>> profiles; |
| 1004 | if (!profile_files_fd_.empty()) { |
| 1005 | for (int profile_file_fd : profile_files_fd_) { |
| 1006 | std::unique_ptr<const ProfileCompilationInfo> profile(LoadProfile("", profile_file_fd)); |
| 1007 | if (profile == nullptr) { |
| 1008 | return -3; |
| 1009 | } |
| 1010 | profiles.emplace_back(std::move(profile)); |
| 1011 | } |
| 1012 | } |
| 1013 | if (!profile_files_.empty()) { |
| 1014 | for (const std::string& profile_file : profile_files_) { |
| 1015 | std::unique_ptr<const ProfileCompilationInfo> profile(LoadProfile(profile_file, kInvalidFd)); |
| 1016 | if (profile == nullptr) { |
| 1017 | return -4; |
| 1018 | } |
| 1019 | profiles.emplace_back(std::move(profile)); |
| 1020 | } |
| 1021 | } |
| 1022 | ProfileCompilationInfo out_profile; |
| 1023 | GenerateBootImageProfile(dex_files, |
| 1024 | profiles, |
| 1025 | boot_image_options_, |
| 1026 | VLOG_IS_ON(profiler), |
| 1027 | &out_profile); |
| 1028 | out_profile.Save(reference_fd); |
| 1029 | close(reference_fd); |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 1033 | bool ShouldCreateProfile() { |
| 1034 | return !create_profile_from_file_.empty(); |
| 1035 | } |
| 1036 | |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 1037 | int GenerateTestProfile() { |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 1038 | // Validate parameters for this command. |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 1039 | if (test_profile_method_percerntage_ > 100) { |
| 1040 | Usage("Invalid percentage for --generate-test-profile-method-percentage"); |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 1041 | } |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 1042 | if (test_profile_class_percentage_ > 100) { |
| 1043 | Usage("Invalid percentage for --generate-test-profile-class-percentage"); |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 1044 | } |
Jeff Hao | f0a31f8 | 2017-03-27 15:50:37 -0700 | [diff] [blame] | 1045 | // If given APK files or DEX locations, check that they're ok. |
| 1046 | if (!apk_files_.empty() || !apks_fd_.empty() || !dex_locations_.empty()) { |
| 1047 | if (apk_files_.empty() && apks_fd_.empty()) { |
| 1048 | Usage("APK files must be specified when passing DEX locations to --generate-test-profile"); |
| 1049 | } |
| 1050 | if (dex_locations_.empty()) { |
| 1051 | Usage("DEX locations must be specified when passing APK files to --generate-test-profile"); |
| 1052 | } |
| 1053 | } |
David Sehr | 153da0e | 2017-02-15 08:54:51 -0800 | [diff] [blame] | 1054 | // ShouldGenerateTestProfile confirms !test_profile_.empty(). |
George Burgess IV | 71f7726 | 2016-10-25 13:08:17 -0700 | [diff] [blame] | 1055 | int profile_test_fd = open(test_profile_.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0644); |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 1056 | if (profile_test_fd < 0) { |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 1057 | LOG(ERROR) << "Cannot open " << test_profile_ << strerror(errno); |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 1058 | return -1; |
| 1059 | } |
Jeff Hao | f0a31f8 | 2017-03-27 15:50:37 -0700 | [diff] [blame] | 1060 | bool result; |
| 1061 | if (apk_files_.empty() && apks_fd_.empty() && dex_locations_.empty()) { |
| 1062 | result = ProfileCompilationInfo::GenerateTestProfile(profile_test_fd, |
| 1063 | test_profile_num_dex_, |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 1064 | test_profile_method_percerntage_, |
| 1065 | test_profile_class_percentage_, |
Jeff Hao | f0a31f8 | 2017-03-27 15:50:37 -0700 | [diff] [blame] | 1066 | test_profile_seed_); |
| 1067 | } else { |
| 1068 | // Initialize MemMap for ZipArchive::OpenFromFd. |
| 1069 | MemMap::Init(); |
| 1070 | // Open the dex files to look up classes and methods. |
| 1071 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1072 | OpenApkFilesFromLocations(&dex_files); |
| 1073 | // Create a random profile file based on the set of dex files. |
| 1074 | result = ProfileCompilationInfo::GenerateTestProfile(profile_test_fd, |
| 1075 | dex_files, |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 1076 | test_profile_method_percerntage_, |
| 1077 | test_profile_class_percentage_, |
Jeff Hao | f0a31f8 | 2017-03-27 15:50:37 -0700 | [diff] [blame] | 1078 | test_profile_seed_); |
| 1079 | } |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 1080 | close(profile_test_fd); // ignore close result. |
| 1081 | return result ? 0 : -1; |
| 1082 | } |
| 1083 | |
| 1084 | bool ShouldGenerateTestProfile() { |
| 1085 | return !test_profile_.empty(); |
| 1086 | } |
| 1087 | |
Calin Juravle | 2dba0ab | 2018-01-22 19:22:24 -0800 | [diff] [blame] | 1088 | bool ShouldCopyAndUpdateProfileKey() const { |
| 1089 | return copy_and_update_profile_key_; |
| 1090 | } |
| 1091 | |
| 1092 | bool CopyAndUpdateProfileKey() const { |
| 1093 | // Validate that at least one profile file was passed, as well as a reference profile. |
| 1094 | if (!(profile_files_.size() == 1 ^ profile_files_fd_.size() == 1)) { |
| 1095 | Usage("Only one profile file should be specified."); |
| 1096 | } |
| 1097 | if (reference_profile_file_.empty() && !FdIsValid(reference_profile_file_fd_)) { |
| 1098 | Usage("No reference profile file specified."); |
| 1099 | } |
| 1100 | |
| 1101 | if (apk_files_.empty() && apks_fd_.empty()) { |
| 1102 | Usage("No apk files specified"); |
| 1103 | } |
| 1104 | |
| 1105 | bool use_fds = profile_files_fd_.size() == 1; |
| 1106 | |
| 1107 | ProfileCompilationInfo profile; |
| 1108 | // Do not clear if invalid. The input might be an archive. |
| 1109 | if (profile.Load(profile_files_[0], /*clear_if_invalid*/ false)) { |
| 1110 | // Open the dex files to look up classes and methods. |
| 1111 | std::vector<std::unique_ptr<const DexFile>> dex_files; |
| 1112 | OpenApkFilesFromLocations(&dex_files); |
| 1113 | if (!profile.UpdateProfileKeys(dex_files)) { |
| 1114 | return false; |
| 1115 | } |
| 1116 | return use_fds |
| 1117 | ? profile.Save(reference_profile_file_fd_) |
| 1118 | : profile.Save(reference_profile_file_, /*bytes_written*/ nullptr); |
| 1119 | } else { |
| 1120 | return false; |
| 1121 | } |
| 1122 | } |
| 1123 | |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 1124 | private: |
| 1125 | static void ParseFdForCollection(const StringPiece& option, |
| 1126 | const char* arg_name, |
| 1127 | std::vector<int>* fds) { |
| 1128 | int fd; |
| 1129 | ParseUintOption(option, arg_name, &fd, Usage); |
| 1130 | fds->push_back(fd); |
| 1131 | } |
| 1132 | |
| 1133 | static void CloseAllFds(const std::vector<int>& fds, const char* descriptor) { |
| 1134 | for (size_t i = 0; i < fds.size(); i++) { |
| 1135 | if (close(fds[i]) < 0) { |
| 1136 | PLOG(WARNING) << "Failed to close descriptor for " << descriptor << " at index " << i; |
| 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | void LogCompletionTime() { |
David Sehr | 52683cf | 2016-05-05 09:02:38 -0700 | [diff] [blame] | 1142 | static constexpr uint64_t kLogThresholdTime = MsToNs(100); // 100ms |
| 1143 | uint64_t time_taken = NanoTime() - start_ns_; |
David Sehr | ed79301 | 2016-05-05 13:39:43 -0700 | [diff] [blame] | 1144 | if (time_taken > kLogThresholdTime) { |
David Sehr | d855718 | 2016-05-06 12:29:35 -0700 | [diff] [blame] | 1145 | LOG(WARNING) << "profman took " << PrettyDuration(time_taken); |
David Sehr | ed79301 | 2016-05-05 13:39:43 -0700 | [diff] [blame] | 1146 | } |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | std::vector<std::string> profile_files_; |
| 1150 | std::vector<int> profile_files_fd_; |
David Sehr | 546d24f | 2016-06-02 10:46:19 -0700 | [diff] [blame] | 1151 | std::vector<std::string> dex_locations_; |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 1152 | std::vector<std::string> apk_files_; |
David Sehr | 546d24f | 2016-06-02 10:46:19 -0700 | [diff] [blame] | 1153 | std::vector<int> apks_fd_; |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 1154 | std::string reference_profile_file_; |
| 1155 | int reference_profile_file_fd_; |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 1156 | bool dump_only_; |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 1157 | bool dump_classes_and_methods_; |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 1158 | bool generate_boot_image_profile_; |
David Brazdil | f13ac7c | 2018-01-30 10:09:08 +0000 | [diff] [blame^] | 1159 | bool skip_apk_verification_; |
David Sehr | 4fcdd6d | 2016-05-24 14:52:31 -0700 | [diff] [blame] | 1160 | int dump_output_to_fd_; |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 1161 | BootImageOptions boot_image_options_; |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 1162 | std::string test_profile_; |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 1163 | std::string create_profile_from_file_; |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 1164 | uint16_t test_profile_num_dex_; |
Shubham Ajmera | d704f0b | 2017-07-26 16:33:35 -0700 | [diff] [blame] | 1165 | uint16_t test_profile_method_percerntage_; |
| 1166 | uint16_t test_profile_class_percentage_; |
Jeff Hao | f0a31f8 | 2017-03-27 15:50:37 -0700 | [diff] [blame] | 1167 | uint32_t test_profile_seed_; |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 1168 | uint64_t start_ns_; |
Calin Juravle | 2dba0ab | 2018-01-22 19:22:24 -0800 | [diff] [blame] | 1169 | bool copy_and_update_profile_key_; |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 1170 | }; |
| 1171 | |
| 1172 | // See ProfileAssistant::ProcessingResult for return codes. |
| 1173 | static int profman(int argc, char** argv) { |
| 1174 | ProfMan profman; |
| 1175 | |
| 1176 | // Parse arguments. Argument mistakes will lead to exit(EXIT_FAILURE) in UsageError. |
| 1177 | profman.ParseArgs(argc, argv); |
| 1178 | |
Calin Juravle | 7bcdb53 | 2016-06-07 16:14:47 +0100 | [diff] [blame] | 1179 | if (profman.ShouldGenerateTestProfile()) { |
| 1180 | return profman.GenerateTestProfile(); |
| 1181 | } |
Calin Juravle | 876f350 | 2016-03-24 16:16:34 +0000 | [diff] [blame] | 1182 | if (profman.ShouldOnlyDumpProfile()) { |
| 1183 | return profman.DumpProfileInfo(); |
| 1184 | } |
Mathieu Chartier | 3406726 | 2017-04-06 13:55:46 -0700 | [diff] [blame] | 1185 | if (profman.ShouldOnlyDumpClassesAndMethods()) { |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 1186 | return profman.DumpClassesAndMethods(); |
David Sehr | 7c80f2d | 2017-02-07 16:47:58 -0800 | [diff] [blame] | 1187 | } |
| 1188 | if (profman.ShouldCreateProfile()) { |
| 1189 | return profman.CreateProfile(); |
| 1190 | } |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 1191 | |
| 1192 | if (profman.ShouldCreateBootProfile()) { |
| 1193 | return profman.CreateBootProfile(); |
| 1194 | } |
Calin Juravle | 2e2db78 | 2016-02-23 12:00:03 +0000 | [diff] [blame] | 1195 | // Process profile information and assess if we need to do a profile guided compilation. |
| 1196 | // This operation involves I/O. |
| 1197 | return profman.ProcessProfiles(); |
| 1198 | } |
| 1199 | |
| 1200 | } // namespace art |
| 1201 | |
| 1202 | int main(int argc, char **argv) { |
| 1203 | return art::profman(argc, argv); |
| 1204 | } |
| 1205 | |