diff options
author | Jean-Marie Henaff <jmhenaff@google.com> | 2014-05-21 15:50:02 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-21 15:50:03 +0000 |
commit | b3d3bb5f259a22cc06c1721b311eee89d91b89fb (patch) | |
tree | f3b1dfcac917ccb7c83ae484f9b989a8580b2070 | |
parent | c54cc9e6026b219d3fce9a2a232210e6e140fd34 (diff) | |
parent | 6b04aadbc2564b18de5beedf978797a6a88fdca3 (diff) | |
download | toolchain_jack-b3d3bb5f259a22cc06c1721b311eee89d91b89fb.zip toolchain_jack-b3d3bb5f259a22cc06c1721b311eee89d91b89fb.tar.gz toolchain_jack-b3d3bb5f259a22cc06c1721b311eee89d91b89fb.tar.bz2 |
Merge "Add small stats Schedulables on JMethod and JField." into jack-wip-dev
-rw-r--r-- | jack/src/com/android/jack/Jack.java | 20 | ||||
-rw-r--r-- | jack/src/com/android/jack/Options.java | 5 | ||||
-rw-r--r-- | jack/src/com/android/jack/scheduling/feature/CompiledTypeStats.java | 27 | ||||
-rw-r--r-- | jack/src/com/android/jack/statistics/FieldStats.java | 63 | ||||
-rw-r--r-- | jack/src/com/android/jack/statistics/MethodStats.java | 81 |
5 files changed, 195 insertions, 1 deletions
diff --git a/jack/src/com/android/jack/Jack.java b/jack/src/com/android/jack/Jack.java index 6e03f00..8b2f9f6 100644 --- a/jack/src/com/android/jack/Jack.java +++ b/jack/src/com/android/jack/Jack.java @@ -90,6 +90,7 @@ import com.android.jack.scheduling.adapter.JDefinedClassOrInterfaceAdapter; import com.android.jack.scheduling.adapter.JFieldAdapter; import com.android.jack.scheduling.adapter.JMethodAdapter; import com.android.jack.scheduling.adapter.JPackageAdapter; +import com.android.jack.scheduling.feature.CompiledTypeStats; import com.android.jack.scheduling.feature.DexNonZipOutput; import com.android.jack.scheduling.feature.DexZipOutput; import com.android.jack.scheduling.feature.DxLegacy; @@ -141,6 +142,8 @@ import com.android.jack.shrob.shrink.remover.MethodKeepMarkerRemover; import com.android.jack.shrob.shrink.remover.TypeShrinkMarkerRemover; import com.android.jack.shrob.spec.Flags; import com.android.jack.statistics.BinaryOperationWithCst; +import com.android.jack.statistics.FieldStats; +import com.android.jack.statistics.MethodStats; import com.android.jack.transformations.AssertionTransformer; import com.android.jack.transformations.AssertionTransformerSchedulingSeparator; import com.android.jack.transformations.EmptyClinitRemover; @@ -381,6 +384,10 @@ public abstract class Jack { request.addFeature(SourceVersion7.class); } + if (config.get(Options.ENABLE_COMPILED_FILES_STATISTICS).booleanValue()) { + request.addFeature(CompiledTypeStats.class); + } + if (options.hasSanityChecks()) { request.addFeature(SanityChecks.class); } @@ -789,13 +796,18 @@ public abstract class Jack { } SubPlanBuilder<JMethod> methodPlan = typePlan.appendSubPlan(JMethodAdapter.class); - + if (features.contains(CompiledTypeStats.class)) { + methodPlan.append(MethodStats.class); + } if (features.contains(LineDebugInfo.class)) { methodPlan.append(ThisRefDebugInfoAdder.class); } } { SubPlanBuilder<JField> fieldPlan = typePlan.appendSubPlan(JFieldAdapter.class); + if (features.contains(CompiledTypeStats.class)) { + fieldPlan.append(FieldStats.class); + } fieldPlan.append(FieldInitializerRemover.class); } } @@ -1076,6 +1088,9 @@ public abstract class Jack { { SubPlanBuilder<JMethod> methodPlan = typePlan7.appendSubPlan(JMethodAdapter.class); + if (features.contains(CompiledTypeStats.class)) { + methodPlan.append(MethodStats.class); + } if (features.contains(LineDebugInfo.class)) { methodPlan.append(ThisRefDebugInfoAdder.class); } @@ -1083,6 +1098,9 @@ public abstract class Jack { { SubPlanBuilder<JField> fieldPlan = typePlan7.appendSubPlan(JFieldAdapter.class); + if (features.contains(CompiledTypeStats.class)) { + fieldPlan.append(FieldStats.class); + } fieldPlan.append(FieldInitializerRemover.class); } } diff --git a/jack/src/com/android/jack/Options.java b/jack/src/com/android/jack/Options.java index 6b8fae6..68229a7 100644 --- a/jack/src/com/android/jack/Options.java +++ b/jack/src/com/android/jack/Options.java @@ -132,6 +132,11 @@ public class Options { "jack.dex.output", "Dex output file", new PathCodec()) .requiredIf(GENERATE_DEX_FILE.getValue().isTrue()); + @Nonnull + public static final BooleanPropertyId ENABLE_COMPILED_FILES_STATISTICS = BooleanPropertyId.create( + "jack.statistic.source", "Enable compiled files statistics").addDefaultValue( + Boolean.FALSE); + @Option(name = "-v", aliases = "--version", usage = "display options") protected boolean version; diff --git a/jack/src/com/android/jack/scheduling/feature/CompiledTypeStats.java b/jack/src/com/android/jack/scheduling/feature/CompiledTypeStats.java new file mode 100644 index 0000000..c9e53bd --- /dev/null +++ b/jack/src/com/android/jack/scheduling/feature/CompiledTypeStats.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.scheduling.feature; + +import com.android.sched.item.Description; +import com.android.sched.item.Feature; + +/** + * A {@link Feature} that gives statistics about compiled types. + */ +@Description("Stats on compiled types") +public class CompiledTypeStats implements Feature { +} diff --git a/jack/src/com/android/jack/statistics/FieldStats.java b/jack/src/com/android/jack/statistics/FieldStats.java new file mode 100644 index 0000000..73514a8 --- /dev/null +++ b/jack/src/com/android/jack/statistics/FieldStats.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.statistics; + +import com.android.jack.ir.ast.JField; +import com.android.jack.scheduling.feature.CompiledTypeStats; +import com.android.sched.item.Description; +import com.android.sched.schedulable.RunnableSchedulable; +import com.android.sched.schedulable.Support; +import com.android.sched.util.log.Tracer; +import com.android.sched.util.log.TracerFactory; +import com.android.sched.util.log.stats.Counter; +import com.android.sched.util.log.stats.CounterImpl; +import com.android.sched.util.log.stats.StatisticId; + +import java.lang.reflect.Modifier; + +import javax.annotation.Nonnull; + +/** + * This {@link RunnableSchedulable} computes some statistics about compiled fields. + */ +@Description("Computes some statistics about compiled fields.") +@Support(CompiledTypeStats.class) +public class FieldStats implements RunnableSchedulable<JField> { + + @Nonnull + public static final StatisticId<Counter> INSTANCE_FIELDS_COUNT = new StatisticId<Counter>( + "jack.source.field.instance", "Instance fields", + CounterImpl.class, Counter.class); + + @Nonnull + public static final StatisticId<Counter> STATIC_FIELDS_COUNT = new StatisticId<Counter>( + "jack.source.field.static", "Static fields", + CounterImpl.class, Counter.class); + + @Override + public void run(@Nonnull JField field) throws Exception { + if (field.isExternal()) { + return; + } + Tracer tracer = TracerFactory.getTracer(); + if (Modifier.isStatic(field.getModifier())) { + tracer.getStatistic(STATIC_FIELDS_COUNT).incValue(); + } else { + tracer.getStatistic(INSTANCE_FIELDS_COUNT).incValue(); + } + } +} diff --git a/jack/src/com/android/jack/statistics/MethodStats.java b/jack/src/com/android/jack/statistics/MethodStats.java new file mode 100644 index 0000000..93102a4 --- /dev/null +++ b/jack/src/com/android/jack/statistics/MethodStats.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.statistics; + +import com.android.jack.Options; +import com.android.jack.ir.ast.JMethod; +import com.android.jack.scheduling.feature.CompiledTypeStats; +import com.android.jack.util.filter.Filter; +import com.android.sched.item.Description; +import com.android.sched.schedulable.RunnableSchedulable; +import com.android.sched.schedulable.Support; +import com.android.sched.util.config.ThreadConfig; +import com.android.sched.util.log.Tracer; +import com.android.sched.util.log.TracerFactory; +import com.android.sched.util.log.stats.Counter; +import com.android.sched.util.log.stats.CounterImpl; +import com.android.sched.util.log.stats.Percent; +import com.android.sched.util.log.stats.PercentImpl; +import com.android.sched.util.log.stats.StatisticId; + +import java.lang.reflect.Modifier; + +import javax.annotation.Nonnull; + +/** + * This {@link RunnableSchedulable} computes some statistics about compiled methods. + */ +@Description("Computes some statistics about compiled methods.") +@Support(CompiledTypeStats.class) +public class MethodStats implements RunnableSchedulable<JMethod> { + + @Nonnull + private final Filter<JMethod> filter = ThreadConfig.get(Options.METHOD_FILTER); + + @Nonnull + public static final StatisticId<Percent> CONCRETE_METHODS_PERCENT = new StatisticId<Percent>( + "jack.source.method.concrete", "Concrete methods", + PercentImpl.class, Percent.class); + + @Nonnull + public static final StatisticId<Counter> INSTANCE_METHODS_COUNT = new StatisticId<Counter>( + "jack.source.method.instance", "Instance methods", + CounterImpl.class, Counter.class); + + @Nonnull + public static final StatisticId<Counter> STATIC_METHODS_COUNT = new StatisticId<Counter>( + "jack.source.method.static", "Static methods", + CounterImpl.class, Counter.class); + + @Override + public void run(@Nonnull JMethod method) throws Exception { + if (method.getEnclosingType().isExternal() || !filter.accept(this.getClass(), method)) { + return; + } + Tracer tracer = TracerFactory.getTracer(); + if (!method.isNative() && !method.isAbstract()) { + tracer.getStatistic(CONCRETE_METHODS_PERCENT).addTrue(); + } else { + tracer.getStatistic(CONCRETE_METHODS_PERCENT).addFalse(); + } + if (Modifier.isStatic(method.getModifier())) { + tracer.getStatistic(STATIC_METHODS_COUNT).incValue(); + } else { + tracer.getStatistic(INSTANCE_METHODS_COUNT).incValue(); + } + } +} |