Integrating Kanzi Monitor from source code

You can integrate Kanzi Monitor from source code into your Kanzi application project. The source code is located in the <KanziWorkspace>/Engine/plugins/monitor/src directory.

Build options

Kanzi Monitor exposes two CMake options that control how it is built into your application:

Option

Description

-DKANZI_LINK_KZMONITOR=ON

Required. Enables Kanzi Monitor in your project. When off, the integration block below is skipped and no Kanzi Monitor code is built.

-DKZMONITOR_PERFETTO_PRODUCER=ON

Optional. Links the vendored Perfetto producer SDK into libkzmonitor.so so the Trace Service’s perfetto-producer writer can stream events through the platform tracing daemon (Android traced / Linux perfetto) and into Android Performance Analyzer. Off by default when building from source. When off, ActiveWriters = perfetto-producer activates the writer but its registered callback is a no-op (the SDK isn’t linked). See Using the Profiling Trace service for the full perfetto-producer workflow.

Pass both flags on the same CMake command line. They can be added to either Windows or Android integrations.

Note

The pre-built Android binaries shipped under Engine/plugins/monitor/lib/android/ are built with -DKZMONITOR_PERFETTO_PRODUCER=ON. If you use Integrating Kanzi Monitor as a prebuilt library instead of building from source, ActiveWriters = perfetto-producer and PerfettoProducerCaptureSeconds work without any extra CMake flag — the producer SDK is already linked. You can verify this in logcat: Perfetto producer SDK initialized (system + in-process backends) appears at startup.

Integrating to Windows projects with CMake and Visual Studio

To integrate Kanzi Monitor from source to a Windows application project:

  1. In the top-level CMakeLists.txt, add the Kanzi Monitor detection, linking, and configuration block after the include(kanzi-common) call.

    Pass -DKANZI_LINK_KZMONITOR=ON when generating the CMake project to enable Kanzi Monitor. To also enable the Perfetto producer SDK (see Build options), add -DKZMONITOR_PERFETTO_PRODUCER=ON.

    Note

    Projects created with Kanzi 4.1.0 or newer already contain an equivalent if(KANZI_LINK_KZMONITOR) block in the application CMakeLists.txt generated by Kanzi Studio (see the application templates under <KanziWorkspace>/Templates). If your project was created with Kanzi 4.1.0, you do not need to add the block below — just pass -DKANZI_LINK_KZMONITOR=ON to enable Kanzi Monitor. Add the block manually only if your project predates 4.1.0, or if its generated CMakeLists.txt does not already contain it.

    Note

    This block ends with target_link_libraries(${PROJECT_NAME} ...), so place it after the add_executable(${PROJECT_NAME} ...) call that creates the target, not immediately after include(kanzi-common). Placing it before the target exists fails CMake configuration with “Cannot specify link libraries for target … which is not built by this project.”

    if(KANZI_LINK_KZMONITOR)
        set(PLUGIN_COMMON_SETUP cmake/common-setup.cmake)
        # KANZI_MONITOR_ROOT can be set explicitly: cmake -DKANZI_MONITOR_ROOT=<path>
        # If not set, auto-detection from known locations is attempted.
        if(NOT KANZI_MONITOR_ROOT)
            if(EXISTS ${PROJECT_SOURCE_DIR}/../../../Engine/plugins/monitor/${PLUGIN_COMMON_SETUP})
                set(KANZI_MONITOR_ROOT ${PROJECT_SOURCE_DIR}/../../../Engine/plugins/monitor)
            elseif(DEFINED ENV{KANZI_HOME} AND
                   EXISTS "$ENV{KANZI_HOME}/Engine/plugins/monitor/${PLUGIN_COMMON_SETUP}")
                set(KANZI_MONITOR_ROOT "$ENV{KANZI_HOME}/Engine/plugins/monitor")
            endif()
            if(NOT KANZI_MONITOR_ROOT)
                message(FATAL_ERROR
                    "Cannot find Monitor plugin root directory. "
                    "Pass -DKANZI_MONITOR_ROOT=<path> to CMake, set the KANZI_HOME "
                    "environment variable to your Kanzi workspace root, or install "
                    "the plugin under 'WORKSPACE/Engine/plugins'.")
            endif()
        endif()
        include(${KANZI_MONITOR_ROOT}/${PLUGIN_COMMON_SETUP})
        include(${KANZI_MONITOR_ROOT}/cmake/monitor-config.cmake)
        target_link_libraries(${PROJECT_NAME} ${KANZI_MONITOR_NAMESPACE}kzmonitor)
    endif()
    
  2. Inside the if(KANZI_LINK_KZMONITOR) block, add the Kanzi Monitor library as a subdirectory to build from source:

    add_subdirectory(${KANZI_MONITOR_ROOT} "${CMAKE_BINARY_DIR}/monitor")
    

    Note

    When Kanzi Monitor is added as a subdirectory, its example application is not built by default. To also build the example, pass -DBUILD_EXAMPLES=ON to CMake.

  3. Regenerate the project from the updated CMake files.

    For example, run the generate_cmake_vs2022_solution.bat script.

  4. Add the kzmonitor module to module names in either application.cfg or under the onConfigure function:

    application.cfg: ModuleNames = "kzmonitor"
    
    void onConfigure(ApplicationProperties& configuration) override
    {
        configuration.moduleNames = { "kzmonitor" };
    }
    
  5. (Optional) To enable rendering statistics and GPU object counts in Release and Profiling builds, enable the Kanzi graphics statistics layer. You can do this in either application.cfg:

    GraphicsStatisticEnabled = true
    

    or in onConfigure():

    configuration.graphicsStatisticsEnabled = true;
    

    In Debug builds, the graphics statistics layer is enabled by default. Without this setting, the Kanzi Monitor still reports FPS, frame time, resource counts, and memory usage, but per-frame rendering counters and GPU object counts remain zero.

    See GraphicsStatisticEnabled in the Kanzi application configuration reference.

  6. Make sure that the application has the necessary privileges to write files and open TCP sockets.

