NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.
Profiling with DSS
Overview[edit]
Debug Server Scripting (DSS) provides several APIs to setup, collect and export profiling data.
Environment Setup[edit]
The environment setup needed is the same as for any DSS script.
Profile Setup[edit]
To setup profiling, a profile activity object for each desired activity needs to be created using the profileSetup.getActivity() API. A default activity to profile must be passed into the API. There are currently three default activities supported:
- Collect Code Coverage and Exclusive Profile Data - this will configure the profiler to collect code coverage data
- Profile all Functions for CPU Cycles - this will configure the profiler to collect CPU cycles (cycle.CPU) for all functions
- Profile all Functions for Total Cycles - this will configure the profiler to collect total cycles (cycle.total) for all functions
Note that the activities available can vary depending on the target. The list of supported activities for a particular target can be generated with the profileSetup.printActivityList() API.
To create and enable a profile activity object for profiling all functions for Total cycles:
<syntaxhighlight lang="javascript"> // retrieve an activity from the activity list based on the name myProfileActivity = debugSession.profileSetup.getActivity("Profile all Functions for Total Cycles");
// enable profiling for specified activity myProfileActivity.setStatus(true); </syntaxhighlight>
Once an activity object is created, it can be further configured to collect data for more events than just the default event. This can be done by getting a property object for the event to be profiled from the activity interface, and then enabling it. The following example will add the collection of L1P cache misses to the events being profiled:
<syntaxhighlight lang="javascript"> // get the propery object for L1P miss summary eventL1PMissSummary = myProfileActivity.getProperty("Events.L1P.miss.summary"); // enable collection L1P miss summary data eventL1PMissSummary.setBoolean(true); </syntaxhighlight>
If you wish to profile many events, you can create an array of the desired events and then use a 'for' loop for a cleaner implementation:
<syntaxhighlight lang="javascript"> // array of events to be profiled var evtNames = new Array("Events.L1D.hit.summary",
"Events.L1D.miss.summary", "Events.L1D.miss.conflict", "Events.L1D.miss.non_conflict", "Events.L1P.miss.summary", "Events.CPU.stall.mem.L1D", "Events.CPU.stall.mem.L1P", "Events.L1P.hit" );
// retrieve an activity from the activity list based on the name myProfileActivity= debugSession.profileSetup.getActivity("Profile all Functions for Total Cycles");
// enable profiling of all events in the array for (evtCount=0;evtCount<evtNames.length;evtCount++) {
event = myProfileActivity.getProperty(evtNames[evtCount]); event.setBoolean(true);
}
// enable profiling for specified activity myProfileActivity.setStatus(true); </syntaxhighlight>
Note that the available events to profile will vary depending on the device and if simulation or emulation is being used. The profile activity listProperties() API will generate the full list of all events supported for the current device.
Exporting Profiling Data[edit]
The exporting of the collected profiling data is done with DVT. The API doc for the DVT and examples can be found from: <INSTALL DIR>\ccsv4\scripting\docs\GettingStarted.htm
<syntaxhighlight lang="javascript"> dvtServer = dssScriptEnv.getServer("DVTServer.1"); </syntaxhighlight>
Then a profile analysis session must be opened to export the data. Pass in the debug session and the analysis provider. For the analysis provider, the options are:
- FunctionProfile - Export function profile data
- CoverageProfile - Export code coverage data
<syntaxhighlight lang="javascript"> // create a profile analysis session for function level profiling data collected var profileAnalysisSession = dvtServer.openProfileAnalysisSession(debugSession, "FunctionProfile"); </syntaxhighlight>
Before exporting any data, we need to make sure that all processing of profiling data is completed:
<syntaxhighlight lang="javascript"> profileAnalysisSession.waitUntilProfilingComplete(); </syntaxhighlight>
Next create a ProfileAnalysisExport object for all tables of collected profiling data
<syntaxhighlight lang="javascript"> var exports = profileAnalysisSession.exportData(); </syntaxhighlight>
We can then export the data. We can choose to export some or all of the data. The example below will use the API to export all the data for the first table into a *.csv file.
<syntaxhighlight lang="javascript"> exports[0].save("myProfilingData.csv"); </syntaxhighlight>
When exporting multiple tables (a table exists for each event enabled), a 'for' loop can be used:
<syntaxhighlight lang="javascript"> for (var e=0; e < exports.length; e++) {
exports[e].save(profileResultsFolder + "\\" + exports[e].getName() + ".csv");
} </syntaxhighlight>
Once done, don't forget to terminate the profile session and terminate the DVT Server:
<syntaxhighlight lang="javascript"> // close profile session profileAnalysisSession.terminate(); dvtServer.stop(); </syntaxhighlight>