blob: f8035aae344cb1f44a8d22998d9793f945bb3cc4 [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,
Calin Juravle702d2602015-04-30 19:28:21 +010032 kInstructionSimplifications,
Alexandre Rames44b9cf92015-08-19 15:39:06 +010033 kInstructionSimplificationsArch,
Calin Juravle175dc732015-08-25 15:42:32 +010034 kUnresolvedMethod,
Calin Juravlee460d1d2015-09-29 04:52:17 +010035 kUnresolvedField,
Calin Juravle07380a22015-09-17 14:15:12 +010036 kUnresolvedFieldNotAFastAccess,
Calin Juravlead543382015-11-19 17:26:29 +000037 kRemovedCheckedCast,
38 kRemovedDeadInstruction,
39 kRemovedNullCheck,
Calin Juravle702d2602015-04-30 19:28:21 +010040 kNotCompiledBranchOutsideMethodCode,
David Brazdil4833f5a2015-12-16 10:37:39 +000041 kNotCompiledThrowCatchLoop,
David Brazdil15693bf2015-12-16 10:30:45 +000042 kNotCompiledAmbiguousArrayOp,
Calin Juravle48c2b032014-12-09 18:11:36 +000043 kNotCompiledHugeMethod,
44 kNotCompiledLargeMethodNoBranches,
Nicolas Geoffray2e335252015-06-18 11:11:27 +010045 kNotCompiledMalformedOpcode,
Calin Juravle48c2b032014-12-09 18:11:36 +000046 kNotCompiledNoCodegen,
Calin Juravle702d2602015-04-30 19:28:21 +010047 kNotCompiledPathological,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000048 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000049 kNotCompiledUnhandledInstruction,
Calin Juravle702d2602015-04-30 19:28:21 +010050 kNotCompiledUnsupportedIsa,
Calin Juravlead543382015-11-19 17:26:29 +000051 kNotCompiledVerificationError,
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010052 kNotCompiledVerifyAtRuntime,
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010053 kInlinedMonomorphicCall,
54 kMonomorphicCall,
55 kPolymorphicCall,
56 kMegamorphicCall,
Calin Juravle48c2b032014-12-09 18:11:36 +000057 kLastStat
58};
59
60class OptimizingCompilerStats {
61 public:
62 OptimizingCompilerStats() {}
63
David Brazdil2d7352b2015-04-20 14:52:42 +010064 void RecordStat(MethodCompilationStat stat, size_t count = 1) {
65 compile_stats_[stat] += count;
Calin Juravle48c2b032014-12-09 18:11:36 +000066 }
67
68 void Log() const {
Calin Juravlead543382015-11-19 17:26:29 +000069 if (!kIsDebugBuild && !VLOG_IS_ON(compiler)) {
70 // Log only in debug builds or if the compiler is verbose.
71 return;
72 }
73
Calin Juravle48c2b032014-12-09 18:11:36 +000074 if (compile_stats_[kAttemptCompilation] == 0) {
75 LOG(INFO) << "Did not compile any method.";
76 } else {
Calin Juravlead543382015-11-19 17:26:29 +000077 float compiled_percent =
78 compile_stats_[kCompiled] * 100.0f / compile_stats_[kAttemptCompilation];
79 LOG(INFO) << "Attempted compilation of " << compile_stats_[kAttemptCompilation]
80 << " methods: " << std::fixed << std::setprecision(2)
81 << compiled_percent << "% (" << compile_stats_[kCompiled] << ") compiled.";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010082
Calin Juravle48c2b032014-12-09 18:11:36 +000083 for (int i = 0; i < kLastStat; i++) {
84 if (compile_stats_[i] != 0) {
Andreas Gampeda9badb2015-06-05 20:22:12 -070085 LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": "
86 << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +000087 }
88 }
Calin Juravle48c2b032014-12-09 18:11:36 +000089 }
90 }
91
92 private:
Andreas Gampeda9badb2015-06-05 20:22:12 -070093 std::string PrintMethodCompilationStat(MethodCompilationStat stat) const {
Calin Juravlead543382015-11-19 17:26:29 +000094 std::string name;
Calin Juravle48c2b032014-12-09 18:11:36 +000095 switch (stat) {
Calin Juravlead543382015-11-19 17:26:29 +000096 case kAttemptCompilation : name = "AttemptCompilation"; break;
97 case kCompiled : name = "Compiled"; break;
98 case kInlinedInvoke : name = "InlinedInvoke"; break;
99 case kInstructionSimplifications: name = "InstructionSimplifications"; break;
100 case kInstructionSimplificationsArch: name = "InstructionSimplificationsArch"; break;
101 case kUnresolvedMethod : name = "UnresolvedMethod"; break;
102 case kUnresolvedField : name = "UnresolvedField"; break;
103 case kUnresolvedFieldNotAFastAccess : name = "UnresolvedFieldNotAFastAccess"; break;
104 case kRemovedCheckedCast: name = "RemovedCheckedCast"; break;
105 case kRemovedDeadInstruction: name = "RemovedDeadInstruction"; break;
106 case kRemovedNullCheck: name = "RemovedNullCheck"; break;
107 case kNotCompiledBranchOutsideMethodCode: name = "NotCompiledBranchOutsideMethodCode"; break;
David Brazdil4833f5a2015-12-16 10:37:39 +0000108 case kNotCompiledThrowCatchLoop : name = "NotCompiledThrowCatchLoop"; break;
David Brazdil15693bf2015-12-16 10:30:45 +0000109 case kNotCompiledAmbiguousArrayOp : name = "NotCompiledAmbiguousArrayOp"; break;
Calin Juravlead543382015-11-19 17:26:29 +0000110 case kNotCompiledHugeMethod : name = "NotCompiledHugeMethod"; break;
111 case kNotCompiledLargeMethodNoBranches : name = "NotCompiledLargeMethodNoBranches"; break;
112 case kNotCompiledMalformedOpcode : name = "NotCompiledMalformedOpcode"; break;
113 case kNotCompiledNoCodegen : name = "NotCompiledNoCodegen"; break;
114 case kNotCompiledPathological : name = "NotCompiledPathological"; break;
115 case kNotCompiledSpaceFilter : name = "NotCompiledSpaceFilter"; break;
116 case kNotCompiledUnhandledInstruction : name = "NotCompiledUnhandledInstruction"; break;
117 case kNotCompiledUnsupportedIsa : name = "NotCompiledUnsupportedIsa"; break;
118 case kNotCompiledVerificationError : name = "NotCompiledVerificationError"; break;
119 case kNotCompiledVerifyAtRuntime : name = "NotCompiledVerifyAtRuntime"; break;
Nicolas Geoffray73be1e82015-09-17 15:22:56 +0100120 case kInlinedMonomorphicCall: name = "InlinedMonomorphicCall"; break;
121 case kMonomorphicCall: name = "MonomorphicCall"; break;
122 case kPolymorphicCall: name = "PolymorphicCall"; break;
123 case kMegamorphicCall: name = "kMegamorphicCall"; break;
Andreas Gampeda9badb2015-06-05 20:22:12 -0700124
Calin Juravlead543382015-11-19 17:26:29 +0000125 case kLastStat:
126 LOG(FATAL) << "invalid stat "
127 << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat);
128 UNREACHABLE();
Calin Juravle48c2b032014-12-09 18:11:36 +0000129 }
Calin Juravlead543382015-11-19 17:26:29 +0000130 return "OptStat#" + name;
Calin Juravle48c2b032014-12-09 18:11:36 +0000131 }
132
133 AtomicInteger compile_stats_[kLastStat];
134
135 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
136};
137
138} // namespace art
139
140#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_