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 string module = 50004;
|
||||
repeated string module = 50004;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ AtomDecl::AtomDecl(const AtomDecl &that)
|
||||
uidField(that.uidField),
|
||||
whitelisted(that.whitelisted),
|
||||
binaryFields(that.binaryFields),
|
||||
hasModule(that.hasModule),
|
||||
moduleName(that.moduleName) {}
|
||||
moduleNames(that.moduleNames) {}
|
||||
|
||||
AtomDecl::AtomDecl(int c, const string& n, const string& m)
|
||||
:code(c),
|
||||
@@ -442,9 +441,9 @@ int collate_atoms(const Descriptor *descriptor, Atoms *atoms) {
|
||||
atomDecl.whitelisted = true;
|
||||
}
|
||||
|
||||
if (atomField->options().HasExtension(os::statsd::module)) {
|
||||
atomDecl.hasModule = true;
|
||||
atomDecl.moduleName = atomField->options().GetExtension(os::statsd::module);
|
||||
for (int j = 0; j < atomField->options().ExtensionSize(os::statsd::module); ++j) {
|
||||
const string moduleName = atomField->options().GetExtension(os::statsd::module, j);
|
||||
atomDecl.moduleNames.insert(moduleName);
|
||||
}
|
||||
|
||||
vector<java_type_t> signature;
|
||||
@@ -453,36 +452,15 @@ int collate_atoms(const Descriptor *descriptor, Atoms *atoms) {
|
||||
errorCount++;
|
||||
}
|
||||
|
||||
// Add the signature if does not already exist.
|
||||
auto signature_to_modules_it = atoms->signatures_to_modules.find(signature);
|
||||
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->signatures_to_modules[signature].insert(
|
||||
atomDecl.moduleNames.begin(), atomDecl.moduleNames.end());
|
||||
atoms->decls.insert(atomDecl);
|
||||
|
||||
AtomDecl nonChainedAtomDecl(atomField->number(), atomField->name(), atom->name());
|
||||
vector<java_type_t> nonChainedSignature;
|
||||
if (get_non_chained_node(atom, &nonChainedAtomDecl, &nonChainedSignature)) {
|
||||
auto it = atoms->non_chained_signatures_to_modules.find(nonChainedSignature);
|
||||
if (it == atoms->non_chained_signatures_to_modules.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_signatures_to_modules[nonChainedSignature].insert(
|
||||
atomDecl.moduleNames.begin(), atomDecl.moduleNames.end());
|
||||
atoms->non_chained_decls.insert(nonChainedAtomDecl);
|
||||
}
|
||||
|
||||
|
||||
@@ -98,8 +98,7 @@ struct AtomDecl {
|
||||
|
||||
vector<int> binaryFields;
|
||||
|
||||
bool hasModule = false;
|
||||
string moduleName;
|
||||
set<string> moduleNames;
|
||||
|
||||
AtomDecl();
|
||||
AtomDecl(const AtomDecl& that);
|
||||
|
||||
@@ -213,6 +213,10 @@ message ModuleTwoAtom {
|
||||
optional int32 field = 1;
|
||||
}
|
||||
|
||||
message ModuleOneAndTwoAtom {
|
||||
optional int32 field = 1;
|
||||
}
|
||||
|
||||
message NoModuleAtom {
|
||||
optional string field = 1;
|
||||
}
|
||||
@@ -221,6 +225,9 @@ message ModuleAtoms {
|
||||
oneof event {
|
||||
ModuleOneAtom module_one_atom = 1 [(android.os.statsd.module) = "module1"];
|
||||
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;
|
||||
int errorCount = collate_atoms(ModuleAtoms::descriptor(), &atoms);
|
||||
EXPECT_EQ(errorCount, 0);
|
||||
EXPECT_EQ(atoms.decls.size(), 3ul);
|
||||
EXPECT_EQ(atoms.decls.size(), 4ul);
|
||||
}
|
||||
|
||||
TEST(CollationTest, RecognizeModuleAtom) {
|
||||
Atoms atoms;
|
||||
int errorCount = collate_atoms(ModuleAtoms::descriptor(), &atoms);
|
||||
EXPECT_EQ(errorCount, 0);
|
||||
EXPECT_EQ(atoms.decls.size(), 3ul);
|
||||
EXPECT_EQ(atoms.decls.size(), 4ul);
|
||||
for (const auto& atomDecl: atoms.decls) {
|
||||
if (atomDecl.code == 1) {
|
||||
EXPECT_TRUE(atomDecl.hasModule);
|
||||
EXPECT_EQ(atomDecl.moduleName, "module1");
|
||||
EXPECT_EQ(1ul, atomDecl.moduleNames.size());
|
||||
EXPECT_NE(atomDecl.moduleNames.end(), atomDecl.moduleNames.find("module1"));
|
||||
} else if (atomDecl.code == 2) {
|
||||
EXPECT_TRUE(atomDecl.hasModule);
|
||||
EXPECT_EQ(atomDecl.moduleName, "module2");
|
||||
EXPECT_EQ(1ul, atomDecl.moduleNames.size());
|
||||
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 {
|
||||
EXPECT_FALSE(atomDecl.hasModule);
|
||||
EXPECT_TRUE(atomDecl.moduleNames.empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,4 +290,4 @@ TEST(CollationTest, RecognizeModuleAtom) {
|
||||
}
|
||||
|
||||
} // namespace stats_log_api_gen
|
||||
} // namespace android
|
||||
} // namespace android
|
||||
|
||||
@@ -102,7 +102,7 @@ bool atom_needed_for_module(const AtomDecl& atomDecl, const string& moduleName)
|
||||
if (moduleName == DEFAULT_MODULE_NAME) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user