Loading cmds/statsd/src/atoms.proto +9 −9 Original line number Diff line number Diff line Loading @@ -4590,7 +4590,7 @@ message GeneralExternalStorageAccessStats { // Includes file path and ContentResolver accesses optional uint32 secondary_storage_accesses = 4; // Comma-separated list of mime types that were accessed. optional MimeTypes mime_types_accessed = 5; optional MimeTypes mime_types_accessed = 5 [(log_mode) = MODE_BYTES]; } /** Loading Loading @@ -6174,7 +6174,7 @@ message ProcessStatsAvailablePagesProto { * Pulled from ProcessStatsService.java */ message ProcStats { optional ProcessStatsSectionProto proc_stats_section = 1; optional ProcessStatsSectionProto proc_stats_section = 1 [(log_mode) = MODE_BYTES]; // Data pulled from device into this is sometimes sharded across multiple atoms to work around // a size limit. When this happens, this shard ID will contain an increasing 1-indexed integer // with the number of this shard. Loading @@ -6185,7 +6185,7 @@ message ProcStats { * Pulled from ProcessStatsService.java */ message ProcStatsPkgProc { optional ProcessStatsSectionProto proc_stats_section = 1; optional ProcessStatsSectionProto proc_stats_section = 1 [(log_mode) = MODE_BYTES]; } // Next Tag: 2 Loading @@ -6203,7 +6203,7 @@ message NotificationRemoteViewsProto { * Pulled from NotificationManagerService.java */ message NotificationRemoteViews { optional NotificationRemoteViewsProto notification_remote_views = 1; optional NotificationRemoteViewsProto notification_remote_views = 1 [(log_mode) = MODE_BYTES]; } /** Loading Loading @@ -6271,7 +6271,7 @@ message DNDModeProto { // May also be "MANUAL_RULE" to indicate app-activation of the manual rule. optional string id = 5; optional int32 uid = 6 [(is_uid) = true]; // currently only SYSTEM_UID or 0 for other optional DNDPolicyProto policy = 7; optional DNDPolicyProto policy = 7 [(log_mode) = MODE_BYTES]; } /** Loading Loading @@ -6436,7 +6436,7 @@ message PowerProfileProto { * Pulled from PowerProfile.java */ message PowerProfile { optional PowerProfileProto power_profile = 1; optional PowerProfileProto power_profile = 1 [(log_mode) = MODE_BYTES]; } /** Loading Loading @@ -8131,7 +8131,7 @@ message DeviceIdentifierAccessDenied { message TrainInfo { optional int64 train_version_code = 1; optional TrainExperimentIds train_experiment_id = 2; optional TrainExperimentIds train_experiment_id = 2 [(log_mode) = MODE_BYTES]; optional string train_name = 3; Loading Loading @@ -11179,8 +11179,8 @@ message BlobInfo { optional int64 expiry_timestamp_millis = 3; // List of committers of this Blob optional BlobCommitterListProto committers = 4; optional BlobCommitterListProto committers = 4 [(log_mode) = MODE_BYTES]; // List of leasees of this Blob optional BlobLeaseeListProto leasees = 5; optional BlobLeaseeListProto leasees = 5 [(log_mode) = MODE_BYTES]; } tools/stats_log_api_gen/Collation.cpp +40 −13 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ namespace android { namespace stats_log_api_gen { using google::protobuf::OneofDescriptor; using google::protobuf::EnumDescriptor; using google::protobuf::FieldDescriptor; using google::protobuf::FileDescriptor; Loading Loading @@ -396,8 +397,7 @@ int collate_atom(const Descriptor* atom, AtomDecl* atomDecl, vector<java_type_t> collate_enums(*field->enum_type(), &atField); } // Generate signature for pushed atoms if (atomDecl->code < PULL_ATOM_START_ID) { // Generate signature for atom. if (javaType == JAVA_TYPE_ENUM) { // All enums are treated as ints when it comes to function signatures. signature->push_back(JAVA_TYPE_INT); Loading @@ -406,7 +406,6 @@ int collate_atom(const Descriptor* atom, AtomDecl* atomDecl, vector<java_type_t> } else { signature->push_back(javaType); } } atomDecl->fields.push_back(atField); Loading Loading @@ -518,8 +517,7 @@ int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* shared_ptr<AtomDecl> atomDecl = make_shared<AtomDecl>(atomField->number(), atomField->name(), atom->name()); if (atomDecl->code < PULL_ATOM_START_ID && atomField->options().GetExtension(os::statsd::truncate_timestamp)) { if (atomField->options().GetExtension(os::statsd::truncate_timestamp)) { addAnnotationToAtomDecl(atomDecl.get(), ATOM_ID_FIELD_NUMBER, ANNOTATION_ID_TRUNCATE_TIMESTAMP, ANNOTATION_TYPE_BOOL, AnnotationValue(true)); Loading @@ -537,7 +535,24 @@ int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* continue; } FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet = atoms->signatureInfoMap[signature]; const OneofDescriptor* oneofAtom = atomField->containing_oneof(); if (oneofAtom == nullptr) { print_error(atomField, "Atom is not declared in a `oneof` field: %s\n", atomField->name().c_str()); errorCount++; continue; } else if ((oneofAtom->name() != ONEOF_PUSHED_ATOM_NAME) && (oneofAtom->name() != ONEOF_PULLED_ATOM_NAME)) { print_error(atomField, "Atom is neither a pushed nor pulled atom: %s\n", atomField->name().c_str()); errorCount++; continue; } FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet = oneofAtom->name() == ONEOF_PUSHED_ATOM_NAME ? atoms->signatureInfoMap[signature] : atoms->pulledAtomsSignatureInfoMap[signature]; populateFieldNumberToAtomDeclSet(atomDecl, &fieldNumberToAtomDeclSet); atoms->decls.insert(atomDecl); Loading @@ -556,6 +571,7 @@ int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* } if (dbg) { // Signatures for pushed atoms. printf("signatures = [\n"); for (SignatureInfoMap::const_iterator it = atoms->signatureInfoMap.begin(); it != atoms->signatureInfoMap.end(); it++) { Loading @@ -566,6 +582,17 @@ int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* } printf("\n"); } // Signatures for pull atoms. for (SignatureInfoMap::const_iterator it = atoms->pulledAtomsSignatureInfoMap.begin(); it != atoms->pulledAtomsSignatureInfoMap.end(); it++) { printf(" "); for (vector<java_type_t>::const_iterator jt = it->first.begin(); jt != it->first.end(); jt++) { printf(" %d", (int)*jt); } printf("\n"); } printf("]\n"); } Loading tools/stats_log_api_gen/Collation.h +10 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ namespace android { namespace stats_log_api_gen { using google::protobuf::OneofDescriptor; using google::protobuf::Descriptor; using google::protobuf::FieldDescriptor; using std::map; Loading @@ -41,6 +42,14 @@ const int PULL_ATOM_START_ID = 10000; const int FIRST_UID_IN_CHAIN_ID = 0; /** * The types of oneof atoms. * * `OneofDescriptor::name()` returns the name of the oneof. */ const string ONEOF_PUSHED_ATOM_NAME = "pushed"; const string ONEOF_PULLED_ATOM_NAME = "pulled"; enum AnnotationId : uint8_t { ANNOTATION_ID_IS_UID = 1, ANNOTATION_ID_TRUNCATE_TIMESTAMP = 2, Loading Loading @@ -184,6 +193,7 @@ using SignatureInfoMap = map<vector<java_type_t>, FieldNumberToAtomDeclSet>; struct Atoms { SignatureInfoMap signatureInfoMap; SignatureInfoMap pulledAtomsSignatureInfoMap; AtomDeclSet decls; AtomDeclSet non_chained_decls; SignatureInfoMap nonChainedSignatureInfoMap; Loading tools/stats_log_api_gen/java_writer.cpp +184 −142 Original line number Diff line number Diff line Loading @@ -96,14 +96,8 @@ static void write_annotations(FILE* out, int argIndex, } } static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMap, const AtomDecl& attributionDecl, const bool supportQ) { for (auto signatureInfoMapIt = signatureInfoMap.begin(); signatureInfoMapIt != signatureInfoMap.end(); signatureInfoMapIt++) { // Print method signature. fprintf(out, " public static void write(int code"); const vector<java_type_t>& signature = signatureInfoMapIt->first; const FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet = signatureInfoMapIt->second; static void write_method_signature(FILE* out, const vector<java_type_t>& signature, const AtomDecl& attributionDecl) { int argIndex = 1; for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end(); arg++) { Loading @@ -119,15 +113,11 @@ static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMa } argIndex++; } fprintf(out, ") {\n"); // Print method body. string indent(""); if (supportQ) { fprintf(out, " if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {\n"); indent = " "; } static int write_method_body(FILE* out, const vector<java_type_t>& signature, const FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet, const AtomDecl& attributionDecl, const string& indent) { // Start StatsEvent.Builder. fprintf(out, "%s final StatsEvent.Builder builder = " Loading @@ -139,7 +129,7 @@ static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMa write_annotations(out, ATOM_ID_FIELD_NUMBER, fieldNumberToAtomDeclSet); // Write the args. argIndex = 1; int argIndex = 1; for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end(); arg++) { switch (*arg) { Loading Loading @@ -250,8 +240,32 @@ static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMa write_annotations(out, argIndex, fieldNumberToAtomDeclSet); argIndex++; } return 0; } static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMap, const AtomDecl& attributionDecl, const bool supportQ) { for (auto signatureInfoMapIt = signatureInfoMap.begin(); signatureInfoMapIt != signatureInfoMap.end(); signatureInfoMapIt++) { // Print method signature. fprintf(out, " public static void write(int code"); write_method_signature(out, signatureInfoMapIt->first, attributionDecl); fprintf(out, ") {\n"); // Print method body. string indent(""); if (supportQ) { fprintf(out, " if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {\n"); indent = " "; } int ret = write_method_body(out, signatureInfoMapIt->first, signatureInfoMapIt->second, attributionDecl, indent); if (ret != 0) { return ret; } fprintf(out, "\n"); fprintf(out, "%s builder.usePooledBuffer();\n", indent.c_str()); fprintf(out, "%s StatsLog.write(builder.build());\n", indent.c_str()); Loading @@ -259,9 +273,9 @@ static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMa if (supportQ) { fprintf(out, " } else {\n"); fprintf(out, " QLogger.write(code"); argIndex = 1; for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end(); arg++) { int argIndex = 1; for (vector<java_type_t>::const_iterator arg = signatureInfoMapIt->first.begin(); arg != signatureInfoMapIt->first.end(); arg++) { if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) { const char* uidName = attributionDecl.fields.front().name.c_str(); const char* tagName = attributionDecl.fields.back().name.c_str(); Loading @@ -285,6 +299,32 @@ static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMa return 0; } static int write_java_build_stats_event_methods(FILE* out, const SignatureInfoMap& signatureInfoMap, const AtomDecl& attributionDecl) { for (auto signatureInfoMapIt = signatureInfoMap.begin(); signatureInfoMapIt != signatureInfoMap.end(); signatureInfoMapIt++) { // Print method signature. fprintf(out, " public static StatsEvent buildStatsEvent(int code"); write_method_signature(out, signatureInfoMapIt->first, attributionDecl); fprintf(out, ") {\n"); // Print method body. string indent(""); int ret = write_method_body(out, signatureInfoMapIt->first, signatureInfoMapIt->second, attributionDecl, indent); if (ret != 0) { return ret; } fprintf(out, "\n"); fprintf(out, "%s return builder.build();\n", indent.c_str()); fprintf(out, " }\n"); // method fprintf(out, "\n"); } return 0; } int write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl, const string& javaClass, const string& javaPackage, const bool supportQ, const bool supportWorkSource) { Loading Loading @@ -319,6 +359,8 @@ int write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl& attribut fprintf(out, " // Write methods\n"); errors += write_java_methods(out, atoms.signatureInfoMap, attributionDecl, supportQ); errors += write_java_non_chained_methods(out, atoms.nonChainedSignatureInfoMap); errors += write_java_build_stats_event_methods(out, atoms.pulledAtomsSignatureInfoMap, attributionDecl); if (supportWorkSource) { errors += write_java_work_source_methods(out, atoms.signatureInfoMap); } Loading tools/stats_log_api_gen/test.proto +31 −10 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ message AllTypesAtom { } message Event { oneof event { oneof pushed { OutOfOrderAtom out_of_order_atom = 2; IntAtom int_atom = 1; AnotherIntAtom another_int_atom = 3; Loading @@ -74,7 +74,7 @@ message BadTypesAtom { } message BadTypesEvent { oneof event { oneof pushed { BadTypesAtom bad_types_atom = 1; } } Loading @@ -84,7 +84,7 @@ message BadSkippedFieldSingleAtom { } message BadSkippedFieldSingle { oneof event { oneof pushed { BadSkippedFieldSingleAtom bad = 1; } } Loading @@ -96,7 +96,7 @@ message BadSkippedFieldMultipleAtom { } message BadSkippedFieldMultiple { oneof event { oneof pushed { BadSkippedFieldMultipleAtom bad = 1; } } Loading @@ -107,11 +107,11 @@ message BadAttributionNodePositionAtom { } message BadAttributionNodePosition { oneof event { BadAttributionNodePositionAtom bad = 1; } oneof pushed { BadAttributionNodePositionAtom bad = 1; } } message GoodEventWithBinaryFieldAtom { oneof event { GoodBinaryFieldAtom field1 = 1; } oneof pushed { GoodBinaryFieldAtom field1 = 1; } } message ComplexField { Loading @@ -124,7 +124,7 @@ message GoodBinaryFieldAtom { } message BadEventWithBinaryFieldAtom { oneof event { BadBinaryFieldAtom field1 = 1; } oneof pushed { BadBinaryFieldAtom field1 = 1; } } message BadBinaryFieldAtom { Loading @@ -133,7 +133,7 @@ message BadBinaryFieldAtom { } message BadStateAtoms { oneof event { oneof pushed { BadStateAtom1 bad1 = 1; BadStateAtom2 bad2 = 2; BadStateAtom3 bad3 = 3; Loading @@ -141,7 +141,7 @@ message BadStateAtoms { } message GoodStateAtoms { oneof event { oneof pushed { GoodStateAtom1 good1 = 1; GoodStateAtom2 good2 = 2; } Loading Loading @@ -204,7 +204,7 @@ message NoModuleAtom { } message ModuleAtoms { oneof event { oneof pushed { ModuleOneAtom module_one_atom = 1 [(android.os.statsd.module) = "module1"]; ModuleTwoAtom module_two_atom = 2 [(android.os.statsd.module) = "module2"]; ModuleOneAndTwoAtom module_one_and_two_atom = 3 [ Loading @@ -213,3 +213,24 @@ message ModuleAtoms { NoModuleAtom no_module_atom = 4; } } message NotAPushNorPullAtom { oneof event { IntAtom int_atom = 1; } } message AtomNotInAOneof { optional IntAtom int_atom = 1; } message PushedAndPulledAtoms { oneof pushed { IntAtom int_atom_1 = 1; } oneof pulled { OutOfOrderAtom out_of_order_atom = 11; AnotherIntAtom another_int_atom = 10; } } Loading
cmds/statsd/src/atoms.proto +9 −9 Original line number Diff line number Diff line Loading @@ -4590,7 +4590,7 @@ message GeneralExternalStorageAccessStats { // Includes file path and ContentResolver accesses optional uint32 secondary_storage_accesses = 4; // Comma-separated list of mime types that were accessed. optional MimeTypes mime_types_accessed = 5; optional MimeTypes mime_types_accessed = 5 [(log_mode) = MODE_BYTES]; } /** Loading Loading @@ -6174,7 +6174,7 @@ message ProcessStatsAvailablePagesProto { * Pulled from ProcessStatsService.java */ message ProcStats { optional ProcessStatsSectionProto proc_stats_section = 1; optional ProcessStatsSectionProto proc_stats_section = 1 [(log_mode) = MODE_BYTES]; // Data pulled from device into this is sometimes sharded across multiple atoms to work around // a size limit. When this happens, this shard ID will contain an increasing 1-indexed integer // with the number of this shard. Loading @@ -6185,7 +6185,7 @@ message ProcStats { * Pulled from ProcessStatsService.java */ message ProcStatsPkgProc { optional ProcessStatsSectionProto proc_stats_section = 1; optional ProcessStatsSectionProto proc_stats_section = 1 [(log_mode) = MODE_BYTES]; } // Next Tag: 2 Loading @@ -6203,7 +6203,7 @@ message NotificationRemoteViewsProto { * Pulled from NotificationManagerService.java */ message NotificationRemoteViews { optional NotificationRemoteViewsProto notification_remote_views = 1; optional NotificationRemoteViewsProto notification_remote_views = 1 [(log_mode) = MODE_BYTES]; } /** Loading Loading @@ -6271,7 +6271,7 @@ message DNDModeProto { // May also be "MANUAL_RULE" to indicate app-activation of the manual rule. optional string id = 5; optional int32 uid = 6 [(is_uid) = true]; // currently only SYSTEM_UID or 0 for other optional DNDPolicyProto policy = 7; optional DNDPolicyProto policy = 7 [(log_mode) = MODE_BYTES]; } /** Loading Loading @@ -6436,7 +6436,7 @@ message PowerProfileProto { * Pulled from PowerProfile.java */ message PowerProfile { optional PowerProfileProto power_profile = 1; optional PowerProfileProto power_profile = 1 [(log_mode) = MODE_BYTES]; } /** Loading Loading @@ -8131,7 +8131,7 @@ message DeviceIdentifierAccessDenied { message TrainInfo { optional int64 train_version_code = 1; optional TrainExperimentIds train_experiment_id = 2; optional TrainExperimentIds train_experiment_id = 2 [(log_mode) = MODE_BYTES]; optional string train_name = 3; Loading Loading @@ -11179,8 +11179,8 @@ message BlobInfo { optional int64 expiry_timestamp_millis = 3; // List of committers of this Blob optional BlobCommitterListProto committers = 4; optional BlobCommitterListProto committers = 4 [(log_mode) = MODE_BYTES]; // List of leasees of this Blob optional BlobLeaseeListProto leasees = 5; optional BlobLeaseeListProto leasees = 5 [(log_mode) = MODE_BYTES]; }
tools/stats_log_api_gen/Collation.cpp +40 −13 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ namespace android { namespace stats_log_api_gen { using google::protobuf::OneofDescriptor; using google::protobuf::EnumDescriptor; using google::protobuf::FieldDescriptor; using google::protobuf::FileDescriptor; Loading Loading @@ -396,8 +397,7 @@ int collate_atom(const Descriptor* atom, AtomDecl* atomDecl, vector<java_type_t> collate_enums(*field->enum_type(), &atField); } // Generate signature for pushed atoms if (atomDecl->code < PULL_ATOM_START_ID) { // Generate signature for atom. if (javaType == JAVA_TYPE_ENUM) { // All enums are treated as ints when it comes to function signatures. signature->push_back(JAVA_TYPE_INT); Loading @@ -406,7 +406,6 @@ int collate_atom(const Descriptor* atom, AtomDecl* atomDecl, vector<java_type_t> } else { signature->push_back(javaType); } } atomDecl->fields.push_back(atField); Loading Loading @@ -518,8 +517,7 @@ int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* shared_ptr<AtomDecl> atomDecl = make_shared<AtomDecl>(atomField->number(), atomField->name(), atom->name()); if (atomDecl->code < PULL_ATOM_START_ID && atomField->options().GetExtension(os::statsd::truncate_timestamp)) { if (atomField->options().GetExtension(os::statsd::truncate_timestamp)) { addAnnotationToAtomDecl(atomDecl.get(), ATOM_ID_FIELD_NUMBER, ANNOTATION_ID_TRUNCATE_TIMESTAMP, ANNOTATION_TYPE_BOOL, AnnotationValue(true)); Loading @@ -537,7 +535,24 @@ int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* continue; } FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet = atoms->signatureInfoMap[signature]; const OneofDescriptor* oneofAtom = atomField->containing_oneof(); if (oneofAtom == nullptr) { print_error(atomField, "Atom is not declared in a `oneof` field: %s\n", atomField->name().c_str()); errorCount++; continue; } else if ((oneofAtom->name() != ONEOF_PUSHED_ATOM_NAME) && (oneofAtom->name() != ONEOF_PULLED_ATOM_NAME)) { print_error(atomField, "Atom is neither a pushed nor pulled atom: %s\n", atomField->name().c_str()); errorCount++; continue; } FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet = oneofAtom->name() == ONEOF_PUSHED_ATOM_NAME ? atoms->signatureInfoMap[signature] : atoms->pulledAtomsSignatureInfoMap[signature]; populateFieldNumberToAtomDeclSet(atomDecl, &fieldNumberToAtomDeclSet); atoms->decls.insert(atomDecl); Loading @@ -556,6 +571,7 @@ int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* } if (dbg) { // Signatures for pushed atoms. printf("signatures = [\n"); for (SignatureInfoMap::const_iterator it = atoms->signatureInfoMap.begin(); it != atoms->signatureInfoMap.end(); it++) { Loading @@ -566,6 +582,17 @@ int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* } printf("\n"); } // Signatures for pull atoms. for (SignatureInfoMap::const_iterator it = atoms->pulledAtomsSignatureInfoMap.begin(); it != atoms->pulledAtomsSignatureInfoMap.end(); it++) { printf(" "); for (vector<java_type_t>::const_iterator jt = it->first.begin(); jt != it->first.end(); jt++) { printf(" %d", (int)*jt); } printf("\n"); } printf("]\n"); } Loading
tools/stats_log_api_gen/Collation.h +10 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ namespace android { namespace stats_log_api_gen { using google::protobuf::OneofDescriptor; using google::protobuf::Descriptor; using google::protobuf::FieldDescriptor; using std::map; Loading @@ -41,6 +42,14 @@ const int PULL_ATOM_START_ID = 10000; const int FIRST_UID_IN_CHAIN_ID = 0; /** * The types of oneof atoms. * * `OneofDescriptor::name()` returns the name of the oneof. */ const string ONEOF_PUSHED_ATOM_NAME = "pushed"; const string ONEOF_PULLED_ATOM_NAME = "pulled"; enum AnnotationId : uint8_t { ANNOTATION_ID_IS_UID = 1, ANNOTATION_ID_TRUNCATE_TIMESTAMP = 2, Loading Loading @@ -184,6 +193,7 @@ using SignatureInfoMap = map<vector<java_type_t>, FieldNumberToAtomDeclSet>; struct Atoms { SignatureInfoMap signatureInfoMap; SignatureInfoMap pulledAtomsSignatureInfoMap; AtomDeclSet decls; AtomDeclSet non_chained_decls; SignatureInfoMap nonChainedSignatureInfoMap; Loading
tools/stats_log_api_gen/java_writer.cpp +184 −142 Original line number Diff line number Diff line Loading @@ -96,14 +96,8 @@ static void write_annotations(FILE* out, int argIndex, } } static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMap, const AtomDecl& attributionDecl, const bool supportQ) { for (auto signatureInfoMapIt = signatureInfoMap.begin(); signatureInfoMapIt != signatureInfoMap.end(); signatureInfoMapIt++) { // Print method signature. fprintf(out, " public static void write(int code"); const vector<java_type_t>& signature = signatureInfoMapIt->first; const FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet = signatureInfoMapIt->second; static void write_method_signature(FILE* out, const vector<java_type_t>& signature, const AtomDecl& attributionDecl) { int argIndex = 1; for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end(); arg++) { Loading @@ -119,15 +113,11 @@ static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMa } argIndex++; } fprintf(out, ") {\n"); // Print method body. string indent(""); if (supportQ) { fprintf(out, " if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {\n"); indent = " "; } static int write_method_body(FILE* out, const vector<java_type_t>& signature, const FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet, const AtomDecl& attributionDecl, const string& indent) { // Start StatsEvent.Builder. fprintf(out, "%s final StatsEvent.Builder builder = " Loading @@ -139,7 +129,7 @@ static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMa write_annotations(out, ATOM_ID_FIELD_NUMBER, fieldNumberToAtomDeclSet); // Write the args. argIndex = 1; int argIndex = 1; for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end(); arg++) { switch (*arg) { Loading Loading @@ -250,8 +240,32 @@ static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMa write_annotations(out, argIndex, fieldNumberToAtomDeclSet); argIndex++; } return 0; } static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMap, const AtomDecl& attributionDecl, const bool supportQ) { for (auto signatureInfoMapIt = signatureInfoMap.begin(); signatureInfoMapIt != signatureInfoMap.end(); signatureInfoMapIt++) { // Print method signature. fprintf(out, " public static void write(int code"); write_method_signature(out, signatureInfoMapIt->first, attributionDecl); fprintf(out, ") {\n"); // Print method body. string indent(""); if (supportQ) { fprintf(out, " if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {\n"); indent = " "; } int ret = write_method_body(out, signatureInfoMapIt->first, signatureInfoMapIt->second, attributionDecl, indent); if (ret != 0) { return ret; } fprintf(out, "\n"); fprintf(out, "%s builder.usePooledBuffer();\n", indent.c_str()); fprintf(out, "%s StatsLog.write(builder.build());\n", indent.c_str()); Loading @@ -259,9 +273,9 @@ static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMa if (supportQ) { fprintf(out, " } else {\n"); fprintf(out, " QLogger.write(code"); argIndex = 1; for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end(); arg++) { int argIndex = 1; for (vector<java_type_t>::const_iterator arg = signatureInfoMapIt->first.begin(); arg != signatureInfoMapIt->first.end(); arg++) { if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) { const char* uidName = attributionDecl.fields.front().name.c_str(); const char* tagName = attributionDecl.fields.back().name.c_str(); Loading @@ -285,6 +299,32 @@ static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMa return 0; } static int write_java_build_stats_event_methods(FILE* out, const SignatureInfoMap& signatureInfoMap, const AtomDecl& attributionDecl) { for (auto signatureInfoMapIt = signatureInfoMap.begin(); signatureInfoMapIt != signatureInfoMap.end(); signatureInfoMapIt++) { // Print method signature. fprintf(out, " public static StatsEvent buildStatsEvent(int code"); write_method_signature(out, signatureInfoMapIt->first, attributionDecl); fprintf(out, ") {\n"); // Print method body. string indent(""); int ret = write_method_body(out, signatureInfoMapIt->first, signatureInfoMapIt->second, attributionDecl, indent); if (ret != 0) { return ret; } fprintf(out, "\n"); fprintf(out, "%s return builder.build();\n", indent.c_str()); fprintf(out, " }\n"); // method fprintf(out, "\n"); } return 0; } int write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl, const string& javaClass, const string& javaPackage, const bool supportQ, const bool supportWorkSource) { Loading Loading @@ -319,6 +359,8 @@ int write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl& attribut fprintf(out, " // Write methods\n"); errors += write_java_methods(out, atoms.signatureInfoMap, attributionDecl, supportQ); errors += write_java_non_chained_methods(out, atoms.nonChainedSignatureInfoMap); errors += write_java_build_stats_event_methods(out, atoms.pulledAtomsSignatureInfoMap, attributionDecl); if (supportWorkSource) { errors += write_java_work_source_methods(out, atoms.signatureInfoMap); } Loading
tools/stats_log_api_gen/test.proto +31 −10 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ message AllTypesAtom { } message Event { oneof event { oneof pushed { OutOfOrderAtom out_of_order_atom = 2; IntAtom int_atom = 1; AnotherIntAtom another_int_atom = 3; Loading @@ -74,7 +74,7 @@ message BadTypesAtom { } message BadTypesEvent { oneof event { oneof pushed { BadTypesAtom bad_types_atom = 1; } } Loading @@ -84,7 +84,7 @@ message BadSkippedFieldSingleAtom { } message BadSkippedFieldSingle { oneof event { oneof pushed { BadSkippedFieldSingleAtom bad = 1; } } Loading @@ -96,7 +96,7 @@ message BadSkippedFieldMultipleAtom { } message BadSkippedFieldMultiple { oneof event { oneof pushed { BadSkippedFieldMultipleAtom bad = 1; } } Loading @@ -107,11 +107,11 @@ message BadAttributionNodePositionAtom { } message BadAttributionNodePosition { oneof event { BadAttributionNodePositionAtom bad = 1; } oneof pushed { BadAttributionNodePositionAtom bad = 1; } } message GoodEventWithBinaryFieldAtom { oneof event { GoodBinaryFieldAtom field1 = 1; } oneof pushed { GoodBinaryFieldAtom field1 = 1; } } message ComplexField { Loading @@ -124,7 +124,7 @@ message GoodBinaryFieldAtom { } message BadEventWithBinaryFieldAtom { oneof event { BadBinaryFieldAtom field1 = 1; } oneof pushed { BadBinaryFieldAtom field1 = 1; } } message BadBinaryFieldAtom { Loading @@ -133,7 +133,7 @@ message BadBinaryFieldAtom { } message BadStateAtoms { oneof event { oneof pushed { BadStateAtom1 bad1 = 1; BadStateAtom2 bad2 = 2; BadStateAtom3 bad3 = 3; Loading @@ -141,7 +141,7 @@ message BadStateAtoms { } message GoodStateAtoms { oneof event { oneof pushed { GoodStateAtom1 good1 = 1; GoodStateAtom2 good2 = 2; } Loading Loading @@ -204,7 +204,7 @@ message NoModuleAtom { } message ModuleAtoms { oneof event { oneof pushed { ModuleOneAtom module_one_atom = 1 [(android.os.statsd.module) = "module1"]; ModuleTwoAtom module_two_atom = 2 [(android.os.statsd.module) = "module2"]; ModuleOneAndTwoAtom module_one_and_two_atom = 3 [ Loading @@ -213,3 +213,24 @@ message ModuleAtoms { NoModuleAtom no_module_atom = 4; } } message NotAPushNorPullAtom { oneof event { IntAtom int_atom = 1; } } message AtomNotInAOneof { optional IntAtom int_atom = 1; } message PushedAndPulledAtoms { oneof pushed { IntAtom int_atom_1 = 1; } oneof pulled { OutOfOrderAtom out_of_order_atom = 11; AnotherIntAtom another_int_atom = 10; } }