Profile clock in CCS

From Texas Instruments Wiki
Jump to: navigation, search


This page describes how to set up and use the profile clock in CCS to count instruction cycles between two points in the code. Since the CCS Profiler has some limitations when profiling on hardware, the profile clock is one of the suggested alternate options.

Note: The below information apply to CCSv5 and greater. In CCSv4, the clock will be under menu Target instead of menu Run.

Enable the Profile Clock

In the debug perspective go to menu Run->Clock->Enable. This will add a clock icon and count to the status bar (on the very bottom of Code Composer Studio in the right hand corner). You may have to do this each time you restart the debugger.

Clock enable.png

Setup the Profile Clock

In the debug perspective go to menu Run->Clock->Setup. This will bring up the Clock Setup dialog.

Clock setup.png

  • Count: In the Clock Setup dialog box, you can specify the event you want to count in the drop-down list of the Count field. Depending on your device, Cycles may be the only option listed. However, some device drivers make use of the on-chip analysis capabilities and may allow profiling other events. The simulator will only display the Cycles parameter in the Count field, since it does not profile other events via its interface with a simulated target.
  • Reset Option: Use the Reset Option parameter to determine how the clock value is accumulated. If you select the Manual radio button, the clock variable accumulates instruction cycle counts without resetting the clock. If you select the Auto radio button, the clock variable is automatically reset (set to 0) before running or stepping the target processor. Therefore the clock only displays the cycles since the last run or step.

Reset the Profile Clock

Double-click on the clock value in the status bar to reset it to 0.

Measure cycles

To measure cycles between two lines of code using profile clock:

  1. Set breakpoints at the lines between which you want to measure cycle count
  2. Run to the first breakpoint
  3. Double click on the clock to reset its value or, if you use the Auto Reset Option, this step can be skipped.
  4. Run to the second breakpoint
  5. The clock will display the cycle count between those two points in the code

Convert Cycles to actual time

The profile clock displays the direct CPU cycle count, therefore its value must be multiplied by 1/CLK to convert it to seconds.

For example, if the target is running at 300MHz and the Profile clock cycle count for a routine is 1000, then the time consumed by the routine would be:

1000 * (1/300,000,000) = 3.3 μs

Considerations when measuring time

Some cores have a 1:1 relationship between the clock and the CPU cycles, therefore a simple instruction like NOP located in internal memory should just jump one unit in the counter. However, if the code is located in external memory the CPU will have to wait several cycles until the instruction is fetched to its internal pipeline (caused by waitstates and stalls), this translates to additional clock cycles measured by the Profile clock.

Similarly, certain instructions require additional CPU cycles to complete their execution if they access memory (MOV, PUSH/POP, etc.), jump to other parts of the code (B, JNE, etc.) or do not execute at all (conditional instructions in the C6000 ISA, for example).

For the instructions that access memory, keep in mind that other peripherals (DMA, HPI) or cores (in case of SoC devices) may be accessing the same region at the same time, which will cause a bus contention and make the CPU wait until it is allowed to fetch the data/instruction.

At last, if the software under evaluation contains interrupt requests, keep in mind that the cycle count may increase significantly if an interrupt is serviced in the middle of the region under evaluation.