blob: 65c84e694243b3d726c043c0cdec603236121ade [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,
Calin Juravle8f20bdb2015-04-21 14:07:50 +010032 kInstructionSimplifications,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000033 kInlinedInvoke,
Calin Juravle48c2b032014-12-09 18:11:36 +000034 kNotCompiledUnsupportedIsa,
35 kNotCompiledPathological,
36 kNotCompiledHugeMethod,
37 kNotCompiledLargeMethodNoBranches,
38 kNotCompiledCannotBuildSSA,
39 kNotCompiledNoCodegen,
40 kNotCompiledUnresolvedMethod,
41 kNotCompiledUnresolvedField,
42 kNotCompiledNonSequentialRegPair,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000043 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000044 kNotOptimizedTryCatch,
45 kNotOptimizedDisabled,
46 kNotCompiledCantAccesType,
47 kNotOptimizedRegisterAllocator,
48 kNotCompiledUnhandledInstruction,
Calin Juravlef1c6d9e2015-04-13 18:42:21 +010049 kNotCompiledVerifyAtRuntime,
50 kNotCompiledClassNotVerified,
Calin Juravleacf735c2015-02-12 15:25:22 +000051 kRemovedCheckedCast,
Calin Juravle8f20bdb2015-04-21 14:07:50 +010052 kRemovedDeadInstruction,
Calin Juravleacf735c2015-02-12 15:25:22 +000053 kRemovedNullCheck,
Calin Juravle48c2b032014-12-09 18:11:36 +000054 kLastStat
55};
56
57class OptimizingCompilerStats {
58 public:
59 OptimizingCompilerStats() {}
60
David Brazdil2d7352b2015-04-20 14:52:42 +010061 void RecordStat(MethodCompilationStat stat, size_t count = 1) {
62 compile_stats_[stat] += count;
Calin Juravle48c2b032014-12-09 18:11:36 +000063 }
64
65 void Log() const {
66 if (compile_stats_[kAttemptCompilation] == 0) {
67 LOG(INFO) << "Did not compile any method.";
68 } else {
69 size_t unoptimized_percent =
70 compile_stats_[kCompiledBaseline] * 100 / compile_stats_[kAttemptCompilation];
71 size_t optimized_percent =
72 compile_stats_[kCompiledOptimized] * 100 / compile_stats_[kAttemptCompilation];
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010073 size_t quick_percent =
74 compile_stats_[kCompiledQuick] * 100 / compile_stats_[kAttemptCompilation];
Calin Juravle48c2b032014-12-09 18:11:36 +000075 std::ostringstream oss;
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010076 oss << "Attempted compilation of " << compile_stats_[kAttemptCompilation] << " methods: ";
77
78 oss << unoptimized_percent << "% (" << compile_stats_[kCompiledBaseline] << ") unoptimized, ";
79 oss << optimized_percent << "% (" << compile_stats_[kCompiledOptimized] << ") optimized, ";
80 oss << quick_percent << "% (" << compile_stats_[kCompiledQuick] << ") quick.";
81
82 LOG(INFO) << oss.str();
83
Calin Juravle48c2b032014-12-09 18:11:36 +000084 for (int i = 0; i < kLastStat; i++) {
85 if (compile_stats_[i] != 0) {
Calin Juravle2be39e02015-04-21 13:56:34 +010086 LOG(INFO) << PrintMethodCompilationStat(i) << ": " << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +000087 }
88 }
Calin Juravle48c2b032014-12-09 18:11:36 +000089 }
90 }
91
92 private:
93 std::string PrintMethodCompilationStat(int stat) const {
94 switch (stat) {
95 case kAttemptCompilation : return "kAttemptCompilation";
96 case kCompiledBaseline : return "kCompiledBaseline";
97 case kCompiledOptimized : return "kCompiledOptimized";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010098 case kCompiledQuick : return "kCompiledQuick";
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000099 case kInlinedInvoke : return "kInlinedInvoke";
Calin Juravle8f20bdb2015-04-21 14:07:50 +0100100 case kInstructionSimplifications: return "kInstructionSimplifications";
Calin Juravle48c2b032014-12-09 18:11:36 +0000101 case kNotCompiledUnsupportedIsa : return "kNotCompiledUnsupportedIsa";
102 case kNotCompiledPathological : return "kNotCompiledPathological";
103 case kNotCompiledHugeMethod : return "kNotCompiledHugeMethod";
104 case kNotCompiledLargeMethodNoBranches : return "kNotCompiledLargeMethodNoBranches";
105 case kNotCompiledCannotBuildSSA : return "kNotCompiledCannotBuildSSA";
106 case kNotCompiledNoCodegen : return "kNotCompiledNoCodegen";
107 case kNotCompiledUnresolvedMethod : return "kNotCompiledUnresolvedMethod";
108 case kNotCompiledUnresolvedField : return "kNotCompiledUnresolvedField";
109 case kNotCompiledNonSequentialRegPair : return "kNotCompiledNonSequentialRegPair";
Calin Juravle48c2b032014-12-09 18:11:36 +0000110 case kNotOptimizedDisabled : return "kNotOptimizedDisabled";
111 case kNotOptimizedTryCatch : return "kNotOptimizedTryCatch";
112 case kNotCompiledCantAccesType : return "kNotCompiledCantAccesType";
Nicolas Geoffray36540cb2015-03-23 14:45:53 +0000113 case kNotCompiledSpaceFilter : return "kNotCompiledSpaceFilter";
Calin Juravle48c2b032014-12-09 18:11:36 +0000114 case kNotOptimizedRegisterAllocator : return "kNotOptimizedRegisterAllocator";
115 case kNotCompiledUnhandledInstruction : return "kNotCompiledUnhandledInstruction";
Calin Juravlef1c6d9e2015-04-13 18:42:21 +0100116 case kNotCompiledVerifyAtRuntime : return "kNotCompiledVerifyAtRuntime";
117 case kNotCompiledClassNotVerified : return "kNotCompiledClassNotVerified";
Calin Juravleacf735c2015-02-12 15:25:22 +0000118 case kRemovedCheckedCast: return "kRemovedCheckedCast";
Calin Juravle8f20bdb2015-04-21 14:07:50 +0100119 case kRemovedDeadInstruction: return "kRemovedDeadInstruction";
Calin Juravleacf735c2015-02-12 15:25:22 +0000120 case kRemovedNullCheck: return "kRemovedNullCheck";
Calin Juravle48c2b032014-12-09 18:11:36 +0000121 default: LOG(FATAL) << "invalid stat";
122 }
123 return "";
124 }
125
126 AtomicInteger compile_stats_[kLastStat];
127
128 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
129};
130
131} // namespace art
132
133#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_