blob: 203b1ec7ec29c16bef3582772faa80d52141aacd [file] [log] [blame]
Calin Juravle48c2b032014-12-09 18:11:36 +00001/*
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 Juravlead543382015-11-19 17:26:29 +000020#include <iomanip>
Calin Juravle48c2b032014-12-09 18:11:36 +000021#include <string>
Andreas Gampeda9badb2015-06-05 20:22:12 -070022#include <type_traits>
Calin Juravle48c2b032014-12-09 18:11:36 +000023
24#include "atomic.h"
25
26namespace art {
27
28enum MethodCompilationStat {
29 kAttemptCompilation = 0,
Mingyao Yang063fc772016-08-02 11:02:54 -070030 kCHAInline,
Calin Juravlead543382015-11-19 17:26:29 +000031 kCompiled,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000032 kInlinedInvoke,
Vladimir Markobe10e8e2016-01-22 12:09:44 +000033 kReplacedInvokeWithSimplePattern,
Calin Juravle702d2602015-04-30 19:28:21 +010034 kInstructionSimplifications,
Alexandre Rames44b9cf92015-08-19 15:39:06 +010035 kInstructionSimplificationsArch,
Calin Juravle175dc732015-08-25 15:42:32 +010036 kUnresolvedMethod,
Calin Juravlee460d1d2015-09-29 04:52:17 +010037 kUnresolvedField,
Calin Juravle07380a22015-09-17 14:15:12 +010038 kUnresolvedFieldNotAFastAccess,
Calin Juravlead543382015-11-19 17:26:29 +000039 kRemovedCheckedCast,
40 kRemovedDeadInstruction,
41 kRemovedNullCheck,
David Brazdil86ea7ee2016-02-16 09:26:07 +000042 kNotCompiledSkipped,
43 kNotCompiledInvalidBytecode,
David Brazdil4833f5a2015-12-16 10:37:39 +000044 kNotCompiledThrowCatchLoop,
David Brazdil15693bf2015-12-16 10:30:45 +000045 kNotCompiledAmbiguousArrayOp,
Calin Juravle48c2b032014-12-09 18:11:36 +000046 kNotCompiledHugeMethod,
47 kNotCompiledLargeMethodNoBranches,
Nicolas Geoffray2e335252015-06-18 11:11:27 +010048 kNotCompiledMalformedOpcode,
Calin Juravle48c2b032014-12-09 18:11:36 +000049 kNotCompiledNoCodegen,
Calin Juravle702d2602015-04-30 19:28:21 +010050 kNotCompiledPathological,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000051 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000052 kNotCompiledUnhandledInstruction,
Calin Juravle702d2602015-04-30 19:28:21 +010053 kNotCompiledUnsupportedIsa,
Calin Juravlead543382015-11-19 17:26:29 +000054 kNotCompiledVerificationError,
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010055 kNotCompiledVerifyAtRuntime,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010056 kInlinedMonomorphicCall,
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000057 kInlinedPolymorphicCall,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010058 kMonomorphicCall,
59 kPolymorphicCall,
60 kMegamorphicCall,
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +010061 kBooleanSimplified,
62 kIntrinsicRecognized,
63 kLoopInvariantMoved,
64 kSelectGenerated,
Calin Juravle69158982016-03-16 11:53:41 +000065 kRemovedInstanceOf,
66 kInlinedInvokeVirtualOrInterface,
Calin Juravle2ae48182016-03-16 14:05:09 +000067 kImplicitNullCheckGenerated,
68 kExplicitNullCheckGenerated,
Nicolas Geoffraydac9b192016-07-15 10:46:17 +010069 kSimplifyIf,
Calin Juravle48c2b032014-12-09 18:11:36 +000070 kLastStat
71};
72
73class OptimizingCompilerStats {
74 public:
75 OptimizingCompilerStats() {}
76
David Brazdil2d7352b2015-04-20 14:52:42 +010077 void RecordStat(MethodCompilationStat stat, size_t count = 1) {
78 compile_stats_[stat] += count;
Calin Juravle48c2b032014-12-09 18:11:36 +000079 }
80
81 void Log() const {
Calin Juravlead543382015-11-19 17:26:29 +000082 if (!kIsDebugBuild && !VLOG_IS_ON(compiler)) {
83 // Log only in debug builds or if the compiler is verbose.
84 return;
85 }
86
Calin Juravle48c2b032014-12-09 18:11:36 +000087 if (compile_stats_[kAttemptCompilation] == 0) {
88 LOG(INFO) << "Did not compile any method.";
89 } else {
Calin Juravlead543382015-11-19 17:26:29 +000090 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 Geoffray12be74e2015-03-30 13:29:08 +010095
Calin Juravle48c2b032014-12-09 18:11:36 +000096 for (int i = 0; i < kLastStat; i++) {
97 if (compile_stats_[i] != 0) {
Andreas Gampeda9badb2015-06-05 20:22:12 -070098 LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": "
99 << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +0000100 }
101 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000102 }
103 }
104
105 private:
Andreas Gampeda9badb2015-06-05 20:22:12 -0700106 std::string PrintMethodCompilationStat(MethodCompilationStat stat) const {
Calin Juravlead543382015-11-19 17:26:29 +0000107 std::string name;
Calin Juravle48c2b032014-12-09 18:11:36 +0000108 switch (stat) {
Calin Juravlead543382015-11-19 17:26:29 +0000109 case kAttemptCompilation : name = "AttemptCompilation"; break;
Mingyao Yang063fc772016-08-02 11:02:54 -0700110 case kCHAInline : name = "CHAInline"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000111 case kCompiled : name = "Compiled"; break;
112 case kInlinedInvoke : name = "InlinedInvoke"; break;
Vladimir Markobe10e8e2016-01-22 12:09:44 +0000113 case kReplacedInvokeWithSimplePattern: name = "ReplacedInvokeWithSimplePattern"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000114 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 Brazdil86ea7ee2016-02-16 09:26:07 +0000122 case kNotCompiledSkipped: name = "NotCompiledSkipped"; break;
123 case kNotCompiledInvalidBytecode: name = "NotCompiledInvalidBytecode"; break;
David Brazdil4833f5a2015-12-16 10:37:39 +0000124 case kNotCompiledThrowCatchLoop : name = "NotCompiledThrowCatchLoop"; break;
David Brazdil15693bf2015-12-16 10:30:45 +0000125 case kNotCompiledAmbiguousArrayOp : name = "NotCompiledAmbiguousArrayOp"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000126 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 Geoffray73be1e82015-09-17 15:22:56 +0100136 case kInlinedMonomorphicCall: name = "InlinedMonomorphicCall"; break;
Nicolas Geoffraya42363f2015-12-17 14:57:09 +0000137 case kInlinedPolymorphicCall: name = "InlinedPolymorphicCall"; break;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100138 case kMonomorphicCall: name = "MonomorphicCall"; break;
139 case kPolymorphicCall: name = "PolymorphicCall"; break;
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +0100140 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 Juravle69158982016-03-16 11:53:41 +0000145 case kRemovedInstanceOf: name = "RemovedInstanceOf"; break;
146 case kInlinedInvokeVirtualOrInterface: name = "InlinedInvokeVirtualOrInterface"; break;
Calin Juravle2ae48182016-03-16 14:05:09 +0000147 case kImplicitNullCheckGenerated: name = "ImplicitNullCheckGenerated"; break;
148 case kExplicitNullCheckGenerated: name = "ExplicitNullCheckGenerated"; break;
Nicolas Geoffraydac9b192016-07-15 10:46:17 +0100149 case kSimplifyIf: name = "SimplifyIf"; break;
Andreas Gampeda9badb2015-06-05 20:22:12 -0700150
Calin Juravlead543382015-11-19 17:26:29 +0000151 case kLastStat:
152 LOG(FATAL) << "invalid stat "
153 << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat);
154 UNREACHABLE();
Calin Juravle48c2b032014-12-09 18:11:36 +0000155 }
Calin Juravlead543382015-11-19 17:26:29 +0000156 return "OptStat#" + name;
Calin Juravle48c2b032014-12-09 18:11:36 +0000157 }
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_