blob: df45c8e89090ed3bcdc10cd62d0ec9a19dedbbe5 [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>
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,
30 kCompiledBaseline,
31 kCompiledOptimized,
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010032 kCompiledQuick,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000033 kInlinedInvoke,
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 Juravle702d2602015-04-30 19:28:21 +010039 kNotCompiledBranchOutsideMethodCode,
40 kNotCompiledCannotBuildSSA,
41 kNotCompiledCantAccesType,
42 kNotCompiledClassNotVerified,
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 Juravlef1c6d9e2015-04-13 18:42:21 +010051 kNotCompiledVerifyAtRuntime,
Calin Juravle702d2602015-04-30 19:28:21 +010052 kNotOptimizedDisabled,
53 kNotOptimizedRegisterAllocator,
54 kNotOptimizedTryCatch,
Calin Juravleacf735c2015-02-12 15:25:22 +000055 kRemovedCheckedCast,
Calin Juravle8f20bdb2015-04-21 14:07:50 +010056 kRemovedDeadInstruction,
Calin Juravleacf735c2015-02-12 15:25:22 +000057 kRemovedNullCheck,
Calin Juravle48c2b032014-12-09 18:11:36 +000058 kLastStat
59};
60
61class OptimizingCompilerStats {
62 public:
63 OptimizingCompilerStats() {}
64
David Brazdil2d7352b2015-04-20 14:52:42 +010065 void RecordStat(MethodCompilationStat stat, size_t count = 1) {
66 compile_stats_[stat] += count;
Calin Juravle48c2b032014-12-09 18:11:36 +000067 }
68
69 void Log() const {
70 if (compile_stats_[kAttemptCompilation] == 0) {
71 LOG(INFO) << "Did not compile any method.";
72 } else {
73 size_t unoptimized_percent =
74 compile_stats_[kCompiledBaseline] * 100 / compile_stats_[kAttemptCompilation];
75 size_t optimized_percent =
76 compile_stats_[kCompiledOptimized] * 100 / compile_stats_[kAttemptCompilation];
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010077 size_t quick_percent =
78 compile_stats_[kCompiledQuick] * 100 / compile_stats_[kAttemptCompilation];
Calin Juravle48c2b032014-12-09 18:11:36 +000079 std::ostringstream oss;
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010080 oss << "Attempted compilation of " << compile_stats_[kAttemptCompilation] << " methods: ";
81
82 oss << unoptimized_percent << "% (" << compile_stats_[kCompiledBaseline] << ") unoptimized, ";
83 oss << optimized_percent << "% (" << compile_stats_[kCompiledOptimized] << ") optimized, ";
84 oss << quick_percent << "% (" << compile_stats_[kCompiledQuick] << ") quick.";
85
86 LOG(INFO) << oss.str();
87
Calin Juravle48c2b032014-12-09 18:11:36 +000088 for (int i = 0; i < kLastStat; i++) {
89 if (compile_stats_[i] != 0) {
Andreas Gampeda9badb2015-06-05 20:22:12 -070090 LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": "
91 << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +000092 }
93 }
Calin Juravle48c2b032014-12-09 18:11:36 +000094 }
95 }
96
97 private:
Andreas Gampeda9badb2015-06-05 20:22:12 -070098 std::string PrintMethodCompilationStat(MethodCompilationStat stat) const {
Calin Juravle48c2b032014-12-09 18:11:36 +000099 switch (stat) {
100 case kAttemptCompilation : return "kAttemptCompilation";
101 case kCompiledBaseline : return "kCompiledBaseline";
102 case kCompiledOptimized : return "kCompiledOptimized";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +0100103 case kCompiledQuick : return "kCompiledQuick";
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000104 case kInlinedInvoke : return "kInlinedInvoke";
Calin Juravle8f20bdb2015-04-21 14:07:50 +0100105 case kInstructionSimplifications: return "kInstructionSimplifications";
Alexandre Rames44b9cf92015-08-19 15:39:06 +0100106 case kInstructionSimplificationsArch: return "kInstructionSimplificationsArch";
Calin Juravle175dc732015-08-25 15:42:32 +0100107 case kUnresolvedMethod : return "kUnresolvedMethod";
Calin Juravlee460d1d2015-09-29 04:52:17 +0100108 case kUnresolvedField : return "kUnresolvedField";
Calin Juravle07380a22015-09-17 14:15:12 +0100109 case kUnresolvedFieldNotAFastAccess : return "kUnresolvedFieldNotAFastAccess";
Calin Juravle702d2602015-04-30 19:28:21 +0100110 case kNotCompiledBranchOutsideMethodCode: return "kNotCompiledBranchOutsideMethodCode";
111 case kNotCompiledCannotBuildSSA : return "kNotCompiledCannotBuildSSA";
112 case kNotCompiledCantAccesType : return "kNotCompiledCantAccesType";
113 case kNotCompiledClassNotVerified : return "kNotCompiledClassNotVerified";
Calin Juravle48c2b032014-12-09 18:11:36 +0000114 case kNotCompiledHugeMethod : return "kNotCompiledHugeMethod";
115 case kNotCompiledLargeMethodNoBranches : return "kNotCompiledLargeMethodNoBranches";
Nicolas Geoffray2e335252015-06-18 11:11:27 +0100116 case kNotCompiledMalformedOpcode : return "kNotCompiledMalformedOpcode";
Calin Juravle48c2b032014-12-09 18:11:36 +0000117 case kNotCompiledNoCodegen : return "kNotCompiledNoCodegen";
Calin Juravle702d2602015-04-30 19:28:21 +0100118 case kNotCompiledPathological : return "kNotCompiledPathological";
Nicolas Geoffray36540cb2015-03-23 14:45:53 +0000119 case kNotCompiledSpaceFilter : return "kNotCompiledSpaceFilter";
Calin Juravle48c2b032014-12-09 18:11:36 +0000120 case kNotCompiledUnhandledInstruction : return "kNotCompiledUnhandledInstruction";
Calin Juravle702d2602015-04-30 19:28:21 +0100121 case kNotCompiledUnsupportedIsa : return "kNotCompiledUnsupportedIsa";
Calin Juravlef1c6d9e2015-04-13 18:42:21 +0100122 case kNotCompiledVerifyAtRuntime : return "kNotCompiledVerifyAtRuntime";
Calin Juravle702d2602015-04-30 19:28:21 +0100123 case kNotOptimizedDisabled : return "kNotOptimizedDisabled";
124 case kNotOptimizedRegisterAllocator : return "kNotOptimizedRegisterAllocator";
125 case kNotOptimizedTryCatch : return "kNotOptimizedTryCatch";
Calin Juravleacf735c2015-02-12 15:25:22 +0000126 case kRemovedCheckedCast: return "kRemovedCheckedCast";
Calin Juravle8f20bdb2015-04-21 14:07:50 +0100127 case kRemovedDeadInstruction: return "kRemovedDeadInstruction";
Calin Juravleacf735c2015-02-12 15:25:22 +0000128 case kRemovedNullCheck: return "kRemovedNullCheck";
Andreas Gampeda9badb2015-06-05 20:22:12 -0700129
130 case kLastStat: break; // Invalid to print out.
Calin Juravle48c2b032014-12-09 18:11:36 +0000131 }
Andreas Gampeda9badb2015-06-05 20:22:12 -0700132 LOG(FATAL) << "invalid stat "
133 << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat);
134 UNREACHABLE();
Calin Juravle48c2b032014-12-09 18:11:36 +0000135 }
136
137 AtomicInteger compile_stats_[kLastStat];
138
139 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
140};
141
142} // namespace art
143
144#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_