trace_processor: implement first android mem metric!
We fill the LMK field for now: more metrics will be filled in following
CLs.
Context: go/perfetto-metrics
Bug: 129747127
Change-Id: If3d7de375e16bbfd15a8b19bda05d3162ae30308
diff --git a/tools/gen_merged_sql_metrics b/tools/gen_merged_sql_metrics
new file mode 100755
index 0000000..6ad35ea
--- /dev/null
+++ b/tools/gen_merged_sql_metrics
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import argparse
+import os
+import sys
+
+# Converts the SQL metrics for trace processor into a C++ header with the SQL
+# as a string constant to allow trace processor to exectue the metrics.
+
+REPLACEMENT_HEADER = '''/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ *******************************************************************************
+ * AUTOGENERATED BY tools/gen_merged_sql_metrics - DO NOT EDIT
+ *******************************************************************************
+ */
+'''
+
+NAMESPACE_BEGIN = '''
+namespace perfetto {
+namespace trace_processor {
+namespace metrics {
+'''
+
+FILE_TO_SQL_STRUCT = '''
+struct FileToSql {
+ const char* filename;
+ const char* sql;
+};
+'''
+
+NAMESPACE_END = '''
+} // namespace metrics
+} // namespace trace_processor
+} // namsepace perfetto
+'''
+
+def filename_to_variable(filename):
+ return "k" + "".join([x.capitalize() for x in filename.split("_")])
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--cpp_out', required=True)
+ parser.add_argument('sql_files', action='append')
+ args = parser.parse_args()
+
+ # Extract the SQL output from each file.
+ escaped_sql_outputs = {}
+ for file_name in args.sql_files:
+ with open(file_name, 'r') as f:
+ basename = os.path.basename(file_name)
+
+ # Escape any quote characters.
+ escaped_sql_outputs[basename] = "".join(f.readlines())
+
+ with open(args.cpp_out, 'w+') as output:
+ output.write(REPLACEMENT_HEADER)
+ output.write(NAMESPACE_BEGIN)
+
+ # Create the C++ variable for each SQL file.
+ for name, sql in escaped_sql_outputs.items():
+ variable = filename_to_variable(os.path.splitext(name)[0])
+ output.write('\nconst char {}[] = R"gendelimiter(\n{})gendelimiter";\n'
+ .format(variable, sql))
+
+ output.write(FILE_TO_SQL_STRUCT)
+
+ # Create mapping of filename to variable name for each variable.
+ output.write("\nconst FileToSql kFileToSql[] = {")
+ for name in escaped_sql_outputs.keys():
+ variable = filename_to_variable(os.path.splitext(name)[0])
+ output.write('\n {{"{}", {}}},\n'.format(name, variable))
+ output.write("};\n")
+
+ output.write(NAMESPACE_END)
+
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main())