Integrating Profiling Helper Tool code to an existing application¶
To use Profiling Helper Tool with an already existing Kanzi application that you created without one of the Profiling Helper Tool templates, you must manually integrate Profiling Helper Tool to your application.
Integrating Profiling Helper Tool code to an existing Visual Studio application¶
To integrate Profiling Helper Tool code to an existing Visual Studio application:
Copy the Profiling Helper Tool
<ProfilingHelperTool>/Application/src/plugindirectory to theApplication/srcdirectory of your Kanzi application.If you use a different directory for source files in your application, copy the plugin directory there.
Open the
CMakeLists.txtfile of your Kanzi application and add Profiling Helper Tool as a dependency:add_subdirectory(src/plugin) ... target_link_libraries(MyApplication Kanzi::kzui Kanzi::kzcoreui ProfilingHelper)
In the
application.cfgfile of your Kanzi application, enable all profilers.Enabling the profilers does not affect performance on Debug or Release builds, because profiling measurements are used only in the Profiling build.
# Enables all performance profiling categories. ProfilingCategoryFilter="*=on"
In your application class implementation, add the headers for Profiling Helper Tool.
#include "profilinghelper_collector.hpp" #include "profiling_helper.hpp"
In your application class implementation, add Profiling Helper Tool to the module list under
Application::onConfigurefunction.// Configures application. void onConfigure(ApplicationProperties& configuration) override { ... // Add the ProfilingHelper Module to load it. The ProfilingHelper module needs to be available as a DLL. configuration.moduleNames.push_back("ProfilingHelper"); ... }
(Optional) In your application class implementation, register startup profilers and set up FPS profiler in the
Application::registerMetadataOverridefunction.void registerMetadataOverride(ObjectFactory& factory) override { ... // Register the Application's startup profilers with the SampleCollector. profilinghelper::SampleCollector::setStartupProfilers(getStartupProfilerRegistry()); // Set up the Application's FPS profiler with the ProfilingHelper. profilinghelper::ProfilingHelper::setPerformanceInfoFPSProfiler(this); ... }
In Visual Studio, set the build configuration to Profiling.
This way you enable Kanzi Engine to collect profiling data at runtime.
Integrating Profiling Helper Tool code to an existing Kanzi Android framework application¶
To integrate Profiling Helper Tool source code to an existing Kanzi Android framework application:
Copy these files and directories to your Kanzi application:
<ProfilingHelperTool>/Application/configs/platforms/droidfw_gradle/profilinghelperplugindirectory to theApplication/configs/platforms/android_gradledirectory of your Kanzi application<ProfilingHelperTool>/Application/src/plugindirectory to theApplication/srcdirectory of your Kanzi application<ProfilingHelperTool>/Application/bin/profilinghelper.cfgto theApplication/bindirectory of your application
In the
Application/configs/platforms/android_gradle/settings.gradle, include theprofilinghelperpluginproject.include ':profilinghelperplugin'
In the
Application/configs/platforms/android_gradle/app/build.gradle, add theprofilinghelperpluginproject as a dependency.dependencies { implementation project(':profilinghelperplugin')
In the
application.cfgfile of your application, enable all profilers and add theProfilingHelperto the list of modules.Enabling the profilers does not affect application performance of the Debug or Release builds, because profiling measurements are performed only in the Profiling build.
# Enables all performance profiling categories. ProfilingCategoryFilter="*=on" ModuleNames = "ProfilingHelper"
To save the profiling data to the filesystem, in the
Application/configs/platforms/android_gradle/app/src/main/AndroidManifest.xml, enable the read and write permission.For Android SDK version 30 and newer:
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
For Android SDK version older than 30:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Create a pop-up when the application starts where you ask for file system access permission. Android requires users to confirm permission requests. This approach makes it easier to enable permissions than it is to do so manually in the application settings.
In the Java file that contains the main activity of your application, add the
requestReadWritePermissionsfunction.For Android SDK version 30 and newer:
void requestReadWritePermissions() { // Check and request permission to read and write to external storage. // Android SDK 30 and above requires MANAGE_EXTERNAL_STORAGE. if(SDK_INT >= Build.VERSION_CODES.R) { if (!Environment.isExternalStorageManager()) { Uri uri = Uri.parse("package:" + BuildConfig.APPLICATION_ID); Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, uri); startActivity(intent); } } }
For Android SDK version older than 30:
void requestReadWritePermissions() { // Check and request permission to read and write to external storage. // Android SDK 30 and above requires WRITE_EXTERNAL_STORAGE. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0); } } }
Call the
requestReadWritePermissionsfunction in theonCreatefunction of your activity.@Override protected void onCreate(Bundle icicle) { // Request the permissions. requestReadWritePermissions();
In Android Studio, set the build configuration to Profiling.
This way you enable Kanzi Engine to collect profiling data at runtime.
On Kanzi Android framework, Profiling Helper Tool by default outputs profiling results to the
sdcarddirectory.