Merge "Update the cc_benchmark to use the new socket schema" into rvc-dev am: be88f7df21 am: 819aa0f9f0

Change-Id: I1bc44318bbf2ad11a29d1964b91ab1de01650667
This commit is contained in:
Christine Tsai
2020-03-25 16:49:28 +00:00
committed by Automerger Merge Worker
7 changed files with 327 additions and 329 deletions

View File

@@ -378,55 +378,55 @@ cc_test {
// statsd micro benchmark // statsd micro benchmark
//############################# //#############################
//cc_benchmark { cc_benchmark {
// name: "statsd_benchmark", name: "statsd_benchmark",
// defaults: ["statsd_defaults"], defaults: ["statsd_defaults"],
//
// srcs: [ srcs: [
// // atom_field_options.proto needs field_options.proto, but that is // atom_field_options.proto needs field_options.proto, but that is
// // not included in libprotobuf-cpp-lite, so compile it here. // not included in libprotobuf-cpp-lite, so compile it here.
// ":libprotobuf-internal-protos", ":libprotobuf-internal-protos",
//
// "benchmark/duration_metric_benchmark.cpp", "benchmark/duration_metric_benchmark.cpp",
// "benchmark/filter_value_benchmark.cpp", "benchmark/filter_value_benchmark.cpp",
// "benchmark/get_dimensions_for_condition_benchmark.cpp", "benchmark/get_dimensions_for_condition_benchmark.cpp",
// "benchmark/hello_world_benchmark.cpp", "benchmark/hello_world_benchmark.cpp",
// "benchmark/log_event_benchmark.cpp", "benchmark/log_event_benchmark.cpp",
// "benchmark/main.cpp", "benchmark/main.cpp",
// "benchmark/metric_util.cpp", "benchmark/metric_util.cpp",
// "benchmark/stats_write_benchmark.cpp", "benchmark/stats_write_benchmark.cpp",
// "src/atom_field_options.proto", "src/atom_field_options.proto",
// "src/atoms.proto", "src/atoms.proto",
// "src/stats_log.proto", "src/stats_log.proto",
// ], ],
//
// proto: { proto: {
// type: "lite", type: "lite",
// include_dirs: ["external/protobuf/src"], include_dirs: ["external/protobuf/src"],
// }, },
//
// cflags: [ cflags: [
// "-Wall", "-Wall",
// "-Werror", "-Werror",
// "-Wno-unused-parameter", "-Wno-unused-parameter",
// "-Wno-unused-variable", "-Wno-unused-variable",
// "-Wno-unused-function", "-Wno-unused-function",
//
// // Bug: http://b/29823425 Disable -Wvarargs for Clang update to r271374 // Bug: http://b/29823425 Disable -Wvarargs for Clang update to r271374
// "-Wno-varargs", "-Wno-varargs",
// ], ],
//
// static_libs: [ static_libs: [
// "libplatformprotos", "libplatformprotos",
// ], "libstatssocket_private",
// ],
// shared_libs: [
// "libgtest_prod", shared_libs: [
// "libprotobuf-cpp-lite", "libgtest_prod",
// "libstatslog", "libprotobuf-cpp-lite",
// "libstatssocket", "libstatslog",
// ], ],
//} }
// ==== java proto device library (for test only) ============================== // ==== java proto device library (for test only) ==============================
java_library { java_library {

View File

@@ -137,77 +137,74 @@ static void BM_DurationMetricNoLink(benchmark::State& state) {
int64_t bucketSizeNs = int64_t bucketSizeNs =
TimeUnitToBucketSizeInMillis(config.duration_metric(0).bucket()) * 1000000LL; TimeUnitToBucketSizeInMillis(config.duration_metric(0).bucket()) * 1000000LL;
std::vector<AttributionNodeInternal> attributions1 = {
CreateAttribution(111, "App1"), CreateAttribution(222, "GMSCoreModule1"),
CreateAttribution(222, "GMSCoreModule2")};
std::vector<AttributionNodeInternal> attributions2 = {
CreateAttribution(333, "App2"), CreateAttribution(222, "GMSCoreModule1"),
CreateAttribution(555, "GMSCoreModule2")};
std::vector<std::unique_ptr<LogEvent>> events; std::vector<std::unique_ptr<LogEvent>> events;
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_OFF, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + 11,
bucketStartTimeNs + 11)); android::view::DISPLAY_STATE_OFF));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_ON, events.push_back(
bucketStartTimeNs + 40)); CreateScreenStateChangedEvent(bucketStartTimeNs + 40, android::view::DISPLAY_STATE_ON));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_OFF, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + 102,
bucketStartTimeNs + 102)); android::view::DISPLAY_STATE_OFF));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_ON, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + 450,
bucketStartTimeNs + 450)); android::view::DISPLAY_STATE_ON));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_OFF, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + 650,
bucketStartTimeNs + 650)); android::view::DISPLAY_STATE_OFF));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_ON, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + bucketSizeNs + 100,
bucketStartTimeNs + bucketSizeNs + 100)); android::view::DISPLAY_STATE_ON));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_OFF, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + bucketSizeNs + 640,
bucketStartTimeNs + bucketSizeNs + 640)); android::view::DISPLAY_STATE_OFF));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_ON, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + bucketSizeNs + 650,
bucketStartTimeNs + bucketSizeNs + 650)); android::view::DISPLAY_STATE_ON));
events.push_back(CreateStartScheduledJobEvent( vector<int> attributionUids1 = {9999};
{CreateAttribution(9999, "")}, "job0", bucketStartTimeNs + 2)); vector<string> attributionTags1 = {""};
events.push_back(CreateFinishScheduledJobEvent( events.push_back(CreateStartScheduledJobEvent(bucketStartTimeNs + 2, attributionUids1,
{CreateAttribution(9999, "")}, "job0",bucketStartTimeNs + 101)); attributionTags1, "job0"));
events.push_back(CreateFinishScheduledJobEvent(bucketStartTimeNs + 101, attributionUids1,
attributionTags1, "job0"));
events.push_back(CreateStartScheduledJobEvent( events.push_back(CreateStartScheduledJobEvent(bucketStartTimeNs + 201, attributionUids1,
{CreateAttribution(9999, "")}, "job2", bucketStartTimeNs + 201)); attributionTags1, "job2"));
events.push_back(CreateFinishScheduledJobEvent( events.push_back(CreateFinishScheduledJobEvent(bucketStartTimeNs + 500, attributionUids1,
{CreateAttribution(9999, "")}, "job2",bucketStartTimeNs + 500)); attributionTags1, "job2"));
events.push_back(CreateStartScheduledJobEvent( vector<int> attributionUids2 = {8888};
{CreateAttribution(8888, "")}, "job2", bucketStartTimeNs + 600)); events.push_back(CreateStartScheduledJobEvent(bucketStartTimeNs + 600, attributionUids2,
events.push_back(CreateFinishScheduledJobEvent( attributionTags1, "job2"));
{CreateAttribution(8888, "")}, "job2",bucketStartTimeNs + bucketSizeNs + 850)); events.push_back(CreateFinishScheduledJobEvent(bucketStartTimeNs + bucketSizeNs + 850,
attributionUids2, attributionTags1, "job2"));
events.push_back(CreateStartScheduledJobEvent( events.push_back(CreateStartScheduledJobEvent(bucketStartTimeNs + bucketSizeNs + 600,
{CreateAttribution(8888, "")}, "job1", bucketStartTimeNs + bucketSizeNs + 600)); attributionUids2, attributionTags1, "job1"));
events.push_back(CreateFinishScheduledJobEvent( events.push_back(CreateFinishScheduledJobEvent(bucketStartTimeNs + bucketSizeNs + 900,
{CreateAttribution(8888, "")}, "job1", bucketStartTimeNs + bucketSizeNs + 900)); attributionUids2, attributionTags1, "job1"));
events.push_back(CreateSyncStartEvent(attributions1, "ReadEmail", vector<int> attributionUids3 = {111, 222, 222};
bucketStartTimeNs + 10)); vector<string> attributionTags3 = {"App1", "GMSCoreModule1", "GMSCoreModule2"};
events.push_back(CreateSyncEndEvent(attributions1, "ReadEmail", events.push_back(CreateSyncStartEvent(bucketStartTimeNs + 10, attributionUids3,
bucketStartTimeNs + 50)); attributionTags3, "ReadEmail"));
events.push_back(CreateSyncEndEvent(bucketStartTimeNs + 50, attributionUids3, attributionTags3,
"ReadEmail"));
events.push_back(CreateSyncStartEvent(attributions1, "ReadEmail", events.push_back(CreateSyncStartEvent(bucketStartTimeNs + 200, attributionUids3,
bucketStartTimeNs + 200)); attributionTags3, "ReadEmail"));
events.push_back(CreateSyncEndEvent(attributions1, "ReadEmail", events.push_back(CreateSyncEndEvent(bucketStartTimeNs + bucketSizeNs + 300, attributionUids3,
bucketStartTimeNs + bucketSizeNs + 300)); attributionTags3, "ReadEmail"));
events.push_back(CreateSyncStartEvent(attributions1, "ReadDoc", events.push_back(CreateSyncStartEvent(bucketStartTimeNs + 400, attributionUids3,
bucketStartTimeNs + 400)); attributionTags3, "ReadDoc"));
events.push_back(CreateSyncEndEvent(attributions1, "ReadDoc", events.push_back(CreateSyncEndEvent(bucketStartTimeNs + bucketSizeNs - 1, attributionUids3,
bucketStartTimeNs + bucketSizeNs - 1)); attributionTags3, "ReadDoc"));
events.push_back(CreateSyncStartEvent(attributions2, "ReadEmail",
bucketStartTimeNs + 401));
events.push_back(CreateSyncEndEvent(attributions2, "ReadEmail",
bucketStartTimeNs + bucketSizeNs + 700));
vector<int> attributionUids4 = {333, 222, 555};
vector<string> attributionTags4 = {"App2", "GMSCoreModule1", "GMSCoreModule2"};
events.push_back(CreateSyncStartEvent(bucketStartTimeNs + 401, attributionUids4,
attributionTags4, "ReadEmail"));
events.push_back(CreateSyncEndEvent(bucketStartTimeNs + bucketSizeNs + 700, attributionUids4,
attributionTags4, "ReadEmail"));
sortLogEventsByTimestamp(&events); sortLogEventsByTimestamp(&events);
while (state.KeepRunning()) { while (state.KeepRunning()) {
@@ -230,78 +227,75 @@ static void BM_DurationMetricLink(benchmark::State& state) {
int64_t bucketSizeNs = int64_t bucketSizeNs =
TimeUnitToBucketSizeInMillis(config.duration_metric(0).bucket()) * 1000000LL; TimeUnitToBucketSizeInMillis(config.duration_metric(0).bucket()) * 1000000LL;
std::vector<AttributionNodeInternal> attributions1 = {
CreateAttribution(111, "App1"), CreateAttribution(222, "GMSCoreModule1"),
CreateAttribution(222, "GMSCoreModule2")};
std::vector<AttributionNodeInternal> attributions2 = {
CreateAttribution(333, "App2"), CreateAttribution(222, "GMSCoreModule1"),
CreateAttribution(555, "GMSCoreModule2")};
std::vector<AttributionNodeInternal> attributions3 = {
CreateAttribution(444, "App3"), CreateAttribution(222, "GMSCoreModule1"),
CreateAttribution(555, "GMSCoreModule2")};
std::vector<std::unique_ptr<LogEvent>> events; std::vector<std::unique_ptr<LogEvent>> events;
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_OFF, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + 55,
bucketStartTimeNs + 55)); android::view::DISPLAY_STATE_OFF));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_ON, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + 120,
bucketStartTimeNs + 120)); android::view::DISPLAY_STATE_ON));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_OFF, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + 121,
bucketStartTimeNs + 121)); android::view::DISPLAY_STATE_OFF));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_ON, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + 450,
bucketStartTimeNs + 450)); android::view::DISPLAY_STATE_ON));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_OFF, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + 501,
bucketStartTimeNs + 501)); android::view::DISPLAY_STATE_OFF));
events.push_back(CreateScreenStateChangedEvent(android::view::DISPLAY_STATE_ON, events.push_back(CreateScreenStateChangedEvent(bucketStartTimeNs + bucketSizeNs + 100,
bucketStartTimeNs + bucketSizeNs + 100)); android::view::DISPLAY_STATE_ON));
events.push_back(CreateStartScheduledJobEvent( vector<int> attributionUids1 = {111};
{CreateAttribution(111, "App1")}, "job1", bucketStartTimeNs + 1)); vector<string> attributionTags1 = {"App1"};
events.push_back(CreateFinishScheduledJobEvent( events.push_back(CreateStartScheduledJobEvent(bucketStartTimeNs + 1, attributionUids1,
{CreateAttribution(111, "App1")}, "job1",bucketStartTimeNs + 101)); attributionTags1, "job1"));
events.push_back(CreateFinishScheduledJobEvent(bucketStartTimeNs + 101, attributionUids1,
attributionTags1, "job1"));
events.push_back(CreateStartScheduledJobEvent( vector<int> attributionUids2 = {333};
{CreateAttribution(333, "App2")}, "job2", bucketStartTimeNs + 201)); vector<string> attributionTags2 = {"App2"};
events.push_back(CreateFinishScheduledJobEvent( events.push_back(CreateStartScheduledJobEvent(bucketStartTimeNs + 201, attributionUids2,
{CreateAttribution(333, "App2")}, "job2",bucketStartTimeNs + 500)); attributionTags2, "job2"));
events.push_back(CreateStartScheduledJobEvent( events.push_back(CreateFinishScheduledJobEvent(bucketStartTimeNs + 500, attributionUids2,
{CreateAttribution(333, "App2")}, "job2", bucketStartTimeNs + 600)); attributionTags2, "job2"));
events.push_back(CreateFinishScheduledJobEvent( events.push_back(CreateStartScheduledJobEvent(bucketStartTimeNs + 600, attributionUids2,
{CreateAttribution(333, "App2")}, "job2", attributionTags2, "job2"));
bucketStartTimeNs + bucketSizeNs + 850)); events.push_back(CreateFinishScheduledJobEvent(bucketStartTimeNs + bucketSizeNs + 850,
attributionUids2, attributionTags2, "job2"));
events.push_back( vector<int> attributionUids3 = {444};
CreateStartScheduledJobEvent({CreateAttribution(444, "App3")}, "job3", vector<string> attributionTags3 = {"App3"};
bucketStartTimeNs + bucketSizeNs - 2)); events.push_back(CreateStartScheduledJobEvent(bucketStartTimeNs + bucketSizeNs - 2,
events.push_back( attributionUids3, attributionTags3, "job3"));
CreateFinishScheduledJobEvent({CreateAttribution(444, "App3")}, "job3", events.push_back(CreateFinishScheduledJobEvent(bucketStartTimeNs + bucketSizeNs + 900,
bucketStartTimeNs + bucketSizeNs + 900)); attributionUids3, attributionTags3, "job3"));
events.push_back(CreateSyncStartEvent(attributions1, "ReadEmail", vector<int> attributionUids4 = {111, 222, 222};
bucketStartTimeNs + 50)); vector<string> attributionTags4 = {"App1", "GMSCoreModule1", "GMSCoreModule2"};
events.push_back(CreateSyncEndEvent(attributions1, "ReadEmail", events.push_back(CreateSyncStartEvent(bucketStartTimeNs + 50, attributionUids4,
bucketStartTimeNs + 110)); attributionTags4, "ReadEmail"));
events.push_back(CreateSyncEndEvent(bucketStartTimeNs + 110, attributionUids4, attributionTags4,
"ReadEmail"));
events.push_back(CreateSyncStartEvent(attributions2, "ReadEmail", vector<int> attributionUids5 = {333, 222, 555};
bucketStartTimeNs + 300)); vector<string> attributionTags5 = {"App2", "GMSCoreModule1", "GMSCoreModule2"};
events.push_back(CreateSyncEndEvent(attributions2, "ReadEmail", events.push_back(CreateSyncStartEvent(bucketStartTimeNs + 300, attributionUids5,
bucketStartTimeNs + bucketSizeNs + 700)); attributionTags5, "ReadEmail"));
events.push_back(CreateSyncStartEvent(attributions2, "ReadDoc", events.push_back(CreateSyncEndEvent(bucketStartTimeNs + bucketSizeNs + 700, attributionUids5,
bucketStartTimeNs + 400)); attributionTags5, "ReadEmail"));
events.push_back(CreateSyncEndEvent(attributions2, "ReadDoc", events.push_back(CreateSyncStartEvent(bucketStartTimeNs + 400, attributionUids5,
bucketStartTimeNs + bucketSizeNs - 1)); attributionTags5, "ReadDoc"));
events.push_back(CreateSyncEndEvent(bucketStartTimeNs + bucketSizeNs - 1, attributionUids5,
attributionTags5, "ReadDoc"));
events.push_back(CreateSyncStartEvent(attributions3, "ReadDoc", vector<int> attributionUids6 = {444, 222, 555};
bucketStartTimeNs + 550)); vector<string> attributionTags6 = {"App3", "GMSCoreModule1", "GMSCoreModule2"};
events.push_back(CreateSyncEndEvent(attributions3, "ReadDoc", events.push_back(CreateSyncStartEvent(bucketStartTimeNs + 550, attributionUids6,
bucketStartTimeNs + 800)); attributionTags6, "ReadDoc"));
events.push_back(CreateSyncStartEvent(attributions3, "ReadDoc", events.push_back(CreateSyncEndEvent(bucketStartTimeNs + 800, attributionUids6, attributionTags6,
bucketStartTimeNs + bucketSizeNs - 1)); "ReadDoc"));
events.push_back(CreateSyncEndEvent(attributions3, "ReadDoc", events.push_back(CreateSyncStartEvent(bucketStartTimeNs + bucketSizeNs - 1, attributionUids6,
bucketStartTimeNs + bucketSizeNs + 700)); attributionTags6, "ReadDoc"));
events.push_back(CreateSyncEndEvent(bucketStartTimeNs + bucketSizeNs + 700, attributionUids6,
attributionTags6, "ReadDoc"));
sortLogEventsByTimestamp(&events); sortLogEventsByTimestamp(&events);
while (state.KeepRunning()) { while (state.KeepRunning()) {

View File

@@ -19,6 +19,7 @@
#include "HashableDimensionKey.h" #include "HashableDimensionKey.h"
#include "logd/LogEvent.h" #include "logd/LogEvent.h"
#include "stats_log_util.h" #include "stats_log_util.h"
#include "stats_event.h"
namespace android { namespace android {
namespace os { namespace os {
@@ -26,17 +27,31 @@ namespace statsd {
using std::vector; using std::vector;
static void createLogEventAndMatcher(LogEvent* event, FieldMatcher *field_matcher) { static void createLogEventAndMatcher(LogEvent* event, FieldMatcher* field_matcher) {
AttributionNodeInternal node; AStatsEvent* statsEvent = AStatsEvent_obtain();
node.set_uid(100); AStatsEvent_setAtomId(statsEvent, 1);
node.set_tag("LOCATION"); AStatsEvent_overwriteTimestamp(statsEvent, 100000);
std::vector<AttributionNodeInternal> nodes = {node, node}; std::vector<int> attributionUids = {100, 100};
event->write(nodes); std::vector<string> attributionTags = {"LOCATION", "LOCATION"};
event->write(3.2f);
event->write("LOCATION"); vector<const char*> cTags(attributionTags.size());
event->write((int64_t)990); for (int i = 0; i < cTags.size(); i++) {
event->init(); cTags[i] = attributionTags[i].c_str();
}
AStatsEvent_writeAttributionChain(statsEvent,
reinterpret_cast<const uint32_t*>(attributionUids.data()),
cTags.data(), attributionUids.size());
AStatsEvent_writeFloat(statsEvent, 3.2f);
AStatsEvent_writeString(statsEvent, "LOCATION");
AStatsEvent_writeInt64(statsEvent, 990);
AStatsEvent_build(statsEvent);
size_t size;
uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size);
event->parseBuffer(buf, size);
AStatsEvent_release(statsEvent);
field_matcher->set_field(1); field_matcher->set_field(1);
auto child = field_matcher->add_child(); auto child = field_matcher->add_child();
@@ -46,7 +61,7 @@ static void createLogEventAndMatcher(LogEvent* event, FieldMatcher *field_matche
} }
static void BM_FilterValue(benchmark::State& state) { static void BM_FilterValue(benchmark::State& state) {
LogEvent event(1, 100000); LogEvent event(/*uid=*/0, /*pid=*/0);
FieldMatcher field_matcher; FieldMatcher field_matcher;
createLogEventAndMatcher(&event, &field_matcher); createLogEventAndMatcher(&event, &field_matcher);

View File

@@ -19,6 +19,7 @@
#include "HashableDimensionKey.h" #include "HashableDimensionKey.h"
#include "logd/LogEvent.h" #include "logd/LogEvent.h"
#include "stats_log_util.h" #include "stats_log_util.h"
#include "stats_event.h"
namespace android { namespace android {
namespace os { namespace os {
@@ -27,16 +28,30 @@ namespace statsd {
using std::vector; using std::vector;
static void createLogEventAndLink(LogEvent* event, Metric2Condition *link) { static void createLogEventAndLink(LogEvent* event, Metric2Condition *link) {
AttributionNodeInternal node; AStatsEvent* statsEvent = AStatsEvent_obtain();
node.set_uid(100); AStatsEvent_setAtomId(statsEvent, 1);
node.set_tag("LOCATION"); AStatsEvent_overwriteTimestamp(statsEvent, 100000);
std::vector<AttributionNodeInternal> nodes = {node, node}; std::vector<int> attributionUids = {100, 100};
event->write(nodes); std::vector<string> attributionTags = {"LOCATION", "LOCATION"};
event->write(3.2f);
event->write("LOCATION"); vector<const char*> cTags(attributionTags.size());
event->write((int64_t)990); for (int i = 0; i < cTags.size(); i++) {
event->init(); cTags[i] = attributionTags[i].c_str();
}
AStatsEvent_writeAttributionChain(statsEvent,
reinterpret_cast<const uint32_t*>(attributionUids.data()),
cTags.data(), attributionUids.size());
AStatsEvent_writeFloat(statsEvent, 3.2f);
AStatsEvent_writeString(statsEvent, "LOCATION");
AStatsEvent_writeInt64(statsEvent, 990);
AStatsEvent_build(statsEvent);
size_t size;
uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size);
event->parseBuffer(buf, size);
AStatsEvent_release(statsEvent);
link->conditionId = 1; link->conditionId = 1;
@@ -54,7 +69,7 @@ static void createLogEventAndLink(LogEvent* event, Metric2Condition *link) {
static void BM_GetDimensionInCondition(benchmark::State& state) { static void BM_GetDimensionInCondition(benchmark::State& state) {
Metric2Condition link; Metric2Condition link;
LogEvent event(1, 100000); LogEvent event(/*uid=*/0, /*pid=*/0);
createLogEventAndLink(&event, &link); createLogEventAndLink(&event, &link);
while (state.KeepRunning()) { while (state.KeepRunning()) {

View File

@@ -39,7 +39,8 @@ static void BM_LogEventCreation(benchmark::State& state) {
uint8_t msg[LOGGER_ENTRY_MAX_PAYLOAD]; uint8_t msg[LOGGER_ENTRY_MAX_PAYLOAD];
size_t size = createAndParseStatsEvent(msg); size_t size = createAndParseStatsEvent(msg);
while (state.KeepRunning()) { while (state.KeepRunning()) {
benchmark::DoNotOptimize(LogEvent(msg, size, /*uid=*/ 1000, /*pid=*/ 1001)); LogEvent event(/*uid=*/ 1000, /*pid=*/ 1001);
benchmark::DoNotOptimize(event.parseBuffer(msg, size));
} }
} }
BENCHMARK(BM_LogEventCreation); BENCHMARK(BM_LogEventCreation);

View File

@@ -14,6 +14,8 @@
#include "metric_util.h" #include "metric_util.h"
#include "stats_event.h"
namespace android { namespace android {
namespace os { namespace os {
namespace statsd { namespace statsd {
@@ -246,117 +248,112 @@ FieldMatcher CreateDimensions(const int atomId, const std::vector<int>& fields)
} }
std::unique_ptr<LogEvent> CreateScreenStateChangedEvent( std::unique_ptr<LogEvent> CreateScreenStateChangedEvent(
const android::view::DisplayStateEnum state, uint64_t timestampNs) { uint64_t timestampNs, const android::view::DisplayStateEnum state) {
auto event = std::make_unique<LogEvent>(android::util::SCREEN_STATE_CHANGED, timestampNs); AStatsEvent* statsEvent = AStatsEvent_obtain();
event->write(state); AStatsEvent_setAtomId(statsEvent, util::SCREEN_STATE_CHANGED);
event->init(); AStatsEvent_overwriteTimestamp(statsEvent, timestampNs);
return event;
}
std::unique_ptr<LogEvent> CreateScreenBrightnessChangedEvent( AStatsEvent_writeInt32(statsEvent, state);
int level, uint64_t timestampNs) { AStatsEvent_build(statsEvent);
auto event = std::make_unique<LogEvent>(android::util::SCREEN_BRIGHTNESS_CHANGED, timestampNs);
(event->write(level));
event->init();
return event;
size_t size;
uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size);
std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0);
logEvent->parseBuffer(buf, size);
AStatsEvent_release(statsEvent);
return logEvent;
} }
std::unique_ptr<LogEvent> CreateScheduledJobStateChangedEvent( std::unique_ptr<LogEvent> CreateScheduledJobStateChangedEvent(
const std::vector<AttributionNodeInternal>& attributions, const string& jobName, const vector<int>& attributionUids, const vector<string>& attributionTags,
const ScheduledJobStateChanged::State state, uint64_t timestampNs) { const string& jobName, const ScheduledJobStateChanged::State state, uint64_t timestampNs) {
auto event = std::make_unique<LogEvent>(android::util::SCHEDULED_JOB_STATE_CHANGED, timestampNs); AStatsEvent* statsEvent = AStatsEvent_obtain();
event->write(attributions); AStatsEvent_setAtomId(statsEvent, util::SCHEDULED_JOB_STATE_CHANGED);
event->write(jobName); AStatsEvent_overwriteTimestamp(statsEvent, timestampNs);
event->write(state);
event->init(); vector<const char*> cTags(attributionTags.size());
return event; for (int i = 0; i < cTags.size(); i++) {
cTags[i] = attributionTags[i].c_str();
}
AStatsEvent_writeAttributionChain(statsEvent,
reinterpret_cast<const uint32_t*>(attributionUids.data()),
cTags.data(), attributionUids.size());
AStatsEvent_writeString(statsEvent, jobName.c_str());
AStatsEvent_writeInt32(statsEvent, state);
AStatsEvent_build(statsEvent);
size_t size;
uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size);
std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0);
logEvent->parseBuffer(buf, size);
AStatsEvent_release(statsEvent);
return logEvent;
} }
std::unique_ptr<LogEvent> CreateStartScheduledJobEvent( std::unique_ptr<LogEvent> CreateStartScheduledJobEvent(uint64_t timestampNs,
const std::vector<AttributionNodeInternal>& attributions, const vector<int>& attributionUids,
const string& name, uint64_t timestampNs) { const vector<string>& attributionTags,
return CreateScheduledJobStateChangedEvent( const string& jobName) {
attributions, name, ScheduledJobStateChanged::STARTED, timestampNs); return CreateScheduledJobStateChangedEvent(attributionUids, attributionTags, jobName,
ScheduledJobStateChanged::STARTED, timestampNs);
} }
// Create log event when scheduled job finishes. // Create log event when scheduled job finishes.
std::unique_ptr<LogEvent> CreateFinishScheduledJobEvent( std::unique_ptr<LogEvent> CreateFinishScheduledJobEvent(uint64_t timestampNs,
const std::vector<AttributionNodeInternal>& attributions, const vector<int>& attributionUids,
const string& name, uint64_t timestampNs) { const vector<string>& attributionTags,
return CreateScheduledJobStateChangedEvent( const string& jobName) {
attributions, name, ScheduledJobStateChanged::FINISHED, timestampNs); return CreateScheduledJobStateChangedEvent(attributionUids, attributionTags, jobName,
ScheduledJobStateChanged::FINISHED, timestampNs);
} }
std::unique_ptr<LogEvent> CreateWakelockStateChangedEvent( std::unique_ptr<LogEvent> CreateSyncStateChangedEvent(uint64_t timestampNs,
const std::vector<AttributionNodeInternal>& attributions, const string& wakelockName, const vector<int>& attributionUids,
const WakelockStateChanged::State state, uint64_t timestampNs) { const vector<string>& attributionTags,
auto event = std::make_unique<LogEvent>(android::util::WAKELOCK_STATE_CHANGED, timestampNs); const string& name,
event->write(attributions); const SyncStateChanged::State state) {
event->write(android::os::WakeLockLevelEnum::PARTIAL_WAKE_LOCK); AStatsEvent* statsEvent = AStatsEvent_obtain();
event->write(wakelockName); AStatsEvent_setAtomId(statsEvent, util::SYNC_STATE_CHANGED);
event->write(state); AStatsEvent_overwriteTimestamp(statsEvent, timestampNs);
event->init();
return event; vector<const char*> cTags(attributionTags.size());
for (int i = 0; i < cTags.size(); i++) {
cTags[i] = attributionTags[i].c_str();
}
AStatsEvent_writeAttributionChain(statsEvent,
reinterpret_cast<const uint32_t*>(attributionUids.data()),
cTags.data(), attributionUids.size());
AStatsEvent_writeString(statsEvent, name.c_str());
AStatsEvent_writeInt32(statsEvent, state);
AStatsEvent_build(statsEvent);
size_t size;
uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size);
std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0);
logEvent->parseBuffer(buf, size);
AStatsEvent_release(statsEvent);
return logEvent;
} }
std::unique_ptr<LogEvent> CreateAcquireWakelockEvent( std::unique_ptr<LogEvent> CreateSyncStartEvent(uint64_t timestampNs,
const std::vector<AttributionNodeInternal>& attributions, const string& wakelockName, const vector<int>& attributionUids,
uint64_t timestampNs) { const vector<string>& attributionTags,
return CreateWakelockStateChangedEvent( const string& name) {
attributions, wakelockName, WakelockStateChanged::ACQUIRE, timestampNs); return CreateSyncStateChangedEvent(timestampNs, attributionUids, attributionTags, name,
SyncStateChanged::ON);
} }
std::unique_ptr<LogEvent> CreateReleaseWakelockEvent( std::unique_ptr<LogEvent> CreateSyncEndEvent(uint64_t timestampNs,
const std::vector<AttributionNodeInternal>& attributions, const string& wakelockName, const vector<int>& attributionUids,
uint64_t timestampNs) { const vector<string>& attributionTags,
return CreateWakelockStateChangedEvent( const string& name) {
attributions, wakelockName, WakelockStateChanged::RELEASE, timestampNs); return CreateSyncStateChangedEvent(timestampNs, attributionUids, attributionTags, name,
} SyncStateChanged::OFF);
std::unique_ptr<LogEvent> CreateActivityForegroundStateChangedEvent(
const int uid, const ActivityForegroundStateChanged::State state, uint64_t timestampNs) {
auto event = std::make_unique<LogEvent>(
android::util::ACTIVITY_FOREGROUND_STATE_CHANGED, timestampNs);
event->write(uid);
event->write("pkg_name");
event->write("class_name");
event->write(state);
event->init();
return event;
}
std::unique_ptr<LogEvent> CreateMoveToBackgroundEvent(const int uid, uint64_t timestampNs) {
return CreateActivityForegroundStateChangedEvent(
uid, ActivityForegroundStateChanged::BACKGROUND, timestampNs);
}
std::unique_ptr<LogEvent> CreateMoveToForegroundEvent(const int uid, uint64_t timestampNs) {
return CreateActivityForegroundStateChangedEvent(
uid, ActivityForegroundStateChanged::FOREGROUND, timestampNs);
}
std::unique_ptr<LogEvent> CreateSyncStateChangedEvent(
const std::vector<AttributionNodeInternal>& attributions, const string& name,
const SyncStateChanged::State state, uint64_t timestampNs) {
auto event = std::make_unique<LogEvent>(android::util::SYNC_STATE_CHANGED, timestampNs);
event->write(attributions);
event->write(name);
event->write(state);
event->init();
return event;
}
std::unique_ptr<LogEvent> CreateSyncStartEvent(
const std::vector<AttributionNodeInternal>& attributions, const string& name,
uint64_t timestampNs) {
return CreateSyncStateChangedEvent(attributions, name, SyncStateChanged::ON, timestampNs);
}
std::unique_ptr<LogEvent> CreateSyncEndEvent(
const std::vector<AttributionNodeInternal>& attributions, const string& name,
uint64_t timestampNs) {
return CreateSyncStateChangedEvent(attributions, name, SyncStateChanged::OFF, timestampNs);
} }
sp<StatsLogProcessor> CreateStatsLogProcessor(const long timeBaseSec, const StatsdConfig& config, sp<StatsLogProcessor> CreateStatsLogProcessor(const long timeBaseSec, const StatsdConfig& config,

View File

@@ -94,55 +94,31 @@ FieldMatcher CreateAttributionUidDimensions(const int atomId,
// Create log event for screen state changed. // Create log event for screen state changed.
std::unique_ptr<LogEvent> CreateScreenStateChangedEvent( std::unique_ptr<LogEvent> CreateScreenStateChangedEvent(
const android::view::DisplayStateEnum state, uint64_t timestampNs); uint64_t timestampNs, const android::view::DisplayStateEnum state);
// Create log event for screen brightness state changed.
std::unique_ptr<LogEvent> CreateScreenBrightnessChangedEvent(
int level, uint64_t timestampNs);
// Create log event when scheduled job starts. // Create log event when scheduled job starts.
std::unique_ptr<LogEvent> CreateStartScheduledJobEvent( std::unique_ptr<LogEvent> CreateStartScheduledJobEvent(uint64_t timestampNs,
const std::vector<AttributionNodeInternal>& attributions, const vector<int>& attributionUids,
const string& name, uint64_t timestampNs); const vector<string>& attributionTags,
const string& jobName);
// Create log event when scheduled job finishes. // Create log event when scheduled job finishes.
std::unique_ptr<LogEvent> CreateFinishScheduledJobEvent( std::unique_ptr<LogEvent> CreateFinishScheduledJobEvent(uint64_t timestampNs,
const std::vector<AttributionNodeInternal>& attributions, const vector<int>& attributionUids,
const string& name, uint64_t timestampNs); const vector<string>& attributionTags,
const string& jobName);
// Create log event for app moving to background.
std::unique_ptr<LogEvent> CreateMoveToBackgroundEvent(const int uid, uint64_t timestampNs);
// Create log event for app moving to foreground.
std::unique_ptr<LogEvent> CreateMoveToForegroundEvent(const int uid, uint64_t timestampNs);
// Create log event when the app sync starts. // Create log event when the app sync starts.
std::unique_ptr<LogEvent> CreateSyncStartEvent( std::unique_ptr<LogEvent> CreateSyncStartEvent(uint64_t timestampNs,
const std::vector<AttributionNodeInternal>& attributions, const string& name, const vector<int>& attributionUids,
uint64_t timestampNs); const vector<string>& attributionTags,
const string& name);
// Create log event when the app sync ends. // Create log event when the app sync ends.
std::unique_ptr<LogEvent> CreateSyncEndEvent( std::unique_ptr<LogEvent> CreateSyncEndEvent(uint64_t timestampNs,
const std::vector<AttributionNodeInternal>& attributions, const string& name, const vector<int>& attributionUids,
uint64_t timestampNs); const vector<string>& attributionTags,
const string& name);
// Create log event when the app sync ends.
std::unique_ptr<LogEvent> CreateAppCrashEvent(
const int uid, uint64_t timestampNs);
// Create log event for acquiring wakelock.
std::unique_ptr<LogEvent> CreateAcquireWakelockEvent(
const std::vector<AttributionNodeInternal>& attributions, const string& wakelockName,
uint64_t timestampNs);
// Create log event for releasing wakelock.
std::unique_ptr<LogEvent> CreateReleaseWakelockEvent(
const std::vector<AttributionNodeInternal>& attributions, const string& wakelockName,
uint64_t timestampNs);
// Create log event for releasing wakelock.
std::unique_ptr<LogEvent> CreateIsolatedUidChangedEvent(
int isolatedUid, int hostUid, bool is_create, uint64_t timestampNs);
// Helper function to create an AttributionNodeInternal proto. // Helper function to create an AttributionNodeInternal proto.
AttributionNodeInternal CreateAttribution(const int& uid, const string& tag); AttributionNodeInternal CreateAttribution(const int& uid, const string& tag);