Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_ |
| 19 | |
| 20 | #include <sstream> |
| 21 | #include <string> |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 22 | #include <type_traits> |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 23 | |
| 24 | #include "atomic.h" |
| 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | enum MethodCompilationStat { |
| 29 | kAttemptCompilation = 0, |
| 30 | kCompiledBaseline, |
| 31 | kCompiledOptimized, |
Nicolas Geoffray | 12be74e | 2015-03-30 13:29:08 +0100 | [diff] [blame] | 32 | kCompiledQuick, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 33 | kInlinedInvoke, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 34 | kInstructionSimplifications, |
Alexandre Rames | 44b9cf9 | 2015-08-19 15:39:06 +0100 | [diff] [blame] | 35 | kInstructionSimplificationsArch, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame^] | 36 | kUnresolvedMethod, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 37 | kNotCompiledBranchOutsideMethodCode, |
| 38 | kNotCompiledCannotBuildSSA, |
| 39 | kNotCompiledCantAccesType, |
| 40 | kNotCompiledClassNotVerified, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 41 | kNotCompiledHugeMethod, |
| 42 | kNotCompiledLargeMethodNoBranches, |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 43 | kNotCompiledMalformedOpcode, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 44 | kNotCompiledNoCodegen, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 45 | kNotCompiledPathological, |
Nicolas Geoffray | 36540cb | 2015-03-23 14:45:53 +0000 | [diff] [blame] | 46 | kNotCompiledSpaceFilter, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 47 | kNotCompiledUnhandledInstruction, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 48 | kNotCompiledUnresolvedField, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 49 | kNotCompiledUnsupportedIsa, |
Calin Juravle | f1c6d9e | 2015-04-13 18:42:21 +0100 | [diff] [blame] | 50 | kNotCompiledVerifyAtRuntime, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 51 | kNotOptimizedDisabled, |
| 52 | kNotOptimizedRegisterAllocator, |
| 53 | kNotOptimizedTryCatch, |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 54 | kRemovedCheckedCast, |
Calin Juravle | 8f20bdb | 2015-04-21 14:07:50 +0100 | [diff] [blame] | 55 | kRemovedDeadInstruction, |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 56 | kRemovedNullCheck, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 57 | kLastStat |
| 58 | }; |
| 59 | |
| 60 | class OptimizingCompilerStats { |
| 61 | public: |
| 62 | OptimizingCompilerStats() {} |
| 63 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 64 | void RecordStat(MethodCompilationStat stat, size_t count = 1) { |
| 65 | compile_stats_[stat] += count; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void Log() const { |
| 69 | if (compile_stats_[kAttemptCompilation] == 0) { |
| 70 | LOG(INFO) << "Did not compile any method."; |
| 71 | } else { |
| 72 | size_t unoptimized_percent = |
| 73 | compile_stats_[kCompiledBaseline] * 100 / compile_stats_[kAttemptCompilation]; |
| 74 | size_t optimized_percent = |
| 75 | compile_stats_[kCompiledOptimized] * 100 / compile_stats_[kAttemptCompilation]; |
Nicolas Geoffray | 12be74e | 2015-03-30 13:29:08 +0100 | [diff] [blame] | 76 | size_t quick_percent = |
| 77 | compile_stats_[kCompiledQuick] * 100 / compile_stats_[kAttemptCompilation]; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 78 | std::ostringstream oss; |
Nicolas Geoffray | 12be74e | 2015-03-30 13:29:08 +0100 | [diff] [blame] | 79 | oss << "Attempted compilation of " << compile_stats_[kAttemptCompilation] << " methods: "; |
| 80 | |
| 81 | oss << unoptimized_percent << "% (" << compile_stats_[kCompiledBaseline] << ") unoptimized, "; |
| 82 | oss << optimized_percent << "% (" << compile_stats_[kCompiledOptimized] << ") optimized, "; |
| 83 | oss << quick_percent << "% (" << compile_stats_[kCompiledQuick] << ") quick."; |
| 84 | |
| 85 | LOG(INFO) << oss.str(); |
| 86 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 87 | for (int i = 0; i < kLastStat; i++) { |
| 88 | if (compile_stats_[i] != 0) { |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 89 | LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": " |
| 90 | << compile_stats_[i]; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
| 96 | private: |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 97 | std::string PrintMethodCompilationStat(MethodCompilationStat stat) const { |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 98 | switch (stat) { |
| 99 | case kAttemptCompilation : return "kAttemptCompilation"; |
| 100 | case kCompiledBaseline : return "kCompiledBaseline"; |
| 101 | case kCompiledOptimized : return "kCompiledOptimized"; |
Nicolas Geoffray | 12be74e | 2015-03-30 13:29:08 +0100 | [diff] [blame] | 102 | case kCompiledQuick : return "kCompiledQuick"; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 103 | case kInlinedInvoke : return "kInlinedInvoke"; |
Calin Juravle | 8f20bdb | 2015-04-21 14:07:50 +0100 | [diff] [blame] | 104 | case kInstructionSimplifications: return "kInstructionSimplifications"; |
Alexandre Rames | 44b9cf9 | 2015-08-19 15:39:06 +0100 | [diff] [blame] | 105 | case kInstructionSimplificationsArch: return "kInstructionSimplificationsArch"; |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame^] | 106 | case kUnresolvedMethod : return "kUnresolvedMethod"; |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 107 | case kNotCompiledBranchOutsideMethodCode: return "kNotCompiledBranchOutsideMethodCode"; |
| 108 | case kNotCompiledCannotBuildSSA : return "kNotCompiledCannotBuildSSA"; |
| 109 | case kNotCompiledCantAccesType : return "kNotCompiledCantAccesType"; |
| 110 | case kNotCompiledClassNotVerified : return "kNotCompiledClassNotVerified"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 111 | case kNotCompiledHugeMethod : return "kNotCompiledHugeMethod"; |
| 112 | case kNotCompiledLargeMethodNoBranches : return "kNotCompiledLargeMethodNoBranches"; |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 113 | case kNotCompiledMalformedOpcode : return "kNotCompiledMalformedOpcode"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 114 | case kNotCompiledNoCodegen : return "kNotCompiledNoCodegen"; |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 115 | case kNotCompiledPathological : return "kNotCompiledPathological"; |
Nicolas Geoffray | 36540cb | 2015-03-23 14:45:53 +0000 | [diff] [blame] | 116 | case kNotCompiledSpaceFilter : return "kNotCompiledSpaceFilter"; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 117 | case kNotCompiledUnhandledInstruction : return "kNotCompiledUnhandledInstruction"; |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 118 | case kNotCompiledUnresolvedField : return "kNotCompiledUnresolvedField"; |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 119 | case kNotCompiledUnsupportedIsa : return "kNotCompiledUnsupportedIsa"; |
Calin Juravle | f1c6d9e | 2015-04-13 18:42:21 +0100 | [diff] [blame] | 120 | case kNotCompiledVerifyAtRuntime : return "kNotCompiledVerifyAtRuntime"; |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 121 | case kNotOptimizedDisabled : return "kNotOptimizedDisabled"; |
| 122 | case kNotOptimizedRegisterAllocator : return "kNotOptimizedRegisterAllocator"; |
| 123 | case kNotOptimizedTryCatch : return "kNotOptimizedTryCatch"; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 124 | case kRemovedCheckedCast: return "kRemovedCheckedCast"; |
Calin Juravle | 8f20bdb | 2015-04-21 14:07:50 +0100 | [diff] [blame] | 125 | case kRemovedDeadInstruction: return "kRemovedDeadInstruction"; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 126 | case kRemovedNullCheck: return "kRemovedNullCheck"; |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 127 | |
| 128 | case kLastStat: break; // Invalid to print out. |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 129 | } |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 130 | LOG(FATAL) << "invalid stat " |
| 131 | << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat); |
| 132 | UNREACHABLE(); |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | AtomicInteger compile_stats_[kLastStat]; |
| 136 | |
| 137 | DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats); |
| 138 | }; |
| 139 | |
| 140 | } // namespace art |
| 141 | |
| 142 | #endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_ |