Remove libstatslog from libstatsmetadata
Instead of relying on the constants in libstatslog, hardcode them in
atoms_info to get rid of the dependency on libstatslog
New generated atoms_info.cpp:
https://paste.googleplex.com/5779947622760448
Bug: 150417465
Test: m libstatsmetadata
Change-Id: I954c963f1883f889053b63d308c648548de71e56
diff --git a/cmds/statsd/Android.bp b/cmds/statsd/Android.bp
index 0c3a49a..959c32c 100644
--- a/cmds/statsd/Android.bp
+++ b/cmds/statsd/Android.bp
@@ -165,10 +165,6 @@
export_generated_headers: [
"atoms_info.h",
],
- shared_libs: [
- "libcutils",
- "libstatslog",
- ],
apex_available: [
//TODO(b/149782403): Remove this once statsd no longer links against libstatsmetadata
"com.android.os.statsd",
diff --git a/tools/stats_log_api_gen/atoms_info_writer.cpp b/tools/stats_log_api_gen/atoms_info_writer.cpp
index 984c929..58f13a4 100644
--- a/tools/stats_log_api_gen/atoms_info_writer.cpp
+++ b/tools/stats_log_api_gen/atoms_info_writer.cpp
@@ -58,19 +58,25 @@
}
static void write_atoms_info_cpp_body(FILE* out, const Atoms& atoms) {
- std::set<string> kTruncatingAtomNames = {"mobile_radio_power_state_changed",
- "audio_state_changed",
- "call_state_changed",
- "phone_signal_strength_changed",
- "mobile_bytes_transfer_by_fg_bg",
- "mobile_bytes_transfer"};
+ std::set<string> kTruncatingAtomNames = {
+ "mobile_radio_power_state_changed",
+ "audio_state_changed",
+ "call_state_changed",
+ "phone_signal_strength_changed",
+ "mobile_bytes_transfer_by_fg_bg",
+ "mobile_bytes_transfer"
+ };
fprintf(out,
"const std::set<int> "
"AtomsInfo::kTruncatingTimestampAtomBlackList = {\n");
- for (set<string>::const_iterator blacklistedAtom = kTruncatingAtomNames.begin();
- blacklistedAtom != kTruncatingAtomNames.end(); blacklistedAtom++) {
- fprintf(out, " %s,\n", make_constant_name(*blacklistedAtom).c_str());
+ for (set<AtomDecl>::const_iterator atom = atoms.decls.begin();
+ atom != atoms.decls.end(); atom++) {
+ if (kTruncatingAtomNames.find(atom->name) != kTruncatingAtomNames.end()) {
+ const string constant = make_constant_name(atom->name);
+ fprintf(out, " %d, // %s\n", atom->code, constant.c_str());
+ }
}
+
fprintf(out, "};\n");
fprintf(out, "\n");
@@ -81,8 +87,8 @@
for (vector<AtomField>::const_iterator field = atom->fields.begin();
field != atom->fields.end(); field++) {
if (field->javaType == JAVA_TYPE_ATTRIBUTION_CHAIN) {
- string constant = make_constant_name(atom->name);
- fprintf(out, " %s,\n", constant.c_str());
+ const string constant = make_constant_name(atom->name);
+ fprintf(out, " %d, // %s\n", atom->code, constant.c_str());
break;
}
}
@@ -96,8 +102,8 @@
for (set<AtomDecl>::const_iterator atom = atoms.decls.begin();
atom != atoms.decls.end(); atom++) {
if (atom->whitelisted) {
- string constant = make_constant_name(atom->name);
- fprintf(out, " %s,\n", constant.c_str());
+ const string constant = make_constant_name(atom->name);
+ fprintf(out, " %d, // %s\n", atom->code, constant.c_str());
}
}
@@ -105,7 +111,7 @@
fprintf(out, "\n");
fprintf(out, "static std::map<int, int> getAtomUidField() {\n");
- fprintf(out, " std::map<int, int> uidField;\n");
+ fprintf(out, " std::map<int, int> uidField;\n");
for (set<AtomDecl>::const_iterator atom = atoms.decls.begin();
atom != atoms.decls.end(); atom++) {
if (atom->uidField == 0) {
@@ -115,8 +121,8 @@
"\n // Adding uid field for atom "
"(%d)%s\n",
atom->code, atom->name.c_str());
- fprintf(out, " uidField[static_cast<int>(%s)] = %d;\n",
- make_constant_name(atom->name).c_str(), atom->uidField);
+ fprintf(out, " uidField[%d /* %s */] = %d;\n",
+ atom->code, make_constant_name(atom->name).c_str(), atom->uidField);
}
fprintf(out, " return uidField;\n");
@@ -140,8 +146,8 @@
"\n // Adding primary and exclusive fields for atom "
"(%d)%s\n",
atom->code, atom->name.c_str());
- fprintf(out, " opt = &(options[static_cast<int>(%s)]);\n",
- make_constant_name(atom->name).c_str());
+ fprintf(out, " opt = &(options[%d /* %s */]);\n",
+ atom->code, make_constant_name(atom->name).c_str());
fprintf(out, " opt->primaryFields.reserve(%lu);\n", atom->primaryFields.size());
for (const auto& field : atom->primaryFields) {
fprintf(out, " opt->primaryFields.push_back(%d);\n", field);
@@ -185,8 +191,8 @@
atom->code, atom->name.c_str());
for (const auto& field : atom->binaryFields) {
- fprintf(out, " options[static_cast<int>(%s)].push_back(%d);\n",
- make_constant_name(atom->name).c_str(), field);
+ fprintf(out, " options[%d /* %s */].push_back(%d);\n",
+ atom->code, make_constant_name(atom->name).c_str(), field);
}
}
@@ -222,12 +228,11 @@
}
int write_atoms_info_cpp(FILE *out, const Atoms &atoms, const string& namespaceStr,
- const string& importHeader, const string& statslogHeader) {
+ const string& importHeader) {
// Print prelude
fprintf(out, "// This file is autogenerated\n");
fprintf(out, "\n");
fprintf(out, "#include <%s>\n", importHeader.c_str());
- fprintf(out, "#include <%s>\n", statslogHeader.c_str());
fprintf(out, "\n");
write_namespace(out, namespaceStr);
diff --git a/tools/stats_log_api_gen/atoms_info_writer.h b/tools/stats_log_api_gen/atoms_info_writer.h
index 12ac862..d04e65a 100644
--- a/tools/stats_log_api_gen/atoms_info_writer.h
+++ b/tools/stats_log_api_gen/atoms_info_writer.h
@@ -27,7 +27,7 @@
using namespace std;
int write_atoms_info_cpp(FILE* out, const Atoms& atoms, const string& namespaceStr,
- const string& importHeader, const string& statslogHeader);
+ const string& importHeader);
int write_atoms_info_header(FILE* out, const Atoms& atoms, const string& namespaceStr);
diff --git a/tools/stats_log_api_gen/main.cpp b/tools/stats_log_api_gen/main.cpp
index ddbf22c..8ea6fcb 100644
--- a/tools/stats_log_api_gen/main.cpp
+++ b/tools/stats_log_api_gen/main.cpp
@@ -682,7 +682,7 @@
return 1;
}
errorCount = android::stats_log_api_gen::write_atoms_info_cpp(
- out, atoms, cppNamespace, atomsInfoCppHeaderImport, cppHeaderImport);
+ out, atoms, cppNamespace, atomsInfoCppHeaderImport);
fclose(out);
}