diff --git a/CMakeLists.txt b/CMakeLists.txt index d41de947..745cfbc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ endif() set(GENERATOR_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}/${NAMESPACE}" CACHE PATH "Location to install the generators.") set(GENERATOR_MODULE_INSTALL_PATH "${GENERATOR_INSTALL_PATH}/Modules" CACHE INTERNAL "Location where to install the generator cmake modules") +option(JSON_GENERATOR_ENABLE_STATS "Globally enable JSON-RPC stats" OFF) option(PROXYSTUB_GENERATOR_ENABLE_SECURITY "Globally enable security checks in proxystubs" OFF) option(PROXYSTUB_GENERATOR_ENABLE_COHERENCY "Globally enable frame coherency checks in proxystubs" OFF) diff --git a/JsonGenerator/source/config.py b/JsonGenerator/source/config.py index ac659167..5da52718 100644 --- a/JsonGenerator/source/config.py +++ b/JsonGenerator/source/config.py @@ -101,6 +101,7 @@ def Parse(cmdline): global AUTO_PREFIX global DEFAULT_CASE_CONVENTION global IGNORE_SOURCE_CASE_CONVENTION + global STATS_FOR_NERDS argparser = argparse.ArgumentParser( description='Generate JSON C++ classes, stub code and API documentation from JSON definition files and C++ header files', @@ -154,6 +155,12 @@ def Parse(cmdline): action="store_true", default=False, help= "disable all warnings (default: warnings enabled)") + argparser.add_argument( + "--stats", + dest="stats", + action="store_true", + default=False, + help= "regiter version with extra stats (default: stats enabled)") json_group = argparser.add_argument_group("JSON parser arguments (optional)") json_group.add_argument("-i", @@ -389,6 +396,8 @@ def Parse(cmdline): if "force" in args.format: RPC_FORMAT_FORCED = True + STATS_FOR_NERDS = args.stats + NO_INCLUDES = args.no_includes NO_VERSIONING = args.no_versioning NO_PUSH_WARNING = args.no_push_warning diff --git a/JsonGenerator/source/rpc_emitter.py b/JsonGenerator/source/rpc_emitter.py index 6d80adf0..e5cc70b3 100644 --- a/JsonGenerator/source/rpc_emitter.py +++ b/JsonGenerator/source/rpc_emitter.py @@ -1696,12 +1696,15 @@ def _Invoke(method, conditional_invoke, sorted_vars, params, response, parent="" methods_and_properties = [x for x in root.properties if not isinstance(x, (JsonNotification))] methods = [x for x in methods_and_properties if not isinstance(x, (JsonNotification, JsonProperty))] + properties = [x for x in methods_and_properties if isinstance(x, (JsonProperty))] events = [x for x in root.properties if isinstance(x, JsonNotification)] async_events = [] async_methods = [] listener_events = [x for x in events if x.is_status_listener] auto_lookup_events = [x for x in events if "@lookup" in x.schema and x.schema["@lookup"].get("id") == "generate"] custom_lookup_events = [x for x in events if "@lookup" in x.schema and x.schema["@lookup"].get("id") == "custom"] + alt_methods = [x for x in methods if x.alternative] + alt_properties = [x for x in properties if x.alternative] alt_events = [x for x in events if x.alternative] lookup_methods = [x for x in methods_and_properties if x.schema.get("@lookup)")] @@ -1831,7 +1834,15 @@ def _Invoke(method, conditional_invoke, sorted_vars, params, response, parent="" emit.Line("ASSERT(%s.template Exists<%s>() == true);" % (names.module, trim(i["fullname"]))) emit.Line() - emit.Line("%s.PluginHost::JSONRPC::RegisterVersion(%s, Version::Major, Version::Minor, Version::Patch);" % (names.module, Tstring(names.namespace))) + version_info = [ Tstring(names.namespace), "Version::Major", "Version::Minor", "Version::Patch" ] + + if config.STATS_FOR_NERDS: + method_count = len(methods) + len(alt_methods) + property_count = len(properties) + len(alt_properties) + event_count = len(events) + len(alt_events) + version_info.extend([str(method_count), str(property_count), str(event_count)]) + + emit.Line("%s.PluginHost::JSONRPC::RegisterVersion(%s);" % (names.module, ", ".join(version_info))) if auto_lookup_interfaces: emit.Line() diff --git a/cmake/FindJsonGenerator.cmake.in b/cmake/FindJsonGenerator.cmake.in index 8f91ce4b..86022474 100644 --- a/cmake/FindJsonGenerator.cmake.in +++ b/cmake/FindJsonGenerator.cmake.in @@ -30,7 +30,7 @@ function(JsonGenerator) message(FATAL_ERROR "JsonGenerator path ${JSON_GENERATOR} invalid.") endif() - set(optionsArgs CODE STUBS DOCS LEGACY_ALT AUTO_PREFIX NO_INCLUDES NO_WARNINGS NO_STYLE_WARNINGS DUPLICATE_OBJ_WARNINGS COPY_CTOR NO_REF_NAMES NO_INTERFACES_SECTION VERBOSE FORCE_GENERATE EMIT_INTERFACE_PATH IGNORE_CASE_CONVENTION) + set(optionsArgs CODE STUBS DOCS LEGACY_ALT AUTO_PREFIX NO_INCLUDES NO_WARNINGS NO_STYLE_WARNINGS DUPLICATE_OBJ_WARNINGS COPY_CTOR NO_REF_NAMES NO_INTERFACES_SECTION VERBOSE FORCE_GENERATE EMIT_INTERFACE_PATH IGNORE_CASE_CONVENTION STATS) set(oneValueArgs OUTPUT CPP_OUTPUT INDENT DEF_STRING DEF_INT_SIZE PATH FORMAT CPP_INTERFACE_PATH JSON_INTERFACE_PATH FRAMEWORK_NAMESPACE CASE_CONVENTION) set(multiValueArgs INPUT IFDIR CPPIFDIR INCLUDE_PATH NAMESPACE) @@ -104,6 +104,10 @@ function(JsonGenerator) list(APPEND _execute_command "--emit-cpp-interface-path") endif() + if(Argument_STATS OR @JSON_GENERATOR_ENABLE_STATS@) + list(APPEND _execute_command "--stats") + endif() + if (Argument_PATH) list(APPEND _execute_command "-p" "${Argument_PATH}") endif()