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, |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 30 | kCompiled, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 31 | kInlinedInvoke, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 32 | kInstructionSimplifications, |
Alexandre Rames | 44b9cf9 | 2015-08-19 15:39:06 +0100 | [diff] [blame] | 33 | kInstructionSimplificationsArch, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 34 | kUnresolvedMethod, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 35 | kUnresolvedField, |
Calin Juravle | 07380a2 | 2015-09-17 14:15:12 +0100 | [diff] [blame] | 36 | kUnresolvedFieldNotAFastAccess, |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 37 | kRemovedCheckedCast, |
| 38 | kRemovedDeadInstruction, |
| 39 | kRemovedNullCheck, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 40 | kNotCompiledBranchOutsideMethodCode, |
Alex Light | 68289a5 | 2015-12-15 17:30:30 -0800 | [diff] [blame] | 41 | kNotCompiledCannotBuildSSA, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 42 | kNotCompiledHugeMethod, |
| 43 | kNotCompiledLargeMethodNoBranches, |
Nicolas Geoffray | 2e33525 | 2015-06-18 11:11:27 +0100 | [diff] [blame] | 44 | kNotCompiledMalformedOpcode, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 45 | kNotCompiledNoCodegen, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 46 | kNotCompiledPathological, |
Nicolas Geoffray | 36540cb | 2015-03-23 14:45:53 +0000 | [diff] [blame] | 47 | kNotCompiledSpaceFilter, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 48 | kNotCompiledUnhandledInstruction, |
Calin Juravle | 702d260 | 2015-04-30 19:28:21 +0100 | [diff] [blame] | 49 | kNotCompiledUnsupportedIsa, |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 50 | kNotCompiledVerificationError, |
Calin Juravle | f1c6d9e | 2015-04-13 18:42:21 +0100 | [diff] [blame] | 51 | kNotCompiledVerifyAtRuntime, |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 52 | kInlinedMonomorphicCall, |
| 53 | kMonomorphicCall, |
| 54 | kPolymorphicCall, |
| 55 | kMegamorphicCall, |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 56 | kLastStat |
| 57 | }; |
| 58 | |
| 59 | class OptimizingCompilerStats { |
| 60 | public: |
| 61 | OptimizingCompilerStats() {} |
| 62 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 63 | void RecordStat(MethodCompilationStat stat, size_t count = 1) { |
| 64 | compile_stats_[stat] += count; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void Log() const { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 68 | if (!kIsDebugBuild && !VLOG_IS_ON(compiler)) { |
| 69 | // Log only in debug builds or if the compiler is verbose. |
| 70 | return; |
| 71 | } |
| 72 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 73 | if (compile_stats_[kAttemptCompilation] == 0) { |
| 74 | LOG(INFO) << "Did not compile any method."; |
| 75 | } else { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 76 | float compiled_percent = |
| 77 | compile_stats_[kCompiled] * 100.0f / compile_stats_[kAttemptCompilation]; |
| 78 | LOG(INFO) << "Attempted compilation of " << compile_stats_[kAttemptCompilation] |
| 79 | << " methods: " << std::fixed << std::setprecision(2) |
| 80 | << compiled_percent << "% (" << compile_stats_[kCompiled] << ") compiled."; |
Nicolas Geoffray | 12be74e | 2015-03-30 13:29:08 +0100 | [diff] [blame] | 81 | |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 82 | for (int i = 0; i < kLastStat; i++) { |
| 83 | if (compile_stats_[i] != 0) { |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 84 | LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": " |
| 85 | << compile_stats_[i]; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 86 | } |
| 87 | } |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
| 91 | private: |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 92 | std::string PrintMethodCompilationStat(MethodCompilationStat stat) const { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 93 | std::string name; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 94 | switch (stat) { |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 95 | case kAttemptCompilation : name = "AttemptCompilation"; break; |
| 96 | case kCompiled : name = "Compiled"; break; |
| 97 | case kInlinedInvoke : name = "InlinedInvoke"; break; |
| 98 | case kInstructionSimplifications: name = "InstructionSimplifications"; break; |
| 99 | case kInstructionSimplificationsArch: name = "InstructionSimplificationsArch"; break; |
| 100 | case kUnresolvedMethod : name = "UnresolvedMethod"; break; |
| 101 | case kUnresolvedField : name = "UnresolvedField"; break; |
| 102 | case kUnresolvedFieldNotAFastAccess : name = "UnresolvedFieldNotAFastAccess"; break; |
| 103 | case kRemovedCheckedCast: name = "RemovedCheckedCast"; break; |
| 104 | case kRemovedDeadInstruction: name = "RemovedDeadInstruction"; break; |
| 105 | case kRemovedNullCheck: name = "RemovedNullCheck"; break; |
| 106 | case kNotCompiledBranchOutsideMethodCode: name = "NotCompiledBranchOutsideMethodCode"; break; |
Alex Light | 68289a5 | 2015-12-15 17:30:30 -0800 | [diff] [blame] | 107 | case kNotCompiledCannotBuildSSA : name = "NotCompiledCannotBuildSSA"; break; |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 108 | case kNotCompiledHugeMethod : name = "NotCompiledHugeMethod"; break; |
| 109 | case kNotCompiledLargeMethodNoBranches : name = "NotCompiledLargeMethodNoBranches"; break; |
| 110 | case kNotCompiledMalformedOpcode : name = "NotCompiledMalformedOpcode"; break; |
| 111 | case kNotCompiledNoCodegen : name = "NotCompiledNoCodegen"; break; |
| 112 | case kNotCompiledPathological : name = "NotCompiledPathological"; break; |
| 113 | case kNotCompiledSpaceFilter : name = "NotCompiledSpaceFilter"; break; |
| 114 | case kNotCompiledUnhandledInstruction : name = "NotCompiledUnhandledInstruction"; break; |
| 115 | case kNotCompiledUnsupportedIsa : name = "NotCompiledUnsupportedIsa"; break; |
| 116 | case kNotCompiledVerificationError : name = "NotCompiledVerificationError"; break; |
| 117 | case kNotCompiledVerifyAtRuntime : name = "NotCompiledVerifyAtRuntime"; break; |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 118 | case kInlinedMonomorphicCall: name = "InlinedMonomorphicCall"; break; |
| 119 | case kMonomorphicCall: name = "MonomorphicCall"; break; |
| 120 | case kPolymorphicCall: name = "PolymorphicCall"; break; |
| 121 | case kMegamorphicCall: name = "kMegamorphicCall"; break; |
Andreas Gampe | da9badb | 2015-06-05 20:22:12 -0700 | [diff] [blame] | 122 | |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 123 | case kLastStat: |
| 124 | LOG(FATAL) << "invalid stat " |
| 125 | << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat); |
| 126 | UNREACHABLE(); |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 127 | } |
Calin Juravle | ad54338 | 2015-11-19 17:26:29 +0000 | [diff] [blame] | 128 | return "OptStat#" + name; |
Calin Juravle | 48c2b03 | 2014-12-09 18:11:36 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | AtomicInteger compile_stats_[kLastStat]; |
| 132 | |
| 133 | DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats); |
| 134 | }; |
| 135 | |
| 136 | } // namespace art |
| 137 | |
| 138 | #endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_ |