Merge "Generate compile-time Q-compatible StatsLog" am: d8a5039db0
Change-Id: Ia9206d097b5a5793d35b0e12ec307d013cbe5318
This commit is contained in:
@@ -361,6 +361,50 @@ void write_java_helpers_for_q_schema_methods(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method is called in main.cpp to generate StatsLog for modules that's compatible with
|
||||||
|
// Q at compile-time.
|
||||||
|
int write_stats_log_java_q_for_module(FILE* out, const Atoms& atoms,
|
||||||
|
const AtomDecl &attributionDecl, const string& moduleName,
|
||||||
|
const string& javaClass, const string& javaPackage,
|
||||||
|
const bool supportWorkSource) {
|
||||||
|
// Print prelude
|
||||||
|
fprintf(out, "// This file is autogenerated\n");
|
||||||
|
fprintf(out, "\n");
|
||||||
|
fprintf(out, "package %s;\n", javaPackage.c_str());
|
||||||
|
fprintf(out, "\n");
|
||||||
|
fprintf(out, "import static java.nio.charset.StandardCharsets.UTF_8;\n");
|
||||||
|
fprintf(out, "\n");
|
||||||
|
fprintf(out, "import android.util.StatsLog;\n");
|
||||||
|
fprintf(out, "import android.os.SystemClock;\n");
|
||||||
|
fprintf(out, "\n");
|
||||||
|
fprintf(out, "\n");
|
||||||
|
fprintf(out, "/**\n");
|
||||||
|
fprintf(out, " * Utility class for logging statistics events.\n");
|
||||||
|
fprintf(out, " */\n");
|
||||||
|
fprintf(out, "public class %s {\n", javaClass.c_str());
|
||||||
|
|
||||||
|
write_java_q_logging_constants(out, " ");
|
||||||
|
|
||||||
|
write_java_atom_codes(out, atoms, moduleName);
|
||||||
|
|
||||||
|
write_java_enum_values(out, atoms, moduleName);
|
||||||
|
|
||||||
|
int errors = 0;
|
||||||
|
// Print write methods
|
||||||
|
fprintf(out, " // Write methods\n");
|
||||||
|
errors += write_java_methods_q_schema(out, atoms.signatures_to_modules, attributionDecl,
|
||||||
|
moduleName, " ");
|
||||||
|
errors += write_java_non_chained_methods(out, atoms.non_chained_signatures_to_modules,
|
||||||
|
moduleName);
|
||||||
|
if (supportWorkSource) {
|
||||||
|
errors += write_java_work_source_methods(out, atoms.signatures_to_modules, moduleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(out, "}\n");
|
||||||
|
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(STATS_SCHEMA_LEGACY)
|
#if defined(STATS_SCHEMA_LEGACY)
|
||||||
static void write_java_method(
|
static void write_java_method(
|
||||||
FILE* out,
|
FILE* out,
|
||||||
@@ -423,48 +467,6 @@ int write_stats_log_java_q(FILE* out, const Atoms& atoms, const AtomDecl &attrib
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_stats_log_java_q_for_module(FILE* out, const Atoms& atoms,
|
|
||||||
const AtomDecl &attributionDecl, const string& moduleName,
|
|
||||||
const string& javaClass, const string& javaPackage,
|
|
||||||
const bool supportWorkSource) {
|
|
||||||
// Print prelude
|
|
||||||
fprintf(out, "// This file is autogenerated\n");
|
|
||||||
fprintf(out, "\n");
|
|
||||||
fprintf(out, "package %s;\n", javaPackage.c_str());
|
|
||||||
fprintf(out, "\n");
|
|
||||||
fprintf(out, "import static java.nio.charset.StandardCharsets.UTF_8;\n");
|
|
||||||
fprintf(out, "\n");
|
|
||||||
fprintf(out, "import android.util.StatsLog;\n");
|
|
||||||
fprintf(out, "import android.os.SystemClock;\n");
|
|
||||||
fprintf(out, "\n");
|
|
||||||
fprintf(out, "\n");
|
|
||||||
fprintf(out, "/**\n");
|
|
||||||
fprintf(out, " * Utility class for logging statistics events.\n");
|
|
||||||
fprintf(out, " */\n");
|
|
||||||
fprintf(out, "public class %s {\n", javaClass.c_str());
|
|
||||||
|
|
||||||
write_java_q_logging_constants(out, " ");
|
|
||||||
|
|
||||||
write_java_atom_codes(out, atoms, moduleName);
|
|
||||||
|
|
||||||
write_java_enum_values(out, atoms, moduleName);
|
|
||||||
|
|
||||||
int errors = 0;
|
|
||||||
// Print write methods
|
|
||||||
fprintf(out, " // Write methods\n");
|
|
||||||
errors += write_java_methods_q_schema(out, atoms.signatures_to_modules, attributionDecl,
|
|
||||||
moduleName, " ");
|
|
||||||
errors += write_java_non_chained_methods(out, atoms.non_chained_signatures_to_modules,
|
|
||||||
moduleName);
|
|
||||||
if (supportWorkSource) {
|
|
||||||
errors += write_java_work_source_methods(out, atoms.signatures_to_modules, moduleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(out, "}\n");
|
|
||||||
|
|
||||||
return errors;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace stats_log_api_gen
|
} // namespace stats_log_api_gen
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ void write_java_helpers_for_q_schema_methods(
|
|||||||
const int requiredHelpers,
|
const int requiredHelpers,
|
||||||
const string& indent);
|
const string& indent);
|
||||||
|
|
||||||
#if defined(STATS_SCHEMA_LEGACY)
|
|
||||||
int write_stats_log_java_q(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl,
|
|
||||||
const bool supportWorkSource);
|
|
||||||
|
|
||||||
int write_stats_log_java_q_for_module(FILE* out, const Atoms& atoms,
|
int write_stats_log_java_q_for_module(FILE* out, const Atoms& atoms,
|
||||||
const AtomDecl &attributionDecl, const string& moduleName, const string& javaClass,
|
const AtomDecl &attributionDecl, const string& moduleName, const string& javaClass,
|
||||||
const string& javaPackage, const bool supportWorkSource);
|
const string& javaPackage, const bool supportWorkSource);
|
||||||
|
|
||||||
|
#if defined(STATS_SCHEMA_LEGACY)
|
||||||
|
int write_stats_log_java_q(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl,
|
||||||
|
const bool supportWorkSource);
|
||||||
#endif
|
#endif
|
||||||
} // namespace stats_log_api_gen
|
} // namespace stats_log_api_gen
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
@@ -511,8 +511,10 @@ print_usage()
|
|||||||
fprintf(stderr, " --javaClass CLASS the class name of the java class.\n");
|
fprintf(stderr, " --javaClass CLASS the class name of the java class.\n");
|
||||||
fprintf(stderr, " Optional for Java with module.\n");
|
fprintf(stderr, " Optional for Java with module.\n");
|
||||||
fprintf(stderr, " Default is \"StatsLogInternal\"\n");
|
fprintf(stderr, " Default is \"StatsLogInternal\"\n");
|
||||||
fprintf(stderr, " --supportQ Include support for Android Q.\n");
|
fprintf(stderr, " --supportQ Include runtime support for Android Q.\n");
|
||||||
fprintf(stderr, " --worksource Include support for logging WorkSource objects.\n");
|
fprintf(stderr, " --worksource Include support for logging WorkSource objects.\n");
|
||||||
|
fprintf(stderr, " --compileQ Include compile-time support for Android Q "
|
||||||
|
"(Java only).\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -536,6 +538,7 @@ run(int argc, char const*const* argv)
|
|||||||
string javaClass = DEFAULT_JAVA_CLASS;
|
string javaClass = DEFAULT_JAVA_CLASS;
|
||||||
bool supportQ = false;
|
bool supportQ = false;
|
||||||
bool supportWorkSource = false;
|
bool supportWorkSource = false;
|
||||||
|
bool compileQ = false;
|
||||||
|
|
||||||
int index = 1;
|
int index = 1;
|
||||||
while (index < argc) {
|
while (index < argc) {
|
||||||
@@ -630,6 +633,8 @@ run(int argc, char const*const* argv)
|
|||||||
supportQ = true;
|
supportQ = true;
|
||||||
} else if (0 == strcmp("--worksource", argv[index])) {
|
} else if (0 == strcmp("--worksource", argv[index])) {
|
||||||
supportWorkSource = true;
|
supportWorkSource = true;
|
||||||
|
} else if (0 == strcmp("--compileQ", argv[index])) {
|
||||||
|
compileQ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
@@ -645,12 +650,18 @@ run(int argc, char const*const* argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DEFAULT_MODULE_NAME == moduleName && supportQ) {
|
if (DEFAULT_MODULE_NAME == moduleName && (supportQ || compileQ)) {
|
||||||
// Support for Q schema is not needed for default module.
|
// Support for Q schema is not needed for default module.
|
||||||
fprintf(stderr, "%s cannot support Q schema\n", moduleName.c_str());
|
fprintf(stderr, "%s cannot support Q schema\n", moduleName.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (supportQ && compileQ) {
|
||||||
|
// Runtime Q support is redundant if compile-time Q support is required.
|
||||||
|
fprintf(stderr, "Cannot specify compileQ and supportQ simultaneously.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Collate the parameters
|
// Collate the parameters
|
||||||
Atoms atoms;
|
Atoms atoms;
|
||||||
int errorCount = collate_atoms(Atom::descriptor(), &atoms);
|
int errorCount = collate_atoms(Atom::descriptor(), &atoms);
|
||||||
@@ -748,9 +759,15 @@ run(int argc, char const*const* argv)
|
|||||||
javaClass = "StatsLogInternal";
|
javaClass = "StatsLogInternal";
|
||||||
javaPackage = "android.util";
|
javaPackage = "android.util";
|
||||||
}
|
}
|
||||||
errorCount = android::stats_log_api_gen::write_stats_log_java(
|
if (compileQ) {
|
||||||
out, atoms, attributionDecl, moduleName, javaClass, javaPackage, supportQ,
|
errorCount = android::stats_log_api_gen::write_stats_log_java_q_for_module(
|
||||||
supportWorkSource);
|
out, atoms, attributionDecl, moduleName, javaClass, javaPackage,
|
||||||
|
supportWorkSource);
|
||||||
|
} else {
|
||||||
|
errorCount = android::stats_log_api_gen::write_stats_log_java(
|
||||||
|
out, atoms, attributionDecl, moduleName, javaClass, javaPackage, supportQ,
|
||||||
|
supportWorkSource);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
|||||||
Reference in New Issue
Block a user