1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 # Write out processes data for C++. The processes are defined
6 # in a file provided as a command-line argument.
11 from mozparsers
.shared_telemetry_utils
import ParserError
, load_yaml_file
13 # The banner/text at the top of the generated file.
14 banner
= """/* This file is auto-generated from Telemetry build scripts,
15 see gen_process_data.py. */
19 #ifndef mozilla_TelemetryProcessData_h
20 #define mozilla_TelemetryProcessData_h
22 #include "mozilla/TelemetryProcessEnums.h"
29 } // namespace Telemetry
30 } // namespace mozilla
31 #endif // mozilla_TelemetryProcessData_h"""
34 def to_enum_label(name
):
35 return name
.title().replace("_", "")
38 def write_processes_data(processes
, output
):
40 print(line
, file=output
)
42 processes
= collections
.OrderedDict(processes
)
44 p("static GeckoProcessType ProcessIDToGeckoProcessType[%d] = {" % len(processes
))
45 for i
, (name
, value
) in enumerate(sorted(processes
.items())):
47 " /* %d: ProcessID::%s = */ %s,"
48 % (i
, to_enum_label(name
), value
["gecko_enum"])
52 p("#if defined(_MSC_VER) && !defined(__clang__)")
53 p("static const char* const ProcessIDToString[%d] = {" % len(processes
))
55 p("static constexpr const char* ProcessIDToString[%d] = {" % len(processes
))
57 for i
, (name
, value
) in enumerate(sorted(processes
.items())):
58 p(' /* %d: ProcessID::%s = */ "%s",' % (i
, to_enum_label(name
), name
))
62 def main(output
, *filenames
):
63 if len(filenames
) > 1:
64 raise Exception("We don't support loading from more than one file.")
67 processes
= load_yaml_file(filenames
[0])
69 # Write the process data file.
70 print(banner
, file=output
)
71 print(file_header
, file=output
)
72 write_processes_data(processes
, output
)
73 print(file_footer
, file=output
)
74 except ParserError
as ex
:
75 print("\nError generating processes data:\n" + str(ex
) + "\n")
79 if __name__
== "__main__":
80 main(sys
.stdout
, *sys
.argv
[1:])