blob: c8d1ce0bd5855eab508b438a4db6d12cdf692fb7 [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,
Calin Juravlead543382015-11-19 17:26:29 +000030 kCompiled,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000031 kInlinedInvoke,
Vladimir Markobe10e8e2016-01-22 12:09:44 +000032 kReplacedInvokeWithSimplePattern,
Calin Juravle702d2602015-04-30 19:28:21 +010033 kInstructionSimplifications,
Alexandre Rames44b9cf92015-08-19 15:39:06 +010034 kInstructionSimplificationsArch,
Calin Juravle175dc732015-08-25 15:42:32 +010035 kUnresolvedMethod,
Calin Juravlee460d1d2015-09-29 04:52:17 +010036 kUnresolvedField,
Calin Juravle07380a22015-09-17 14:15:12 +010037 kUnresolvedFieldNotAFastAccess,
Calin Juravlead543382015-11-19 17:26:29 +000038 kRemovedCheckedCast,
39 kRemovedDeadInstruction,
40 kRemovedNullCheck,
David Brazdil86ea7ee2016-02-16 09:26:07 +000041 kNotCompiledSkipped,
42 kNotCompiledInvalidBytecode,
David Brazdil4833f5a2015-12-16 10:37:39 +000043 kNotCompiledThrowCatchLoop,
David Brazdil15693bf2015-12-16 10:30:45 +000044 kNotCompiledAmbiguousArrayOp,
Calin Juravle48c2b032014-12-09 18:11:36 +000045 kNotCompiledHugeMethod,
46 kNotCompiledLargeMethodNoBranches,
Nicolas Geoffray2e335252015-06-18 11:11:27 +010047 kNotCompiledMalformedOpcode,
Calin Juravle48c2b032014-12-09 18:11:36 +000048 kNotCompiledNoCodegen,
Calin Juravle702d2602015-04-30 19:28:21 +010049 kNotCompiledPathological,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000050 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000051 kNotCompiledUnhandledInstruction,
Calin Juravle702d2602015-04-30 19:28:21 +010052 kNotCompiledUnsupportedIsa,
Calin Juravlead543382015-11-19 17:26:29 +000053 kNotCompiledVerificationError,
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010054 kNotCompiledVerifyAtRuntime,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010055 kInlinedMonomorphicCall,
Nicolas Geoffraya42363f2015-12-17 14:57:09 +000056 kInlinedPolymorphicCall,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010057 kMonomorphicCall,
58 kPolymorphicCall,
59 kMegamorphicCall,
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +010060 kBooleanSimplified,
61 kIntrinsicRecognized,
62 kLoopInvariantMoved,
63 kSelectGenerated,
Calin Juravle69158982016-03-16 11:53:41 +000064 kRemovedInstanceOf,
65 kInlinedInvokeVirtualOrInterface,
Calin Juravle2ae48182016-03-16 14:05:09 +000066 kImplicitNullCheckGenerated,
67 kExplicitNullCheckGenerated,
Nicolas Geoffraydac9b192016-07-15 10:46:17 +010068 kSimplifyIf,
Calin Juravle48c2b032014-12-09 18:11:36 +000069 kLastStat
70};
71
72class OptimizingCompilerStats {
73 public:
74 OptimizingCompilerStats() {}
75
David Brazdil2d7352b2015-04-20 14:52:42 +010076 void RecordStat(MethodCompilationStat stat, size_t count = 1) {
77 compile_stats_[stat] += count;
Calin Juravle48c2b032014-12-09 18:11:36 +000078 }
79
80 void Log() const {
Calin Juravlead543382015-11-19 17:26:29 +000081 if (!kIsDebugBuild && !VLOG_IS_ON(compiler)) {
82 // Log only in debug builds or if the compiler is verbose.
83 return;
84 }
85
Calin Juravle48c2b032014-12-09 18:11:36 +000086 if (compile_stats_[kAttemptCompilation] == 0) {
87 LOG(INFO) << "Did not compile any method.";
88 } else {
Calin Juravlead543382015-11-19 17:26:29 +000089 float compiled_percent =
90 compile_stats_[kCompiled] * 100.0f / compile_stats_[kAttemptCompilation];
91 LOG(INFO) << "Attempted compilation of " << compile_stats_[kAttemptCompilation]
92 << " methods: " << std::fixed << std::setprecision(2)
93 << compiled_percent << "% (" << compile_stats_[kCompiled] << ") compiled.";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010094
Calin Juravle48c2b032014-12-09 18:11:36 +000095 for (int i = 0; i < kLastStat; i++) {
96 if (compile_stats_[i] != 0) {
Andreas Gampeda9badb2015-06-05 20:22:12 -070097 LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": "
98 << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +000099 }
100 }
Calin Juravle48c2b032014-12-09 18:11:36 +0000101 }
102 }
103
104 private:
Andreas Gampeda9badb2015-06-05 20:22:12 -0700105 std::string PrintMethodCompilationStat(MethodCompilationStat stat) const {
Calin Juravlead543382015-11-19 17:26:29 +0000106 std::string name;
Calin Juravle48c2b032014-12-09 18:11:36 +0000107 switch (stat) {
Calin Juravlead543382015-11-19 17:26:29 +0000108 case kAttemptCompilation : name = "AttemptCompilation"; break;
109 case kCompiled : name = "Compiled"; break;
110 case kInlinedInvoke : name = "InlinedInvoke"; break;
Vladimir Markobe10e8e2016-01-22 12:09:44 +0000111 case kReplacedInvokeWithSimplePattern: name = "ReplacedInvokeWithSimplePattern"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000112 case kInstructionSimplifications: name = "InstructionSimplifications"; break;
113 case kInstructionSimplificationsArch: name = "InstructionSimplificationsArch"; break;
114 case kUnresolvedMethod : name = "UnresolvedMethod"; break;
115 case kUnresolvedField : name = "UnresolvedField"; break;
116 case kUnresolvedFieldNotAFastAccess : name = "UnresolvedFieldNotAFastAccess"; break;
117 case kRemovedCheckedCast: name = "RemovedCheckedCast"; break;
118 case kRemovedDeadInstruction: name = "RemovedDeadInstruction"; break;
119 case kRemovedNullCheck: name = "RemovedNullCheck"; break;
David Brazdil86ea7ee2016-02-16 09:26:07 +0000120 case kNotCompiledSkipped: name = "NotCompiledSkipped"; break;
121 case kNotCompiledInvalidBytecode: name = "NotCompiledInvalidBytecode"; break;
David Brazdil4833f5a2015-12-16 10:37:39 +0000122 case kNotCompiledThrowCatchLoop : name = "NotCompiledThrowCatchLoop"; break;
David Brazdil15693bf2015-12-16 10:30:45 +0000123 case kNotCompiledAmbiguousArrayOp : name = "NotCompiledAmbiguousArrayOp"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000124 case kNotCompiledHugeMethod : name = "NotCompiledHugeMethod"; break;
125 case kNotCompiledLargeMethodNoBranches : name = "NotCompiledLargeMethodNoBranches"; break;
126 case kNotCompiledMalformedOpcode : name = "NotCompiledMalformedOpcode"; break;
127 case kNotCompiledNoCodegen : name = "NotCompiledNoCodegen"; break;
128 case kNotCompiledPathological : name = "NotCompiledPathological"; break;
129 case kNotCompiledSpaceFilter : name = "NotCompiledSpaceFilter"; break;
130 case kNotCompiledUnhandledInstruction : name = "NotCompiledUnhandledInstruction"; break;
131 case kNotCompiledUnsupportedIsa : name = "NotCompiledUnsupportedIsa"; break;
132 case kNotCompiledVerificationError : name = "NotCompiledVerificationError"; break;
133 case kNotCompiledVerifyAtRuntime : name = "NotCompiledVerifyAtRuntime"; break;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100134 case kInlinedMonomorphicCall: name = "InlinedMonomorphicCall"; break;
Nicolas Geoffraya42363f2015-12-17 14:57:09 +0000135 case kInlinedPolymorphicCall: name = "InlinedPolymorphicCall"; break;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100136 case kMonomorphicCall: name = "MonomorphicCall"; break;
137 case kPolymorphicCall: name = "PolymorphicCall"; break;
Jean-Philippe Halimi38e9e802016-02-18 16:42:03 +0100138 case kMegamorphicCall: name = "MegamorphicCall"; break;
139 case kBooleanSimplified : name = "BooleanSimplified"; break;
140 case kIntrinsicRecognized : name = "IntrinsicRecognized"; break;
141 case kLoopInvariantMoved : name = "LoopInvariantMoved"; break;
142 case kSelectGenerated : name = "SelectGenerated"; break;
Calin Juravle69158982016-03-16 11:53:41 +0000143 case kRemovedInstanceOf: name = "RemovedInstanceOf"; break;
144 case kInlinedInvokeVirtualOrInterface: name = "InlinedInvokeVirtualOrInterface"; break;
Calin Juravle2ae48182016-03-16 14:05:09 +0000145 case kImplicitNullCheckGenerated: name = "ImplicitNullCheckGenerated"; break;
146 case kExplicitNullCheckGenerated: name = "ExplicitNullCheckGenerated"; break;
Nicolas Geoffraydac9b192016-07-15 10:46:17 +0100147 case kSimplifyIf: name = "SimplifyIf"; break;
Andreas Gampeda9badb2015-06-05 20:22:12 -0700148
Calin Juravlead543382015-11-19 17:26:29 +0000149 case kLastStat:
150 LOG(FATAL) << "invalid stat "
151 << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat);
152 UNREACHABLE();
Calin Juravle48c2b032014-12-09 18:11:36 +0000153 }
Calin Juravlead543382015-11-19 17:26:29 +0000154 return "OptStat#" + name;
Calin Juravle48c2b032014-12-09 18:11:36 +0000155 }
156
157 AtomicInteger compile_stats_[kLastStat];
158
159 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
160};
161
162} // namespace art
163
164#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_