blob: b988813f75aaff40e3a826166c51c9c629e0e166 [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,
35 kNotCompiledBranchOutsideMethodCode,
36 kNotCompiledCannotBuildSSA,
37 kNotCompiledCantAccesType,
38 kNotCompiledClassNotVerified,
Calin Juravle48c2b032014-12-09 18:11:36 +000039 kNotCompiledHugeMethod,
40 kNotCompiledLargeMethodNoBranches,
Calin Juravle48c2b032014-12-09 18:11:36 +000041 kNotCompiledNoCodegen,
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) {
Andreas Gampeda9badb2015-06-05 20:22:12 -070087 LOG(INFO) << PrintMethodCompilationStat(static_cast<MethodCompilationStat>(i)) << ": "
88 << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +000089 }
90 }
Calin Juravle48c2b032014-12-09 18:11:36 +000091 }
92 }
93
94 private:
Andreas Gampeda9badb2015-06-05 20:22:12 -070095 std::string PrintMethodCompilationStat(MethodCompilationStat stat) const {
Calin Juravle48c2b032014-12-09 18:11:36 +000096 switch (stat) {
97 case kAttemptCompilation : return "kAttemptCompilation";
98 case kCompiledBaseline : return "kCompiledBaseline";
99 case kCompiledOptimized : return "kCompiledOptimized";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +0100100 case kCompiledQuick : return "kCompiledQuick";
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000101 case kInlinedInvoke : return "kInlinedInvoke";
Calin Juravle8f20bdb2015-04-21 14:07:50 +0100102 case kInstructionSimplifications: return "kInstructionSimplifications";
Calin Juravle702d2602015-04-30 19:28:21 +0100103 case kNotCompiledBranchOutsideMethodCode: return "kNotCompiledBranchOutsideMethodCode";
104 case kNotCompiledCannotBuildSSA : return "kNotCompiledCannotBuildSSA";
105 case kNotCompiledCantAccesType : return "kNotCompiledCantAccesType";
106 case kNotCompiledClassNotVerified : return "kNotCompiledClassNotVerified";
Calin Juravle48c2b032014-12-09 18:11:36 +0000107 case kNotCompiledHugeMethod : return "kNotCompiledHugeMethod";
108 case kNotCompiledLargeMethodNoBranches : return "kNotCompiledLargeMethodNoBranches";
Calin Juravle48c2b032014-12-09 18:11:36 +0000109 case kNotCompiledNoCodegen : return "kNotCompiledNoCodegen";
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";
Andreas Gampeda9badb2015-06-05 20:22:12 -0700123
124 case kLastStat: break; // Invalid to print out.
Calin Juravle48c2b032014-12-09 18:11:36 +0000125 }
Andreas Gampeda9badb2015-06-05 20:22:12 -0700126 LOG(FATAL) << "invalid stat "
127 << static_cast<std::underlying_type<MethodCompilationStat>::type>(stat);
128 UNREACHABLE();
Calin Juravle48c2b032014-12-09 18:11:36 +0000129 }
130
131 AtomicInteger compile_stats_[kLastStat];
132
133 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
134};
135
136} // namespace art
137
138#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_