blob: b97a66719daaf878402f90ea9ceef2994bed06e9 [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 Juravleacf735c2015-02-12 15:25:22 +000048 kRemovedCheckedCast,
49 kRemovedNullCheck,
Calin Juravle48c2b032014-12-09 18:11:36 +000050 kLastStat
51};
52
53class OptimizingCompilerStats {
54 public:
55 OptimizingCompilerStats() {}
56
57 void RecordStat(MethodCompilationStat stat) {
58 compile_stats_[stat]++;
59 }
60
61 void Log() const {
62 if (compile_stats_[kAttemptCompilation] == 0) {
63 LOG(INFO) << "Did not compile any method.";
64 } else {
65 size_t unoptimized_percent =
66 compile_stats_[kCompiledBaseline] * 100 / compile_stats_[kAttemptCompilation];
67 size_t optimized_percent =
68 compile_stats_[kCompiledOptimized] * 100 / compile_stats_[kAttemptCompilation];
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010069 size_t quick_percent =
70 compile_stats_[kCompiledQuick] * 100 / compile_stats_[kAttemptCompilation];
Calin Juravle48c2b032014-12-09 18:11:36 +000071 std::ostringstream oss;
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010072 oss << "Attempted compilation of " << compile_stats_[kAttemptCompilation] << " methods: ";
73
74 oss << unoptimized_percent << "% (" << compile_stats_[kCompiledBaseline] << ") unoptimized, ";
75 oss << optimized_percent << "% (" << compile_stats_[kCompiledOptimized] << ") optimized, ";
76 oss << quick_percent << "% (" << compile_stats_[kCompiledQuick] << ") quick.";
77
78 LOG(INFO) << oss.str();
79
Calin Juravle48c2b032014-12-09 18:11:36 +000080 for (int i = 0; i < kLastStat; i++) {
81 if (compile_stats_[i] != 0) {
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010082 VLOG(compiler) << PrintMethodCompilationStat(i) << ": " << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +000083 }
84 }
Calin Juravle48c2b032014-12-09 18:11:36 +000085 }
86 }
87
88 private:
89 std::string PrintMethodCompilationStat(int stat) const {
90 switch (stat) {
91 case kAttemptCompilation : return "kAttemptCompilation";
92 case kCompiledBaseline : return "kCompiledBaseline";
93 case kCompiledOptimized : return "kCompiledOptimized";
Nicolas Geoffray12be74e2015-03-30 13:29:08 +010094 case kCompiledQuick : return "kCompiledQuick";
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000095 case kInlinedInvoke : return "kInlinedInvoke";
Calin Juravle48c2b032014-12-09 18:11:36 +000096 case kNotCompiledUnsupportedIsa : return "kNotCompiledUnsupportedIsa";
97 case kNotCompiledPathological : return "kNotCompiledPathological";
98 case kNotCompiledHugeMethod : return "kNotCompiledHugeMethod";
99 case kNotCompiledLargeMethodNoBranches : return "kNotCompiledLargeMethodNoBranches";
100 case kNotCompiledCannotBuildSSA : return "kNotCompiledCannotBuildSSA";
101 case kNotCompiledNoCodegen : return "kNotCompiledNoCodegen";
102 case kNotCompiledUnresolvedMethod : return "kNotCompiledUnresolvedMethod";
103 case kNotCompiledUnresolvedField : return "kNotCompiledUnresolvedField";
104 case kNotCompiledNonSequentialRegPair : return "kNotCompiledNonSequentialRegPair";
Calin Juravle48c2b032014-12-09 18:11:36 +0000105 case kNotOptimizedDisabled : return "kNotOptimizedDisabled";
106 case kNotOptimizedTryCatch : return "kNotOptimizedTryCatch";
107 case kNotCompiledCantAccesType : return "kNotCompiledCantAccesType";
Nicolas Geoffray36540cb2015-03-23 14:45:53 +0000108 case kNotCompiledSpaceFilter : return "kNotCompiledSpaceFilter";
Calin Juravle48c2b032014-12-09 18:11:36 +0000109 case kNotOptimizedRegisterAllocator : return "kNotOptimizedRegisterAllocator";
110 case kNotCompiledUnhandledInstruction : return "kNotCompiledUnhandledInstruction";
Calin Juravleacf735c2015-02-12 15:25:22 +0000111 case kRemovedCheckedCast: return "kRemovedCheckedCast";
112 case kRemovedNullCheck: return "kRemovedNullCheck";
Calin Juravle48c2b032014-12-09 18:11:36 +0000113 default: LOG(FATAL) << "invalid stat";
114 }
115 return "";
116 }
117
118 AtomicInteger compile_stats_[kLastStat];
119
120 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
121};
122
123} // namespace art
124
125#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_