CCS News

Advanced Code Profiling

Friday 13 November, 2020

The CCS C Compilers have a unique feature called Data Streaming, where an ICD unit is used as a TTL to USB translator. This can do printf()'s and getc()'s through the programming pins to the PC. Many of our users have been using data streaming not only for debugging, but for diagnostics, factory test and calibration.

Using this same interface, the compilers have the ability to inject code to send data out this port at specific points in the code. This information can include a timestamp, as well as, text data. This forms the infrastructure of the code profiling feature in the IDE.

For example, in the code one needs to only add these lines:

#use profile( ICD)
#profile functions

and the compiler inserts a code to transmit a tag at the start and end of every function in the program. When the profile tool is then run in the IDE, the following occurs:



The function tags inserted can optionally include the actual parameters and in the software to get a sequence of events as shown here:



The compiler also allows user defined areas of code to be timed. The user can specify a start and stop event and give the timer a name. A profileout() call is used with text starts with START, followed by something and then another profileout with STOP, and the same something will cause a timer to be created in the software. For example:

profileout("Start interpolation algorithm");
y2=((x2-x1)*(y3-y1))/(x3-x1)+y1;
profileout("Stop interpolation algorithm");


Notice the 4th line down:



profileout() can also be used to output the values of variables real-time. For example:
profileout("value=", value); // Sends a variable and a title for the variable
profileout( value ); // Sends a variable and the title is the variable name


An example screen showing the profileout() data:



The compiler can also be set up to insert tags at every branch in the program or between specific points to help with full path testing. If users own an IDE compiler and a CCS ICD-U64 or ICD-U80, this is a feature that can help users a great deal and is very easy to get going.


Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit https://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.