summaryrefslogtreecommitdiff
path: root/tools/stats_log_api_gen/Collation.h
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2020-08-31 21:21:38 -0700
committerXin Li <delphij@google.com>2020-08-31 21:21:38 -0700
commit628590d7ec80e10a3fc24b1c18a1afb55cca10a8 (patch)
tree4b1c3f52d86d7fb53afbe9e9438468588fa489f8 /tools/stats_log_api_gen/Collation.h
parentb11b8ec3aec8bb42f2c07e1c5ac7942da293baa8 (diff)
parentd2d3a20624d968199353ccf6ddbae6f3ac39c9af (diff)
Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709)
Bug: 166295507 Merged-In: I3d92a6de21a938f6b352ec26dc23420c0fe02b27 Change-Id: Ifdb80563ef042738778ebb8a7581a97c4e3d96e2
Diffstat (limited to 'tools/stats_log_api_gen/Collation.h')
-rw-r--r--tools/stats_log_api_gen/Collation.h156
1 files changed, 115 insertions, 41 deletions
diff --git a/tools/stats_log_api_gen/Collation.h b/tools/stats_log_api_gen/Collation.h
index 3efdd520d7f5..10b34ecf5f54 100644
--- a/tools/stats_log_api_gen/Collation.h
+++ b/tools/stats_log_api_gen/Collation.h
@@ -17,45 +17,110 @@
#ifndef ANDROID_STATS_LOG_API_GEN_COLLATION_H
#define ANDROID_STATS_LOG_API_GEN_COLLATION_H
-
#include <google/protobuf/descriptor.h>
+#include <stdint.h>
+#include <map>
#include <set>
#include <vector>
-#include <map>
+
+#include "frameworks/base/cmds/statsd/src/atom_field_options.pb.h"
namespace android {
namespace stats_log_api_gen {
+using google::protobuf::Descriptor;
+using google::protobuf::FieldDescriptor;
using std::map;
using std::set;
+using std::shared_ptr;
using std::string;
using std::vector;
-using google::protobuf::Descriptor;
-using google::protobuf::FieldDescriptor;
const int PULL_ATOM_START_ID = 10000;
+const int FIRST_UID_IN_CHAIN_ID = 0;
+
+enum AnnotationId : uint8_t {
+ ANNOTATION_ID_IS_UID = 1,
+ ANNOTATION_ID_TRUNCATE_TIMESTAMP = 2,
+ ANNOTATION_ID_PRIMARY_FIELD = 3,
+ ANNOTATION_ID_EXCLUSIVE_STATE = 4,
+ ANNOTATION_ID_PRIMARY_FIELD_FIRST_UID = 5,
+ ANNOTATION_ID_DEFAULT_STATE = 6,
+ ANNOTATION_ID_TRIGGER_STATE_RESET = 7,
+ ANNOTATION_ID_STATE_NESTED = 8,
+};
+
+const int ATOM_ID_FIELD_NUMBER = -1;
+
+const string DEFAULT_MODULE_NAME = "DEFAULT";
+
/**
* The types for atom parameters.
*/
typedef enum {
- JAVA_TYPE_UNKNOWN = 0,
-
- JAVA_TYPE_ATTRIBUTION_CHAIN = 1,
- JAVA_TYPE_BOOLEAN = 2,
- JAVA_TYPE_INT = 3,
- JAVA_TYPE_LONG = 4,
- JAVA_TYPE_FLOAT = 5,
- JAVA_TYPE_DOUBLE = 6,
- JAVA_TYPE_STRING = 7,
- JAVA_TYPE_ENUM = 8,
- JAVA_TYPE_KEY_VALUE_PAIR = 9,
-
- JAVA_TYPE_OBJECT = -1,
- JAVA_TYPE_BYTE_ARRAY = -2,
+ JAVA_TYPE_UNKNOWN = 0,
+
+ JAVA_TYPE_ATTRIBUTION_CHAIN = 1,
+ JAVA_TYPE_BOOLEAN = 2,
+ JAVA_TYPE_INT = 3,
+ JAVA_TYPE_LONG = 4,
+ JAVA_TYPE_FLOAT = 5,
+ JAVA_TYPE_DOUBLE = 6,
+ JAVA_TYPE_STRING = 7,
+ JAVA_TYPE_ENUM = 8,
+ JAVA_TYPE_KEY_VALUE_PAIR = 9,
+
+ JAVA_TYPE_OBJECT = -1,
+ JAVA_TYPE_BYTE_ARRAY = -2,
} java_type_t;
+enum AnnotationType {
+ ANNOTATION_TYPE_UNKNOWN = 0,
+ ANNOTATION_TYPE_INT = 1,
+ ANNOTATION_TYPE_BOOL = 2,
+};
+
+union AnnotationValue {
+ int intValue;
+ bool boolValue;
+
+ AnnotationValue(const int value) : intValue(value) {
+ }
+ AnnotationValue(const bool value) : boolValue(value) {
+ }
+};
+
+struct Annotation {
+ const AnnotationId annotationId;
+ const int atomId;
+ AnnotationType type;
+ AnnotationValue value;
+
+ inline Annotation(AnnotationId annotationId, int atomId, AnnotationType type,
+ AnnotationValue value)
+ : annotationId(annotationId), atomId(atomId), type(type), value(value) {
+ }
+ inline ~Annotation() {
+ }
+
+ inline bool operator<(const Annotation& that) const {
+ return atomId == that.atomId ? annotationId < that.annotationId : atomId < that.atomId;
+ }
+};
+
+struct SharedComparator {
+ template <typename T>
+ inline bool operator()(const shared_ptr<T>& lhs, const shared_ptr<T>& rhs) const {
+ return (*lhs) < (*rhs);
+ }
+};
+
+using AnnotationSet = set<shared_ptr<Annotation>, SharedComparator>;
+
+using FieldNumberToAnnotations = map<int, AnnotationSet>;
+
/**
* The name and type for an atom field.
*/
@@ -63,15 +128,20 @@ struct AtomField {
string name;
java_type_t javaType;
- // If the field is of type enum, the following map contains the list of enum values.
+ // If the field is of type enum, the following map contains the list of enum
+ // values.
map<int /* numeric value */, string /* value name */> enumValues;
- inline AtomField() :name(), javaType(JAVA_TYPE_UNKNOWN) {}
- inline AtomField(const AtomField& that) :name(that.name),
- javaType(that.javaType),
- enumValues(that.enumValues) {}
- inline AtomField(string n, java_type_t jt) :name(n), javaType(jt) {}
- inline ~AtomField() {}
+ inline AtomField() : name(), javaType(JAVA_TYPE_UNKNOWN) {
+ }
+ inline AtomField(const AtomField& that)
+ : name(that.name), javaType(that.javaType), enumValues(that.enumValues) {
+ }
+
+ inline AtomField(string n, java_type_t jt) : name(n), javaType(jt) {
+ }
+ inline ~AtomField() {
+ }
};
/**
@@ -84,18 +154,16 @@ struct AtomDecl {
string message;
vector<AtomField> fields;
+ FieldNumberToAnnotations fieldNumberToAnnotations;
+
vector<int> primaryFields;
int exclusiveField = 0;
+ int defaultState = INT_MAX;
+ int triggerStateReset = INT_MAX;
+ bool nested = true;
int uidField = 0;
- bool whitelisted = false;
-
- vector<int> binaryFields;
-
- bool hasModule = false;
- string moduleName;
-
AtomDecl();
AtomDecl(const AtomDecl& that);
AtomDecl(int code, const string& name, const string& message);
@@ -106,22 +174,28 @@ struct AtomDecl {
}
};
+using AtomDeclSet = set<shared_ptr<AtomDecl>, SharedComparator>;
+
+// Maps a field number to a set of atoms that have annotation(s) for their field with that field
+// number.
+using FieldNumberToAtomDeclSet = map<int, AtomDeclSet>;
+
+using SignatureInfoMap = map<vector<java_type_t>, FieldNumberToAtomDeclSet>;
+
struct Atoms {
- map<vector<java_type_t>, set<string>> signatures_to_modules;
- set<AtomDecl> decls;
- set<AtomDecl> non_chained_decls;
- map<vector<java_type_t>, set<string>> non_chained_signatures_to_modules;
- int maxPushedAtomId;
+ SignatureInfoMap signatureInfoMap;
+ AtomDeclSet decls;
+ AtomDeclSet non_chained_decls;
+ SignatureInfoMap nonChainedSignatureInfoMap;
};
/**
* Gather the information about the atoms. Returns the number of errors.
*/
-int collate_atoms(const Descriptor* descriptor, Atoms* atoms);
-int collate_atom(const Descriptor *atom, AtomDecl *atomDecl, vector<java_type_t> *signature);
+int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* atoms);
+int collate_atom(const Descriptor* atom, AtomDecl* atomDecl, vector<java_type_t>* signature);
} // namespace stats_log_api_gen
} // namespace android
-
-#endif // ANDROID_STATS_LOG_API_GEN_COLLATION_H
+#endif // ANDROID_STATS_LOG_API_GEN_COLLATION_H