blob: d4a936d1c3feee95e1ac85b520226fecba6f1f3b [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 Juravle48c2b032014-12-09 18:11:36 +000033 kNotCompiledUnsupportedIsa,
34 kNotCompiledPathological,
35 kNotCompiledHugeMethod,
36 kNotCompiledLargeMethodNoBranches,
37 kNotCompiledCannotBuildSSA,
38 kNotCompiledNoCodegen,
39 kNotCompiledUnresolvedMethod,
40 kNotCompiledUnresolvedField,
41 kNotCompiledNonSequentialRegPair,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000042 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000043 kNotOptimizedTryCatch,
44 kNotOptimizedDisabled,
45 kNotCompiledCantAccesType,
46 kNotOptimizedRegisterAllocator,
47 kNotCompiledUnhandledInstruction,
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010048 kNotCompiledVerifyAtRuntime,
49 kNotCompiledClassNotVerified,
Calin Juravleacf735c2015-02-12 15:25:22 +000050 kRemovedCheckedCast,
51 kRemovedNullCheck,
Alexandre Rames188d4312015-04-09 18:30:21 +010052 kInstructionSimplifications,
Calin Juravle48c2b032014-12-09 18:11:36 +000053 kLastStat
54};
55
56class OptimizingCompilerStats {
57 public:
58 OptimizingCompilerStats() {}
59
60 void RecordStat(MethodCompilationStat stat) {
61 compile_stats_[stat]++;
62 }
63
64 void Log() const {
65 if (compile_stats_[kAttemptCompilation] == 0) {
66 LOG(INFO) << "Did not compile any method.";
67 } else {
68 size_t unoptimized_percent =
69 compile_stats_[kCompiledBaseline] * 100 / compile_stats_[kAttemptCompilation];
70 size_t optimized_percent =
71 compile_stats_[kCompiledOptimized] * 100 / compile_stats_[kAttemptCompilation];
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010072 size_t quick_percent =
73 compile_stats_[kCompiledQuick] * 100 / compile_stats_[kAttemptCompilation];
Calin Juravle48c2b032014-12-09 18:11:36 +000074 std::ostringstream oss;
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010075 oss << "Attempted compilation of " << compile_stats_[kAttemptCompilation] << " methods: ";
76
77 oss << unoptimized_percent << "% (" << compile_stats_[kCompiledBaseline] << ") unoptimized, ";
78 oss << optimized_percent << "% (" << compile_stats_[kCompiledOptimized] << ") optimized, ";
79 oss << quick_percent << "% (" << compile_stats_[kCompiledQuick] << ") quick.";
80
81 LOG(INFO) << oss.str();
82
Calin Juravle48c2b032014-12-09 18:11:36 +000083 for (int i = 0; i < kLastStat; i++) {
84 if (compile_stats_[i] != 0) {
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010085 VLOG(compiler) << PrintMethodCompilationStat(i) << ": " << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +000086 }
87 }
Calin Juravle48c2b032014-12-09 18:11:36 +000088 }
89 }
90
91 private:
92 std::string PrintMethodCompilationStat(int stat) const {
93 switch (stat) {
94 case kAttemptCompilation : return "kAttemptCompilation";
95 case kCompiledBaseline : return "kCompiledBaseline";
96 case kCompiledOptimized : return "kCompiledOptimized";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010097 case kCompiledQuick : return "kCompiledQuick";
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000098 case kInlinedInvoke : return "kInlinedInvoke";
Calin Juravle48c2b032014-12-09 18:11:36 +000099 case kNotCompiledUnsupportedIsa : return "kNotCompiledUnsupportedIsa";
100 case kNotCompiledPathological : return "kNotCompiledPathological";
101 case kNotCompiledHugeMethod : return "kNotCompiledHugeMethod";
102 case kNotCompiledLargeMethodNoBranches : return "kNotCompiledLargeMethodNoBranches";
103 case kNotCompiledCannotBuildSSA : return "kNotCompiledCannotBuildSSA";
104 case kNotCompiledNoCodegen : return "kNotCompiledNoCodegen";
105 case kNotCompiledUnresolvedMethod : return "kNotCompiledUnresolvedMethod";
106 case kNotCompiledUnresolvedField : return "kNotCompiledUnresolvedField";
107 case kNotCompiledNonSequentialRegPair : return "kNotCompiledNonSequentialRegPair";
Calin Juravle48c2b032014-12-09 18:11:36 +0000108 case kNotOptimizedDisabled : return "kNotOptimizedDisabled";
109 case kNotOptimizedTryCatch : return "kNotOptimizedTryCatch";
110 case kNotCompiledCantAccesType : return "kNotCompiledCantAccesType";
Nicolas Geoffray36540cb2015-03-23 14:45:53 +0000111 case kNotCompiledSpaceFilter : return "kNotCompiledSpaceFilter";
Calin Juravle48c2b032014-12-09 18:11:36 +0000112 case kNotOptimizedRegisterAllocator : return "kNotOptimizedRegisterAllocator";
113 case kNotCompiledUnhandledInstruction : return "kNotCompiledUnhandledInstruction";
Calin Juravlef1c6d9e2015-04-13 18:42:21 +0100114 case kNotCompiledVerifyAtRuntime : return "kNotCompiledVerifyAtRuntime";
115 case kNotCompiledClassNotVerified : return "kNotCompiledClassNotVerified";
Calin Juravleacf735c2015-02-12 15:25:22 +0000116 case kRemovedCheckedCast: return "kRemovedCheckedCast";
117 case kRemovedNullCheck: return "kRemovedNullCheck";
Alexandre Rames188d4312015-04-09 18:30:21 +0100118 case kInstructionSimplifications: return "kInstructionSimplifications";
Calin Juravle48c2b032014-12-09 18:11:36 +0000119 default: LOG(FATAL) << "invalid stat";
120 }
121 return "";
122 }
123
124 AtomicInteger compile_stats_[kLastStat];
125
126 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
127};
128
129} // namespace art
130
131#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_