use of org.robolectric.pluginapi.perf.Metric in project robolectric by robolectric.
the class PerfStatsCollectorTest method shouldRunAndMeasureCheckedException.
@Test
public void shouldRunAndMeasureCheckedException() throws Exception {
try {
collector.measure("event", () -> {
fakeClock.delay(5);
throw new IOException("fake");
});
fail("should have thrown");
} catch (IOException e) {
assertThat(e.getMessage()).isEqualTo("fake");
}
Collection<Metric> metrics = collector.getMetrics();
assertThat(metrics).contains(new Metric("event", 1, 5, false));
}
use of org.robolectric.pluginapi.perf.Metric in project robolectric by robolectric.
the class PerfStatsCollectorTest method shouldRunAndMeasureSuccessfulCallable.
@Test
public void shouldRunAndMeasureSuccessfulCallable() throws Exception {
assertThat(collector.measure("event", () -> {
fakeClock.delay(10);
return "return value";
})).isEqualTo("return value");
Collection<Metric> metrics = collector.getMetrics();
assertThat(metrics).containsExactly(new Metric("event", 1, 10, true));
}
use of org.robolectric.pluginapi.perf.Metric in project robolectric by robolectric.
the class SimplePerfStatsReporter method finalReport.
@SuppressWarnings("AndroidJdkLibsChecker)")
private synchronized void finalReport() {
Map<MetricKey, MetricValue> mergedMetrics = new TreeMap<>();
for (Data perfStatsData : perfStatsData) {
AndroidMetadata metadata = perfStatsData.metadata.get(AndroidMetadata.class);
Map<String, String> deviceBootProperties = metadata.getDeviceBootProperties();
int sdkInt = Integer.parseInt(deviceBootProperties.get("ro.build.version.sdk"));
String resourcesMode = metadata.getResourcesMode();
for (Metric metric : perfStatsData.metrics) {
MetricKey key = new MetricKey(metric.getName(), metric.isSuccess(), sdkInt, resourcesMode);
MetricValue mergedMetric = mergedMetrics.get(key);
if (mergedMetric == null) {
mergedMetric = new MetricValue();
mergedMetrics.put(key, mergedMetric);
}
mergedMetric.report(metric);
}
}
System.out.println("Name\tSDK\tResources\tSuccess\tCount\tMin ms\tMax ms\tAvg ms\tTotal ms");
for (Entry<MetricKey, MetricValue> entry : mergedMetrics.entrySet()) {
MetricKey key = entry.getKey();
MetricValue value = entry.getValue();
System.out.println(MessageFormat.format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}", key.name, key.sdkLevel, key.resourcesMode, key.success, value.count, (int) (value.minNs / 1000000), (int) (value.maxNs / 1000000), (int) (value.elapsedNs / 1000000 / value.count), (int) (value.elapsedNs / 1000000)));
}
}
use of org.robolectric.pluginapi.perf.Metric in project robolectric by robolectric.
the class PerfStatsCollector method incrementCount.
public void incrementCount(String eventName) {
synchronized (PerfStatsCollector.this) {
MetricKey key = new MetricKey(eventName, true);
Metric metric = metricMap.get(key);
if (metric == null) {
metricMap.put(key, metric = new Metric(key.name, key.success));
}
metric.incrementCount();
}
}
Aggregations