Merge "Statsd TestDrive tool: Write output to stdout. Also: Option for less verbose output." into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0f309dc04a
@@ -25,6 +25,7 @@ import com.android.internal.os.StatsdConfigProto.SimpleAtomMatcher;
|
|||||||
import com.android.internal.os.StatsdConfigProto.StatsdConfig;
|
import com.android.internal.os.StatsdConfigProto.StatsdConfig;
|
||||||
import com.android.internal.os.StatsdConfigProto.TimeUnit;
|
import com.android.internal.os.StatsdConfigProto.TimeUnit;
|
||||||
import com.android.os.AtomsProto.Atom;
|
import com.android.os.AtomsProto.Atom;
|
||||||
|
import com.android.os.StatsLog;
|
||||||
import com.android.os.StatsLog.ConfigMetricsReport;
|
import com.android.os.StatsLog.ConfigMetricsReport;
|
||||||
import com.android.os.StatsLog.ConfigMetricsReportList;
|
import com.android.os.StatsLog.ConfigMetricsReportList;
|
||||||
import com.android.os.StatsLog.StatsLogReport;
|
import com.android.os.StatsLog.StatsLogReport;
|
||||||
@@ -78,11 +79,12 @@ public class TestDrive {
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
String mDeviceSerial = null;
|
String mDeviceSerial = null;
|
||||||
|
@VisibleForTesting
|
||||||
|
Dumper mDumper = new BasicDumper();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
final Configuration configuration = new Configuration();
|
final Configuration configuration = new Configuration();
|
||||||
|
final TestDrive testDrive = new TestDrive();
|
||||||
TestDrive testDrive = new TestDrive();
|
|
||||||
Utils.setUpLogger(LOGGER, false);
|
Utils.setUpLogger(LOGGER, false);
|
||||||
|
|
||||||
if (!testDrive.processArgs(configuration, args,
|
if (!testDrive.processArgs(configuration, args,
|
||||||
@@ -94,7 +96,7 @@ public class TestDrive {
|
|||||||
configuration.createConfig(), configuration.hasPulledAtoms(),
|
configuration.createConfig(), configuration.hasPulledAtoms(),
|
||||||
configuration.hasPushedAtoms());
|
configuration.hasPushedAtoms());
|
||||||
if (reports != null) {
|
if (reports != null) {
|
||||||
configuration.dumpMetrics(reports);
|
configuration.dumpMetrics(reports, testDrive.mDumper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +118,9 @@ public class TestDrive {
|
|||||||
if (remaining_args >= 2 && arg.equals("-one")) {
|
if (remaining_args >= 2 && arg.equals("-one")) {
|
||||||
LOGGER.info("Creating one event metric to catch all pushed atoms.");
|
LOGGER.info("Creating one event metric to catch all pushed atoms.");
|
||||||
configuration.mOnePushedAtomEvent = true;
|
configuration.mOnePushedAtomEvent = true;
|
||||||
|
} else if (remaining_args >= 2 && arg.equals("-terse")) {
|
||||||
|
LOGGER.info("Terse output format.");
|
||||||
|
mDumper = new TerseDumper();
|
||||||
} else if (remaining_args >= 3 && arg.equals("-p")) {
|
} else if (remaining_args >= 3 && arg.equals("-p")) {
|
||||||
configuration.mAdditionalAllowedPackage = args[++first_arg];
|
configuration.mAdditionalAllowedPackage = args[++first_arg];
|
||||||
} else if (remaining_args >= 3 && arg.equals("-s")) {
|
} else if (remaining_args >= 3 && arg.equals("-s")) {
|
||||||
@@ -198,12 +203,13 @@ public class TestDrive {
|
|||||||
String mAdditionalAllowedPackage = null;
|
String mAdditionalAllowedPackage = null;
|
||||||
private final Set<Long> mTrackedMetrics = new HashSet<>();
|
private final Set<Long> mTrackedMetrics = new HashSet<>();
|
||||||
|
|
||||||
private void dumpMetrics(ConfigMetricsReportList reportList) {
|
private void dumpMetrics(ConfigMetricsReportList reportList, Dumper dumper) {
|
||||||
// We may get multiple reports. Take the last one.
|
// We may get multiple reports. Take the last one.
|
||||||
ConfigMetricsReport report = reportList.getReports(reportList.getReportsCount() - 1);
|
ConfigMetricsReport report = reportList.getReports(reportList.getReportsCount() - 1);
|
||||||
for (StatsLogReport statsLog : report.getMetricsList()) {
|
for (StatsLogReport statsLog : report.getMetricsList()) {
|
||||||
if (isTrackedMetric(statsLog.getMetricId())) {
|
if (isTrackedMetric(statsLog.getMetricId())) {
|
||||||
LOGGER.info(statsLog.toString());
|
LOGGER.info(statsLog.toString());
|
||||||
|
dumper.dump(statsLog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,6 +347,51 @@ public class TestDrive {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Dumper {
|
||||||
|
void dump(StatsLogReport report);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class BasicDumper implements Dumper {
|
||||||
|
@Override
|
||||||
|
public void dump(StatsLogReport report) {
|
||||||
|
System.out.println(report.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class TerseDumper extends BasicDumper {
|
||||||
|
@Override
|
||||||
|
public void dump(StatsLogReport report) {
|
||||||
|
if (report.hasGaugeMetrics()) {
|
||||||
|
dumpGaugeMetrics(report);
|
||||||
|
}
|
||||||
|
if (report.hasEventMetrics()) {
|
||||||
|
dumpEventMetrics(report);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void dumpEventMetrics(StatsLogReport report) {
|
||||||
|
final List<StatsLog.EventMetricData> data = report.getEventMetrics().getDataList();
|
||||||
|
if (data.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long firstTimestampNanos = data.get(0).getElapsedTimestampNanos();
|
||||||
|
for (StatsLog.EventMetricData event : data) {
|
||||||
|
final double deltaSec = (event.getElapsedTimestampNanos() - firstTimestampNanos)
|
||||||
|
/ 1e9;
|
||||||
|
System.out.println(
|
||||||
|
String.format("+%.3fs: %s", deltaSec, event.getAtom().toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void dumpGaugeMetrics(StatsLogReport report) {
|
||||||
|
final List<StatsLog.GaugeMetricData> data = report.getGaugeMetrics().getDataList();
|
||||||
|
if (data.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (StatsLog.GaugeMetricData gauge : data) {
|
||||||
|
System.out.println(gauge.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String pushConfig(StatsdConfig config, String deviceSerial)
|
private static String pushConfig(StatsdConfig config, String deviceSerial)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
File configFile = File.createTempFile("statsdconfig", ".config");
|
File configFile = File.createTempFile("statsdconfig", ".config");
|
||||||
|
|||||||
@@ -41,24 +41,21 @@ public class TestDriveTest {
|
|||||||
static class Expect {
|
static class Expect {
|
||||||
public boolean success;
|
public boolean success;
|
||||||
public Integer[] atoms;
|
public Integer[] atoms;
|
||||||
public boolean onePushedAtomEvent;
|
public boolean onePushedAtomEvent = false;
|
||||||
public String extraPackage;
|
public String extraPackage = null;
|
||||||
public String target;
|
public String target;
|
||||||
|
public boolean terse = false;
|
||||||
|
|
||||||
static Expect success(Integer... atoms) {
|
static Expect success(Integer... atoms) {
|
||||||
return new Expect(true, atoms, false, null,
|
return new Expect(true, atoms,
|
||||||
TARGET);
|
TARGET);
|
||||||
}
|
}
|
||||||
Expect(boolean success, Integer[] atoms, boolean onePushedAtomEvent, String extraPackage,
|
Expect(boolean success, Integer[] atoms, String target) {
|
||||||
String target) {
|
|
||||||
this.success = success;
|
this.success = success;
|
||||||
this.atoms = atoms;
|
this.atoms = atoms;
|
||||||
this.onePushedAtomEvent = onePushedAtomEvent;
|
|
||||||
this.extraPackage = extraPackage;
|
|
||||||
this.target = target;
|
this.target = target;
|
||||||
}
|
}
|
||||||
static final Expect FAILURE = new Expect(false, null,
|
static final Expect FAILURE = new Expect(false, null, null);
|
||||||
false, null, null);
|
|
||||||
Expect onePushedAtomEvent() {
|
Expect onePushedAtomEvent() {
|
||||||
this.onePushedAtomEvent = true;
|
this.onePushedAtomEvent = true;
|
||||||
return this;
|
return this;
|
||||||
@@ -67,6 +64,10 @@ public class TestDriveTest {
|
|||||||
this.extraPackage = TestDriveTest.PACKAGE;
|
this.extraPackage = TestDriveTest.PACKAGE;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
Expect terse() {
|
||||||
|
this.terse = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameterized.Parameter(0)
|
@Parameterized.Parameter(0)
|
||||||
@@ -118,6 +119,10 @@ public class TestDriveTest {
|
|||||||
Expect.FAILURE}, // Two connected devices, no indication of which to use
|
Expect.FAILURE}, // Two connected devices, no indication of which to use
|
||||||
new Object[]{new String[]{"-one", "244", "245"}, TARGET_ONLY, null,
|
new Object[]{new String[]{"-one", "244", "245"}, TARGET_ONLY, null,
|
||||||
Expect.success(244, 245).onePushedAtomEvent()},
|
Expect.success(244, 245).onePushedAtomEvent()},
|
||||||
|
new Object[]{new String[]{"-terse", "-one", "244", "245"}, TARGET_ONLY, null,
|
||||||
|
Expect.success(244, 245).onePushedAtomEvent().terse()},
|
||||||
|
new Object[]{new String[]{"-one", "-terse", "244", "245"}, TARGET_ONLY, null,
|
||||||
|
Expect.success(244, 245).onePushedAtomEvent().terse()},
|
||||||
new Object[]{new String[]{"-p", PACKAGE, "244", "245"}, TARGET_ONLY, null,
|
new Object[]{new String[]{"-p", PACKAGE, "244", "245"}, TARGET_ONLY, null,
|
||||||
Expect.success(244, 245).extraPackage()},
|
Expect.success(244, 245).extraPackage()},
|
||||||
new Object[]{new String[]{"-p", PACKAGE, "-one", "244", "245"}, TARGET_ONLY, null,
|
new Object[]{new String[]{"-p", PACKAGE, "-one", "244", "245"}, TARGET_ONLY, null,
|
||||||
@@ -132,7 +137,23 @@ public class TestDriveTest {
|
|||||||
Expect.success(244, 245).extraPackage().onePushedAtomEvent()},
|
Expect.success(244, 245).extraPackage().onePushedAtomEvent()},
|
||||||
new Object[]{new String[]{"-one", "-p", PACKAGE, "-s", TARGET, "244", "245"},
|
new Object[]{new String[]{"-one", "-p", PACKAGE, "-s", TARGET, "244", "245"},
|
||||||
TARGET_AND_OTHER, null,
|
TARGET_AND_OTHER, null,
|
||||||
Expect.success(244, 245).extraPackage().onePushedAtomEvent()}
|
Expect.success(244, 245).extraPackage().onePushedAtomEvent()},
|
||||||
|
new Object[]{new String[]{"-terse", "-one", "-p", PACKAGE, "-s", TARGET,
|
||||||
|
"244", "245"},
|
||||||
|
TARGET_AND_OTHER, null,
|
||||||
|
Expect.success(244, 245).extraPackage().onePushedAtomEvent().terse()},
|
||||||
|
new Object[]{new String[]{"-one", "-terse", "-p", PACKAGE, "-s", TARGET,
|
||||||
|
"244", "245"},
|
||||||
|
TARGET_AND_OTHER, null,
|
||||||
|
Expect.success(244, 245).extraPackage().onePushedAtomEvent().terse()},
|
||||||
|
new Object[]{new String[]{"-one", "-p", PACKAGE, "-terse", "-s", TARGET,
|
||||||
|
"244", "245"},
|
||||||
|
TARGET_AND_OTHER, null,
|
||||||
|
Expect.success(244, 245).extraPackage().onePushedAtomEvent().terse()},
|
||||||
|
new Object[]{new String[]{"-one", "-p", PACKAGE, "-s", TARGET, "-terse",
|
||||||
|
"244", "245"},
|
||||||
|
TARGET_AND_OTHER, null,
|
||||||
|
Expect.success(244, 245).extraPackage().onePushedAtomEvent().terse()}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +183,11 @@ public class TestDriveTest {
|
|||||||
assertArrayEquals(mExpect.atoms, collectAtoms(mConfiguration));
|
assertArrayEquals(mExpect.atoms, collectAtoms(mConfiguration));
|
||||||
assertEquals(mExpect.onePushedAtomEvent, mConfiguration.mOnePushedAtomEvent);
|
assertEquals(mExpect.onePushedAtomEvent, mConfiguration.mOnePushedAtomEvent);
|
||||||
assertEquals(mExpect.target, mTestDrive.mDeviceSerial);
|
assertEquals(mExpect.target, mTestDrive.mDeviceSerial);
|
||||||
|
if (mExpect.terse) {
|
||||||
|
assertEquals(TestDrive.TerseDumper.class, mTestDrive.mDumper.getClass());
|
||||||
|
} else {
|
||||||
|
assertEquals(TestDrive.BasicDumper.class, mTestDrive.mDumper.getClass());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
assertFalse(result);
|
assertFalse(result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user