summaryrefslogtreecommitdiff
path: root/tools/stats_log_api_gen/java_writer.cpp
diff options
context:
space:
mode:
authorMuhammad Qureshi <muhammadq@google.com>2020-03-24 13:53:48 -0700
committerMuhammad Qureshi <muhammadq@google.com>2020-03-27 02:23:38 -0700
commit23daf2656c4a1ce5871195fe51782093732b9187 (patch)
treeacd65d20947ba5f0cc3ceb3af81dd9bf0164dfc3 /tools/stats_log_api_gen/java_writer.cpp
parentc6c38632af73e28ad955e1b49101fadab12c9fc8 (diff)
Only send reset state annotation when needed
Only send reset state annotation when reset state occurs. Bug: 151776731 Test: m libstatslog Change-Id: I6f6b4d784d3741c0059085421565eba81db5527c
Diffstat (limited to 'tools/stats_log_api_gen/java_writer.cpp')
-rw-r--r--tools/stats_log_api_gen/java_writer.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/tools/stats_log_api_gen/java_writer.cpp b/tools/stats_log_api_gen/java_writer.cpp
index bcdabeb6745f..3eabb14e3fd4 100644
--- a/tools/stats_log_api_gen/java_writer.cpp
+++ b/tools/stats_log_api_gen/java_writer.cpp
@@ -50,6 +50,8 @@ static void write_annotations(FILE* out, int argIndex,
for (const shared_ptr<AtomDecl>& atomDecl : atomDeclSet) {
fprintf(out, " if (code == %d) {\n", atomDecl->code);
const AnnotationSet& annotations = atomDecl->fieldNumberToAnnotations.at(argIndex);
+ int resetState = -1;
+ int defaultState = -1;
for (const shared_ptr<Annotation>& annotation : annotations) {
// TODO(b/151786433): Write atom constant name instead of atom id literal.
switch (annotation->type) {
@@ -58,8 +60,14 @@ static void write_annotations(FILE* out, int argIndex,
case ANNOTATION_TYPE_INT:
// TODO(b/151786433): Write annotation constant name instead of
// annotation id literal.
- fprintf(out, " builder.addIntAnnotation((byte) %d, %d);\n",
- annotation->annotationId, annotation->value.intValue);
+ if (ANNOTATION_ID_RESET_STATE == annotation->annotationId) {
+ resetState = annotation->value.intValue;
+ } else if (ANNOTATION_ID_DEFAULT_STATE == annotation->annotationId) {
+ defaultState = annotation->value.intValue;
+ } else {
+ fprintf(out, " builder.addIntAnnotation((byte) %d, %d);\n",
+ annotation->annotationId, annotation->value.intValue);
+ }
break;
case ANNOTATION_TYPE_BOOL:
// TODO(b/151786433): Write annotation constant name instead of
@@ -72,6 +80,12 @@ static void write_annotations(FILE* out, int argIndex,
break;
}
}
+ if (defaultState != -1 && resetState != -1) {
+ fprintf(out, " if (arg%d == %d) {\n", argIndex, resetState);
+ fprintf(out, " builder.addIntAnnotation((byte) %d, %d);\n",
+ ANNOTATION_ID_RESET_STATE, defaultState);
+ fprintf(out, " }\n");
+ }
fprintf(out, " }\n");
}
}