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 | |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 20 | #include <iomanip> |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 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, |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 30 | kCHAInline, |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 31 | kCompiled, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 32 | kInlinedInvoke, |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 33 | kReplacedInvokeWithSimplePattern, |
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 | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 37 | kUnresolvedField, |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 38 | kUnresolvedFieldNotAFastAccess, |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 39 | kRemovedCheckedCast, |
| 40 | kRemovedDeadInstruction, |
| 41 | kRemovedNullCheck, |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 42 | kNotCompiledSkipped, |
| 43 | kNotCompiledInvalidBytecode, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 44 | kNotCompiledThrowCatchLoop, |
David Brazdil | 15693bf | 2015-12-16 10:30:45 +0000 | [diff] [blame] | 45 | kNotCompiledAmbiguousArrayOp, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 46 | kNotCompiledHugeMethod, |
| 47 | kNotCompiledLargeMethodNoBranches, |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 48 | kNotCompiledMalformedOpcode, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 49 | kNotCompiledNoCodegen, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 50 | kNotCompiledPathological, |
Nicolas Geoffray | 36540cb | 2015-03-23 14:45:53 +0000 | [diff] [blame] | 51 | kNotCompiledSpaceFilter, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 52 | kNotCompiledUnhandledInstruction, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 53 | kNotCompiledUnsupportedIsa, |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 54 | kNotCompiledVerificationError, |
Calin Juravle | f1c6d9e | 2015-04-13 18:42:21 +0100 | [diff] [blame] | 55 | kNotCompiledVerifyAtRuntime, |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 56 | kInlinedMonomorphicCall, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 57 | kInlinedPolymorphicCall, |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 58 | kMonomorphicCall, |
| 59 | kPolymorphicCall, |
| 60 | kMegamorphicCall, |
Jean-Philippe Halimi | 38e9e80 | 2016-02-18 16:42:03 +0100 | [diff] [blame] | 61 | kBooleanSimplified, |
| 62 | kIntrinsicRecognized, |
| 63 | kLoopInvariantMoved, |
| 64 | kSelectGenerated, |
Calin Juravle | 6915898 | 2016-03-16 11:53:41 +0000 | [diff] [blame] | 65 | kRemovedInstanceOf, |
| 66 | kInlinedInvokeVirtualOrInterface, |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 67 | kImplicitNullCheckGenerated, |
| 68 | kExplicitNullCheckGenerated, |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 69 | kSimplifyIf, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 70 | kLastStat |
| 71 | }; |
| 72 | |
| 73 | class OptimizingCompilerStats { |
| 74 | public: |
| 75 | OptimizingCompilerStats() {} |
| 76 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 77 | void RecordStat(MethodCompilationStat stat, size_t count = 1) { |
| 78 | compile_stats_[stat] += count; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void Log() const { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 82 | if (!kIsDebugBuild && !VLOG_IS_ON(compiler)) { |
| 83 | // Log only in debug builds or if the compiler is verbose. |
| 84 | return; |
| 85 | } |
| 86 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 87 | if (compile_stats_[kAttemptCompilation] == 0) { |
| 88 | LOG(INFO) << "Did not compile any method."; |
| 89 | } else { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 90 | float compiled_percent = |
| 91 | compile_stats_[kCompiled] * 100.0f / compile_stats_[kAttemptCompilation]; |
| 92 | LOG(INFO) << "Attempted compilation of " << compile_stats_[kAttemptCompilation] |
| 93 | << " methods: " << std::fixed << std::setprecision(2) |
| 94 | << compiled_percent << "% (" << compile_stats_[kCompiled] << ") compiled."; |
Nicolas Geoffray | 12be74e | 2015-03-30 13:29:08 +0100 | [diff] [blame] | 95 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 96 | for (int i = 0; i < kLastStat; i++) { |
| 97 | if (compile_stats_[i] != 0) { |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 98 | LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": " |
| 99 | << compile_stats_[i]; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 100 | } |
| 101 | } |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
| 105 | private: |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 106 | std::string PrintMethodCompilationStat(MethodCompilationStat stat) const { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 107 | std::string name; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 108 | switch (stat) { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 109 | case kAttemptCompilation : name = "AttemptCompilation"; break; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 110 | case kCHAInline : name = "CHAInline"; break; |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 111 | case kCompiled : name = "Compiled"; break; |
| 112 | case kInlinedInvoke : name = "InlinedInvoke"; break; |
Vladimir Marko | be10e8e | 2016-01-22 12:09:44 +0000 | [diff] [blame] | 113 | case kReplacedInvokeWithSimplePattern: name = "ReplacedInvokeWithSimplePattern"; break; |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 114 | case kInstructionSimplifications: name = "InstructionSimplifications"; break; |
| 115 | case kInstructionSimplificationsArch: name = "InstructionSimplificationsArch"; break; |
| 116 | case kUnresolvedMethod : name = "UnresolvedMethod"; break; |
| 117 | case kUnresolvedField : name = "UnresolvedField"; break; |
| 118 | case kUnresolvedFieldNotAFastAccess : name = "UnresolvedFieldNotAFastAccess"; break; |
| 119 | case kRemovedCheckedCast: name = "RemovedCheckedCast"; break; |
| 120 | case kRemovedDeadInstruction: name = "RemovedDeadInstruction"; break; |
| 121 | case kRemovedNullCheck: name = "RemovedNullCheck"; break; |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 122 | case kNotCompiledSkipped: name = "NotCompiledSkipped"; break; |
| 123 | case kNotCompiledInvalidBytecode: name = "NotCompiledInvalidBytecode"; break; |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 124 | case kNotCompiledThrowCatchLoop : name = "NotCompiledThrowCatchLoop"; break; |
David Brazdil | 15693bf | 2015-12-16 10:30:45 +0000 | [diff] [blame] | 125 | case kNotCompiledAmbiguousArrayOp : name = "NotCompiledAmbiguousArrayOp"; break; |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 126 | case kNotCompiledHugeMethod : name = "NotCompiledHugeMethod"; break; |
| 127 | case kNotCompiledLargeMethodNoBranches : name = "NotCompiledLargeMethodNoBranches"; break; |
| 128 | case kNotCompiledMalformedOpcode : name = "NotCompiledMalformedOpcode"; break; |
| 129 | case kNotCompiledNoCodegen : name = "NotCompiledNoCodegen"; break; |
| 130 | case kNotCompiledPathological : name = "NotCompiledPathological"; break; |
| 131 | case kNotCompiledSpaceFilter : name = "NotCompiledSpaceFilter"; break; |
| 132 | case kNotCompiledUnhandledInstruction : name = "NotCompiledUnhandledInstruction"; break; |
| 133 | case kNotCompiledUnsupportedIsa : name = "NotCompiledUnsupportedIsa"; break; |
| 134 | case kNotCompiledVerificationError : name = "NotCompiledVerificationError"; break; |
| 135 | case kNotCompiledVerifyAtRuntime : name = "NotCompiledVerifyAtRuntime"; break; |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 136 | case kInlinedMonomorphicCall: name = "InlinedMonomorphicCall"; break; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 137 | case kInlinedPolymorphicCall: name = "InlinedPolymorphicCall"; break; |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 138 | case kMonomorphicCall: name = "MonomorphicCall"; break; |
| 139 | case kPolymorphicCall: name = "PolymorphicCall"; break; |
Jean-Philippe Halimi | 38e9e80 | 2016-02-18 16:42:03 +0100 | [diff] [blame] | 140 | case kMegamorphicCall: name = "MegamorphicCall"; break; |
| 141 | case kBooleanSimplified : name = "BooleanSimplified"; break; |
| 142 | case kIntrinsicRecognized : name = "IntrinsicRecognized"; break; |
| 143 | case kLoopInvariantMoved : name = "LoopInvariantMoved"; break; |
| 144 | case kSelectGenerated : name = "SelectGenerated"; break; |
Calin Juravle | 6915898 | 2016-03-16 11:53:41 +0000 | [diff] [blame] | 145 | case kRemovedInstanceOf: name = "RemovedInstanceOf"; break; |
| 146 | case kInlinedInvokeVirtualOrInterface: name = "InlinedInvokeVirtualOrInterface"; break; |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 147 | case kImplicitNullCheckGenerated: name = "ImplicitNullCheckGenerated"; break; |
| 148 | case kExplicitNullCheckGenerated: name = "ExplicitNullCheckGenerated"; break; |
Nicolas Geoffray | dac9b19 | 2016-07-15 10:46:17 +0100 | [diff] [blame] | 149 | case kSimplifyIf: name = "SimplifyIf"; break; |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 150 | |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 151 | case kLastStat: |
| 152 | LOG(FATAL) << "invalid stat " |
| 153 | << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat); |
| 154 | UNREACHABLE(); |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 155 | } |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 156 | return "OptStat#" + name; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | AtomicInteger compile_stats_[kLastStat]; |
| 160 | |
| 161 | DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats); |
| 162 | }; |
| 163 | |
| 164 | } // namespace art |
| 165 | |
| 166 | #endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_ |