blob: 3ebf0f8cd28b8aff17d0a8eb4c1bf399733a9284 [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,
Calin Juravle48c2b032014-12-09 18:11:36 +000041 kNotOptimizedTryCatch,
42 kNotOptimizedDisabled,
43 kNotCompiledCantAccesType,
44 kNotOptimizedRegisterAllocator,
45 kNotCompiledUnhandledInstruction,
Calin Juravleacf735c2015-02-12 15:25:22 +000046 kRemovedCheckedCast,
47 kRemovedNullCheck,
Calin Juravle48c2b032014-12-09 18:11:36 +000048 kLastStat
49};
50
51class OptimizingCompilerStats {
52 public:
53 OptimizingCompilerStats() {}
54
55 void RecordStat(MethodCompilationStat stat) {
56 compile_stats_[stat]++;
57 }
58
59 void Log() const {
60 if (compile_stats_[kAttemptCompilation] == 0) {
61 LOG(INFO) << "Did not compile any method.";
62 } else {
63 size_t unoptimized_percent =
64 compile_stats_[kCompiledBaseline] * 100 / compile_stats_[kAttemptCompilation];
65 size_t optimized_percent =
66 compile_stats_[kCompiledOptimized] * 100 / compile_stats_[kAttemptCompilation];
67 std::ostringstream oss;
68 oss << "Attempted compilation of " << compile_stats_[kAttemptCompilation] << " methods: "
69 << unoptimized_percent << "% (" << compile_stats_[kCompiledBaseline] << ") unoptimized, "
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000070 << optimized_percent << "% (" << compile_stats_[kCompiledOptimized] << ") optimized.";
Calin Juravle48c2b032014-12-09 18:11:36 +000071 for (int i = 0; i < kLastStat; i++) {
72 if (compile_stats_[i] != 0) {
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000073 oss << "\n" << PrintMethodCompilationStat(i) << ": " << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +000074 }
75 }
76 LOG(INFO) << oss.str();
77 }
78 }
79
80 private:
81 std::string PrintMethodCompilationStat(int stat) const {
82 switch (stat) {
83 case kAttemptCompilation : return "kAttemptCompilation";
84 case kCompiledBaseline : return "kCompiledBaseline";
85 case kCompiledOptimized : return "kCompiledOptimized";
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000086 case kInlinedInvoke : return "kInlinedInvoke";
Calin Juravle48c2b032014-12-09 18:11:36 +000087 case kNotCompiledUnsupportedIsa : return "kNotCompiledUnsupportedIsa";
88 case kNotCompiledPathological : return "kNotCompiledPathological";
89 case kNotCompiledHugeMethod : return "kNotCompiledHugeMethod";
90 case kNotCompiledLargeMethodNoBranches : return "kNotCompiledLargeMethodNoBranches";
91 case kNotCompiledCannotBuildSSA : return "kNotCompiledCannotBuildSSA";
92 case kNotCompiledNoCodegen : return "kNotCompiledNoCodegen";
93 case kNotCompiledUnresolvedMethod : return "kNotCompiledUnresolvedMethod";
94 case kNotCompiledUnresolvedField : return "kNotCompiledUnresolvedField";
95 case kNotCompiledNonSequentialRegPair : return "kNotCompiledNonSequentialRegPair";
Calin Juravle48c2b032014-12-09 18:11:36 +000096 case kNotOptimizedDisabled : return "kNotOptimizedDisabled";
97 case kNotOptimizedTryCatch : return "kNotOptimizedTryCatch";
98 case kNotCompiledCantAccesType : return "kNotCompiledCantAccesType";
99 case kNotOptimizedRegisterAllocator : return "kNotOptimizedRegisterAllocator";
100 case kNotCompiledUnhandledInstruction : return "kNotCompiledUnhandledInstruction";
Calin Juravleacf735c2015-02-12 15:25:22 +0000101 case kRemovedCheckedCast: return "kRemovedCheckedCast";
102 case kRemovedNullCheck: return "kRemovedNullCheck";
Calin Juravle48c2b032014-12-09 18:11:36 +0000103 default: LOG(FATAL) << "invalid stat";
104 }
105 return "";
106 }
107
108 AtomicInteger compile_stats_[kLastStat];
109
110 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
111};
112
113} // namespace art
114
115#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_