Integrating to Android projects with Gradle, CMake, and Android Studio

Note

On Android, you must link Kanzi Monitor with target_link_libraries at build time. Dynamic plugin loading via ModuleNames alone does not work on Android because RTTI type information is not shared across .so library boundaries, which prevents the Kanzi Engine from recognizing the plugin module.

To integrate Kanzi Monitor from source to an Android application project:

  1. In the kanzinative/build.gradle, enable Kanzi Monitor linking by passing -DKANZI_LINK_KZMONITOR=ON to the CMake configuration. To also enable the Perfetto producer SDK (see Build options), pass -DKZMONITOR_PERFETTO_PRODUCER=ON on the same line.

    Note

    In Gradle projects, enable Kanzi Monitor linking by passing -DKANZI_LINK_KZMONITOR=ON in the cmake { arguments } block of the kanzinative/build.gradle:

    cmake {
        // Enable to add Monitor plugin to the AAR.
        arguments "-DKANZI_LINK_KZMONITOR=ON"
    }
    
  2. In the CMakeLists.txt, add the Kanzi Monitor detection, linking, and configuration block after the include(kanzi-common) call:

    Note

    Projects created with Kanzi 4.1.0 or newer already contain an equivalent if(KANZI_LINK_KZMONITOR) block in the application CMakeLists.txt generated by Kanzi Studio (see the application templates under <KanziWorkspace>/Templates). If your project was created with Kanzi 4.1.0, you do not need to add the block below — just pass -DKANZI_LINK_KZMONITOR=ON to enable Kanzi Monitor. Add the block manually only if your project predates 4.1.0, or if its generated CMakeLists.txt does not already contain it.

    Note

    This block ends with target_link_libraries(${PROJECT_NAME} ...), so place it after the add_executable(${PROJECT_NAME} ...) call that creates the target, not immediately after include(kanzi-common). Placing it before the target exists fails CMake configuration with “Cannot specify link libraries for target … which is not built by this project.”

    if(KANZI_LINK_KZMONITOR)
        set(PLUGIN_COMMON_SETUP cmake/common-setup.cmake)
        # KANZI_MONITOR_ROOT can be set explicitly: cmake -DKANZI_MONITOR_ROOT=<path>
        # If not set, auto-detection from known locations is attempted.
        if(NOT KANZI_MONITOR_ROOT)
            if(EXISTS ${PROJECT_SOURCE_DIR}/../../../Engine/plugins/monitor/${PLUGIN_COMMON_SETUP})
                set(KANZI_MONITOR_ROOT ${PROJECT_SOURCE_DIR}/../../../Engine/plugins/monitor)
            elseif(DEFINED ENV{KANZI_HOME} AND
                   EXISTS "$ENV{KANZI_HOME}/Engine/plugins/monitor/${PLUGIN_COMMON_SETUP}")
                set(KANZI_MONITOR_ROOT "$ENV{KANZI_HOME}/Engine/plugins/monitor")
            endif()
            if(NOT KANZI_MONITOR_ROOT)
                message(FATAL_ERROR
                    "Cannot find Monitor plugin root directory. "
                    "Pass -DKANZI_MONITOR_ROOT=<path> to CMake, set the KANZI_HOME "
                    "environment variable to your Kanzi workspace root, or install "
                    "the plugin under 'WORKSPACE/Engine/plugins'.")
            endif()
        endif()
        include(${KANZI_MONITOR_ROOT}/${PLUGIN_COMMON_SETUP})
        include(${KANZI_MONITOR_ROOT}/cmake/monitor-config.cmake)
        target_link_libraries(${PROJECT_NAME} ${KANZI_MONITOR_NAMESPACE}kzmonitor)
    endif()
    
  3. Inside the if(KANZI_LINK_KZMONITOR) block, add the Kanzi Monitor library as a subdirectory to build from source:

    add_subdirectory(${KANZI_MONITOR_ROOT} "${CMAKE_BINARY_DIR}/monitor")
    
  4. If the Kanzi Monitor plugin is not added to the Kanzi Studio project, enable the plugin by adding it to the ModuleNames configuration option in application.cfg:

    ModuleNames = "kzmonitor"
    

    This is the recommended registration method for Android because it works with both Kanzi application frameworks:

    • appfw (Basic Application template) – The application has a C++ ExampleApplication subclass, so you can alternatively set configuration.moduleNames = { "kzmonitor" }; in onConfigure().

    • droidfw (Android Application template) – The application lifecycle is Java-driven and the C++ source is a stub, so application.cfg is the only viable registration path.

  5. (Optional) To enable rendering statistics and GPU object counts in Release and Profiling builds, enable the Kanzi graphics statistics layer. You can do this in application.cfg:

    GraphicsStatisticEnabled = true
    

    or in onConfigure() (appfw projects only):

    configuration.graphicsStatisticsEnabled = true;
    

    In Debug builds, the graphics statistics layer is enabled by default. Without this setting, the Kanzi Monitor still reports FPS, frame time, resource counts, and memory usage, but per-frame rendering counters and GPU object counts remain zero.

    See GraphicsStatisticEnabled in the Kanzi application configuration reference.

  6. Regenerate the project from the updated CMake files.

    For example, update your Android Studio and Gradle environment with the changes that you made to the CMake files.

  7. Make sure that the application has the necessary privileges to write files and open TCP sockets. See Setting permissions on Android.

See also

Integrating Kanzi Monitor as a prebuilt library

Getting started with Kanzi Monitor