blob: 22ec2a5167e46b9fa5597d645814014065a21dbc [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 Geoffraye53798a2014-12-01 10:31:54 +000031 kInlinedInvoke,
Calin Juravle48c2b032014-12-09 18:11:36 +000032 kNotCompiledUnsupportedIsa,
33 kNotCompiledPathological,
34 kNotCompiledHugeMethod,
35 kNotCompiledLargeMethodNoBranches,
36 kNotCompiledCannotBuildSSA,
37 kNotCompiledNoCodegen,
38 kNotCompiledUnresolvedMethod,
39 kNotCompiledUnresolvedField,
40 kNotCompiledNonSequentialRegPair,
Nicolas Geoffray36540cb2015-03-23 14:45:53 +000041 kNotCompiledSpaceFilter,
Calin Juravle48c2b032014-12-09 18:11:36 +000042 kNotOptimizedTryCatch,
43 kNotOptimizedDisabled,
44 kNotCompiledCantAccesType,
45 kNotOptimizedRegisterAllocator,
46 kNotCompiledUnhandledInstruction,
Calin Juravleacf735c2015-02-12 15:25:22 +000047 kRemovedCheckedCast,
48 kRemovedNullCheck,
Calin Juravle48c2b032014-12-09 18:11:36 +000049 kLastStat
50};
51
52class OptimizingCompilerStats {
53 public:
54 OptimizingCompilerStats() {}
55
56 void RecordStat(MethodCompilationStat stat) {
57 compile_stats_[stat]++;
58 }
59
60 void Log() const {
61 if (compile_stats_[kAttemptCompilation] == 0) {
62 LOG(INFO) << "Did not compile any method.";
63 } else {
64 size_t unoptimized_percent =
65 compile_stats_[kCompiledBaseline] * 100 / compile_stats_[kAttemptCompilation];
66 size_t optimized_percent =
67 compile_stats_[kCompiledOptimized] * 100 / compile_stats_[kAttemptCompilation];
68 std::ostringstream oss;
69 oss << "Attempted compilation of " << compile_stats_[kAttemptCompilation] << " methods: "
70 << unoptimized_percent << "% (" << compile_stats_[kCompiledBaseline] << ") unoptimized, "
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000071 << optimized_percent << "% (" << compile_stats_[kCompiledOptimized] << ") optimized.";
Calin Juravle48c2b032014-12-09 18:11:36 +000072 for (int i = 0; i < kLastStat; i++) {
73 if (compile_stats_[i] != 0) {
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000074 oss << "\n" << PrintMethodCompilationStat(i) << ": " << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +000075 }
76 }
77 LOG(INFO) << oss.str();
78 }
79 }
80
81 private:
82 std::string PrintMethodCompilationStat(int stat) const {
83 switch (stat) {
84 case kAttemptCompilation : return "kAttemptCompilation";
85 case kCompiledBaseline : return "kCompiledBaseline";
86 case kCompiledOptimized : return "kCompiledOptimized";
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000087 case kInlinedInvoke : return "kInlinedInvoke";
Calin Juravle48c2b032014-12-09 18:11:36 +000088 case kNotCompiledUnsupportedIsa : return "kNotCompiledUnsupportedIsa";
89 case kNotCompiledPathological : return "kNotCompiledPathological";
90 case kNotCompiledHugeMethod : return "kNotCompiledHugeMethod";
91 case kNotCompiledLargeMethodNoBranches : return "kNotCompiledLargeMethodNoBranches";
92 case kNotCompiledCannotBuildSSA : return "kNotCompiledCannotBuildSSA";
93 case kNotCompiledNoCodegen : return "kNotCompiledNoCodegen";
94 case kNotCompiledUnresolvedMethod : return "kNotCompiledUnresolvedMethod";
95 case kNotCompiledUnresolvedField : return "kNotCompiledUnresolvedField";
96 case kNotCompiledNonSequentialRegPair : return "kNotCompiledNonSequentialRegPair";
Calin Juravle48c2b032014-12-09 18:11:36 +000097 case kNotOptimizedDisabled : return "kNotOptimizedDisabled";
98 case kNotOptimizedTryCatch : return "kNotOptimizedTryCatch";
99 case kNotCompiledCantAccesType : return "kNotCompiledCantAccesType";
Nicolas Geoffray36540cb2015-03-23 14:45:53 +0000100 case kNotCompiledSpaceFilter : return "kNotCompiledSpaceFilter";
Calin Juravle48c2b032014-12-09 18:11:36 +0000101 case kNotOptimizedRegisterAllocator : return "kNotOptimizedRegisterAllocator";
102 case kNotCompiledUnhandledInstruction : return "kNotCompiledUnhandledInstruction";
Calin Juravleacf735c2015-02-12 15:25:22 +0000103 case kRemovedCheckedCast: return "kRemovedCheckedCast";
104 case kRemovedNullCheck: return "kRemovedNullCheck";
Calin Juravle48c2b032014-12-09 18:11:36 +0000105 default: LOG(FATAL) << "invalid stat";
106 }
107 return "";
108 }
109
110 AtomicInteger compile_stats_[kLastStat];
111
112 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
113};
114
115} // namespace art
116
117#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_