Merge "Support multiple module annotations per atom" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
513453c253
@@ -116,5 +116,5 @@ extend google.protobuf.FieldOptions {
|
|||||||
|
|
||||||
optional bool allow_from_any_uid = 50003 [default = false];
|
optional bool allow_from_any_uid = 50003 [default = false];
|
||||||
|
|
||||||
optional string module = 50004;
|
repeated string module = 50004;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,8 +53,7 @@ AtomDecl::AtomDecl(const AtomDecl &that)
|
|||||||
uidField(that.uidField),
|
uidField(that.uidField),
|
||||||
whitelisted(that.whitelisted),
|
whitelisted(that.whitelisted),
|
||||||
binaryFields(that.binaryFields),
|
binaryFields(that.binaryFields),
|
||||||
hasModule(that.hasModule),
|
moduleNames(that.moduleNames) {}
|
||||||
moduleName(that.moduleName) {}
|
|
||||||
|
|
||||||
AtomDecl::AtomDecl(int c, const string& n, const string& m)
|
AtomDecl::AtomDecl(int c, const string& n, const string& m)
|
||||||
:code(c),
|
:code(c),
|
||||||
@@ -442,9 +441,9 @@ int collate_atoms(const Descriptor *descriptor, Atoms *atoms) {
|
|||||||
atomDecl.whitelisted = true;
|
atomDecl.whitelisted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atomField->options().HasExtension(os::statsd::module)) {
|
for (int j = 0; j < atomField->options().ExtensionSize(os::statsd::module); ++j) {
|
||||||
atomDecl.hasModule = true;
|
const string moduleName = atomField->options().GetExtension(os::statsd::module, j);
|
||||||
atomDecl.moduleName = atomField->options().GetExtension(os::statsd::module);
|
atomDecl.moduleNames.insert(moduleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<java_type_t> signature;
|
vector<java_type_t> signature;
|
||||||
@@ -453,36 +452,15 @@ int collate_atoms(const Descriptor *descriptor, Atoms *atoms) {
|
|||||||
errorCount++;
|
errorCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the signature if does not already exist.
|
atoms->signatures_to_modules[signature].insert(
|
||||||
auto signature_to_modules_it = atoms->signatures_to_modules.find(signature);
|
atomDecl.moduleNames.begin(), atomDecl.moduleNames.end());
|
||||||
if (signature_to_modules_it == atoms->signatures_to_modules.end()) {
|
|
||||||
set<string> modules;
|
|
||||||
if (atomDecl.hasModule) {
|
|
||||||
modules.insert(atomDecl.moduleName);
|
|
||||||
}
|
|
||||||
atoms->signatures_to_modules[signature] = modules;
|
|
||||||
} else {
|
|
||||||
if (atomDecl.hasModule) {
|
|
||||||
signature_to_modules_it->second.insert(atomDecl.moduleName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
atoms->decls.insert(atomDecl);
|
atoms->decls.insert(atomDecl);
|
||||||
|
|
||||||
AtomDecl nonChainedAtomDecl(atomField->number(), atomField->name(), atom->name());
|
AtomDecl nonChainedAtomDecl(atomField->number(), atomField->name(), atom->name());
|
||||||
vector<java_type_t> nonChainedSignature;
|
vector<java_type_t> nonChainedSignature;
|
||||||
if (get_non_chained_node(atom, &nonChainedAtomDecl, &nonChainedSignature)) {
|
if (get_non_chained_node(atom, &nonChainedAtomDecl, &nonChainedSignature)) {
|
||||||
auto it = atoms->non_chained_signatures_to_modules.find(nonChainedSignature);
|
atoms->non_chained_signatures_to_modules[nonChainedSignature].insert(
|
||||||
if (it == atoms->non_chained_signatures_to_modules.end()) {
|
atomDecl.moduleNames.begin(), atomDecl.moduleNames.end());
|
||||||
set<string> modules_non_chained;
|
|
||||||
if (atomDecl.hasModule) {
|
|
||||||
modules_non_chained.insert(atomDecl.moduleName);
|
|
||||||
}
|
|
||||||
atoms->non_chained_signatures_to_modules[nonChainedSignature] = modules_non_chained;
|
|
||||||
} else {
|
|
||||||
if (atomDecl.hasModule) {
|
|
||||||
it->second.insert(atomDecl.moduleName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
atoms->non_chained_decls.insert(nonChainedAtomDecl);
|
atoms->non_chained_decls.insert(nonChainedAtomDecl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,8 +98,7 @@ struct AtomDecl {
|
|||||||
|
|
||||||
vector<int> binaryFields;
|
vector<int> binaryFields;
|
||||||
|
|
||||||
bool hasModule = false;
|
set<string> moduleNames;
|
||||||
string moduleName;
|
|
||||||
|
|
||||||
AtomDecl();
|
AtomDecl();
|
||||||
AtomDecl(const AtomDecl& that);
|
AtomDecl(const AtomDecl& that);
|
||||||
|
|||||||
@@ -213,6 +213,10 @@ message ModuleTwoAtom {
|
|||||||
optional int32 field = 1;
|
optional int32 field = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ModuleOneAndTwoAtom {
|
||||||
|
optional int32 field = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message NoModuleAtom {
|
message NoModuleAtom {
|
||||||
optional string field = 1;
|
optional string field = 1;
|
||||||
}
|
}
|
||||||
@@ -221,6 +225,9 @@ message ModuleAtoms {
|
|||||||
oneof event {
|
oneof event {
|
||||||
ModuleOneAtom module_one_atom = 1 [(android.os.statsd.module) = "module1"];
|
ModuleOneAtom module_one_atom = 1 [(android.os.statsd.module) = "module1"];
|
||||||
ModuleTwoAtom module_two_atom = 2 [(android.os.statsd.module) = "module2"];
|
ModuleTwoAtom module_two_atom = 2 [(android.os.statsd.module) = "module2"];
|
||||||
NoModuleAtom no_module_atom = 3;
|
ModuleOneAndTwoAtom module_one_and_two_atom = 3 [
|
||||||
|
(android.os.statsd.module) = "module1", (android.os.statsd.module) = "module2"
|
||||||
|
];
|
||||||
|
NoModuleAtom no_module_atom = 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,23 +248,27 @@ TEST(CollationTest, PassOnLogFromModuleAtom) {
|
|||||||
Atoms atoms;
|
Atoms atoms;
|
||||||
int errorCount = collate_atoms(ModuleAtoms::descriptor(), &atoms);
|
int errorCount = collate_atoms(ModuleAtoms::descriptor(), &atoms);
|
||||||
EXPECT_EQ(errorCount, 0);
|
EXPECT_EQ(errorCount, 0);
|
||||||
EXPECT_EQ(atoms.decls.size(), 3ul);
|
EXPECT_EQ(atoms.decls.size(), 4ul);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CollationTest, RecognizeModuleAtom) {
|
TEST(CollationTest, RecognizeModuleAtom) {
|
||||||
Atoms atoms;
|
Atoms atoms;
|
||||||
int errorCount = collate_atoms(ModuleAtoms::descriptor(), &atoms);
|
int errorCount = collate_atoms(ModuleAtoms::descriptor(), &atoms);
|
||||||
EXPECT_EQ(errorCount, 0);
|
EXPECT_EQ(errorCount, 0);
|
||||||
EXPECT_EQ(atoms.decls.size(), 3ul);
|
EXPECT_EQ(atoms.decls.size(), 4ul);
|
||||||
for (const auto& atomDecl: atoms.decls) {
|
for (const auto& atomDecl: atoms.decls) {
|
||||||
if (atomDecl.code == 1) {
|
if (atomDecl.code == 1) {
|
||||||
EXPECT_TRUE(atomDecl.hasModule);
|
EXPECT_EQ(1ul, atomDecl.moduleNames.size());
|
||||||
EXPECT_EQ(atomDecl.moduleName, "module1");
|
EXPECT_NE(atomDecl.moduleNames.end(), atomDecl.moduleNames.find("module1"));
|
||||||
} else if (atomDecl.code == 2) {
|
} else if (atomDecl.code == 2) {
|
||||||
EXPECT_TRUE(atomDecl.hasModule);
|
EXPECT_EQ(1ul, atomDecl.moduleNames.size());
|
||||||
EXPECT_EQ(atomDecl.moduleName, "module2");
|
EXPECT_NE(atomDecl.moduleNames.end(), atomDecl.moduleNames.find("module2"));
|
||||||
|
} else if (atomDecl.code == 3) {
|
||||||
|
EXPECT_EQ(2ul, atomDecl.moduleNames.size());
|
||||||
|
EXPECT_NE(atomDecl.moduleNames.end(), atomDecl.moduleNames.find("module1"));
|
||||||
|
EXPECT_NE(atomDecl.moduleNames.end(), atomDecl.moduleNames.find("module2"));
|
||||||
} else {
|
} else {
|
||||||
EXPECT_FALSE(atomDecl.hasModule);
|
EXPECT_TRUE(atomDecl.moduleNames.empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ bool atom_needed_for_module(const AtomDecl& atomDecl, const string& moduleName)
|
|||||||
if (moduleName == DEFAULT_MODULE_NAME) {
|
if (moduleName == DEFAULT_MODULE_NAME) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return atomDecl.hasModule && (moduleName == atomDecl.moduleName);
|
return atomDecl.moduleNames.find(moduleName) != atomDecl.moduleNames.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool signature_needed_for_module(const set<string>& modules, const string& moduleName) {
|
bool signature_needed_for_module(const set<string>& modules, const string& moduleName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user