Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Performance Counter

Altera_Forum
Honored Contributor II
1,099 Views

Hi. I have a problem, I am trying to use the "Performance Counter" for general time measurements. In the documentation there is an example how to use it, so I have used it as a base for my tests. However, I don't get the results I expected. For example, the line C-code "i=3;" takes 104 clock ticks to execute?!  

 

My code:  

# include <stdio.h> 

//For the performance counter # include "altera_avalon_performance_counter.h"# include "system.h" 

# define FUNCTION_SECTION_1 1# define FUNCTION_SECTION_2 2 

 

void function_1 (void)  

int i=0; 

//PERF_COUNTER_0_BASE is defined in system.h 

PERF_BEGIN (PERFORMANCE_COUNTER_0_BASE, FUNCTION_SECTION_1); 

 

i=3; //First Object to measure 

 

PERF_END (PERFORMANCE_COUNTER_0_BASE, FUNCTION_SECTION_1); 

}  

 

void function_2 (void)  

int i=0; 

//PERF_COUNTER_0_BASE is defined in system.h 

PERF_BEGIN (PERFORMANCE_COUNTER_0_BASE, FUNCTION_SECTION_2); 

i=3; //Objects to measure 

i=4; 

PERF_END (PERFORMANCE_COUNTER_0_BASE, FUNCTION_SECTION_2); 

}  

//Turn measurement on & off 

 

int main() 

// Reset the counters before every run 

PERF_RESET (PERFORMANCE_COUNTER_0_BASE); 

 

// Now our program starts in earnest. Begin measuring: 

 

PERF_START_MEASURING (PERFORMANCE_COUNTER_0_BASE); 

 

function_1(); 

function_2(); 

 

PERF_STOP_MEASURING (PERFORMANCE_COUNTER_0_BASE); 

 

//Print the result using "perf_print_formatted_report" 

perf_print_formatted_report  

(PERFORMANCE_COUNTER_0_BASE,  

ALT_CPU_FREQ, // defined in "system.h" 

2, // How many sections to print 

"function 1", 

"function 2"); // Display-name of section(s). 

 

return 0; 

 

 

From this code I get the following results:  

 

--Performance Counter Report-- 

Total Time: 1.64167E-05 seconds (788 clock-cycles) 

+---------------+-----+-----------+---------------+-----------+ 

| Section | % | Time (sec)| Time (clocks)|Occurrences| 

+---------------+-----+-----------+---------------+-----------+ 

|function 1 | 13.2| 0.00000| 104| 1| 

+---------------+-----+-----------+---------------+-----------+ 

|function 2 | 19.3| 0.00000| 152| 1| 

+---------------+-----+-----------+---------------+-----------+ 

 

What does it means? What have I done wrong? 

 

/David
0 Kudos
0 Replies
Reply