blob: b6b1bb1cadfbe82a093f89b65a4a48bc27ea1d53 [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
20#include <sstream>
21#include <string>
22
23#include "atomic.h"
24
25namespace art {
26
27enum MethodCompilationStat {
28 kAttemptCompilation = 0,
29 kCompiledBaseline,
30 kCompiledOptimized,
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010031 kCompiledQuick,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000032 kInlinedInvoke,
Calin Juravle702d2602015-04-30 19:28:21 +010033 kInstructionSimplifications,
34 kNotCompiledBranchOutsideMethodCode,
35 kNotCompiledCannotBuildSSA,
36 kNotCompiledCantAccesType,
37 kNotCompiledClassNotVerified,
Calin Juravle48c2b032014-12-09 18:11:36 +000038 kNotCompiledHugeMethod,
39 kNotCompiledLargeMethodNoBranches,
Calin Juravle48c2b032014-12-09 18:11:36 +000040 kNotCompiledNoCodegen,
Calin Juravle48c2b032014-12-09 18:11:36 +000041 kNotCompiledNonSequentialRegPair,
Calin Juravle702d2602015-04-30 19:28:21 +010042 kNotCompiledPathological,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000043 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000044 kNotCompiledUnhandledInstruction,
Calin Juravle702d2602015-04-30 19:28:21 +010045 kNotCompiledUnresolvedField,
46 kNotCompiledUnresolvedMethod,
47 kNotCompiledUnsupportedIsa,
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010048 kNotCompiledVerifyAtRuntime,
Calin Juravle702d2602015-04-30 19:28:21 +010049 kNotOptimizedDisabled,
50 kNotOptimizedRegisterAllocator,
51 kNotOptimizedTryCatch,
Calin Juravleacf735c2015-02-12 15:25:22 +000052 kRemovedCheckedCast,
Calin Juravle8f20bdb2015-04-21 14:07:50 +010053 kRemovedDeadInstruction,
Calin Juravleacf735c2015-02-12 15:25:22 +000054 kRemovedNullCheck,
Calin Juravle48c2b032014-12-09 18:11:36 +000055 kLastStat
56};
57
58class OptimizingCompilerStats {
59 public:
60 OptimizingCompilerStats() {}
61
David Brazdil2d7352b2015-04-20 14:52:42 +010062 void RecordStat(MethodCompilationStat stat, size_t count = 1) {
63 compile_stats_[stat] += count;
Calin Juravle48c2b032014-12-09 18:11:36 +000064 }
65
66 void Log() const {
67 if (compile_stats_[kAttemptCompilation] == 0) {
68 LOG(INFO) << "Did not compile any method.";
69 } else {
70 size_t unoptimized_percent =
71 compile_stats_[kCompiledBaseline] * 100 / compile_stats_[kAttemptCompilation];
72 size_t optimized_percent =
73 compile_stats_[kCompiledOptimized] * 100 / compile_stats_[kAttemptCompilation];
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010074 size_t quick_percent =
75 compile_stats_[kCompiledQuick] * 100 / compile_stats_[kAttemptCompilation];
Calin Juravle48c2b032014-12-09 18:11:36 +000076 std::ostringstream oss;
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010077 oss << "Attempted compilation of " << compile_stats_[kAttemptCompilation] << " methods: ";
78
79 oss << unoptimized_percent << "% (" << compile_stats_[kCompiledBaseline] << ") unoptimized, ";
80 oss << optimized_percent << "% (" << compile_stats_[kCompiledOptimized] << ") optimized, ";
81 oss << quick_percent << "% (" << compile_stats_[kCompiledQuick] << ") quick.";
82
83 LOG(INFO) << oss.str();
84
Calin Juravle48c2b032014-12-09 18:11:36 +000085 for (int i = 0; i < kLastStat; i++) {
86 if (compile_stats_[i] != 0) {
Calin Juravle2be39e02015-04-21 13:56:34 +010087 LOG(INFO) << PrintMethodCompilationStat(i) << ": " << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +000088 }
89 }
Calin Juravle48c2b032014-12-09 18:11:36 +000090 }
91 }
92
93 private:
94 std::string PrintMethodCompilationStat(int stat) const {
95 switch (stat) {
96 case kAttemptCompilation : return "kAttemptCompilation";
97 case kCompiledBaseline : return "kCompiledBaseline";
98 case kCompiledOptimized : return "kCompiledOptimized";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010099 case kCompiledQuick : return "kCompiledQuick";
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000100 case kInlinedInvoke : return "kInlinedInvoke";
Calin Juravle8f20bdb2015-04-21 14:07:50 +0100101 case kInstructionSimplifications: return "kInstructionSimplifications";
Calin Juravle702d2602015-04-30 19:28:21 +0100102 case kNotCompiledBranchOutsideMethodCode: return "kNotCompiledBranchOutsideMethodCode";
103 case kNotCompiledCannotBuildSSA : return "kNotCompiledCannotBuildSSA";
104 case kNotCompiledCantAccesType : return "kNotCompiledCantAccesType";
105 case kNotCompiledClassNotVerified : return "kNotCompiledClassNotVerified";
Calin Juravle48c2b032014-12-09 18:11:36 +0000106 case kNotCompiledHugeMethod : return "kNotCompiledHugeMethod";
107 case kNotCompiledLargeMethodNoBranches : return "kNotCompiledLargeMethodNoBranches";
Calin Juravle48c2b032014-12-09 18:11:36 +0000108 case kNotCompiledNoCodegen : return "kNotCompiledNoCodegen";
Calin Juravle48c2b032014-12-09 18:11:36 +0000109 case kNotCompiledNonSequentialRegPair : return "kNotCompiledNonSequentialRegPair";
Calin Juravle702d2602015-04-30 19:28:21 +0100110 case kNotCompiledPathological : return "kNotCompiledPathological";
Nicolas Geoffray36540cb2015-03-23 14:45:53 +0000111 case kNotCompiledSpaceFilter : return "kNotCompiledSpaceFilter";
Calin Juravle48c2b032014-12-09 18:11:36 +0000112 case kNotCompiledUnhandledInstruction : return "kNotCompiledUnhandledInstruction";
Calin Juravle702d2602015-04-30 19:28:21 +0100113 case kNotCompiledUnresolvedField : return "kNotCompiledUnresolvedField";
114 case kNotCompiledUnresolvedMethod : return "kNotCompiledUnresolvedMethod";
115 case kNotCompiledUnsupportedIsa : return "kNotCompiledUnsupportedIsa";
Calin Juravlef1c6d9e2015-04-13 18:42:21 +0100116 case kNotCompiledVerifyAtRuntime : return "kNotCompiledVerifyAtRuntime";
Calin Juravle702d2602015-04-30 19:28:21 +0100117 case kNotOptimizedDisabled : return "kNotOptimizedDisabled";
118 case kNotOptimizedRegisterAllocator : return "kNotOptimizedRegisterAllocator";
119 case kNotOptimizedTryCatch : return "kNotOptimizedTryCatch";
Calin Juravleacf735c2015-02-12 15:25:22 +0000120 case kRemovedCheckedCast: return "kRemovedCheckedCast";
Calin Juravle8f20bdb2015-04-21 14:07:50 +0100121 case kRemovedDeadInstruction: return "kRemovedDeadInstruction";
Calin Juravleacf735c2015-02-12 15:25:22 +0000122 case kRemovedNullCheck: return "kRemovedNullCheck";
Calin Juravle48c2b032014-12-09 18:11:36 +0000123 default: LOG(FATAL) << "invalid stat";
124 }
125 return "";
126 }
127
128 AtomicInteger compile_stats_[kLastStat];
129
130 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
131};
132
133} // namespace art
134
135#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_