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