i have a codec ported on QNX IDE. i need to calculate the machine cycles consumed by the codec. i got some info in the application profiler once i implemented post moterm profiling. But i just want something that i can obtain after each frame processed, apart from the entire test case/vector run. Normally incase of some dsp applications, i used something like
/* snap the time */
cycle1=ClockCycles( );
/* do something */
printf("poo\n");
/* snap the time again */
cycle2=ClockCycles( );
ncycles=cycle2-cycle1;
printf("%lld cycles elapsed \n", ncycles);
/* find out how many cycles per second */
cps = SYSPAGE_ENTRY(qtime)->cycles_per_sec;
printf( "This system has %lld cycles/sec.\n",cps );
sec=(float)ncycles/cps;
printf("The cycles in seconds is %f \n",sec);
return EXIT_SUCCESS;
thank for ur reply. actually i tried using clockcycles() earlier. but i was getting some inconsistent results. the values obtained are not similar everytime(for example im getting different value while debugging and altogether a different value while running ). is there anything to do with the target processor. because my target is dual core processor. or i need to introduce few more inbuilt APIs before while using clockcycles().
ClockCycles gives the current time, hence if the process is performaing at different speed for whatever reason you will get different value. Dual core can be nasty because ClockCycles gets a value from a counter that could be different in each core. If the process/thread migrate from core to core the result could be bogus.
since mine is a dual core processor, i got to know that i need to create a thread and it should be set with high priority and i need to put my API there and then i need to use clockcycles(). since i was new to RTOS and QNX. could u please suggest how to proceed
If you wish to use ClockCycles() on an SMP machine, you must use the following call to “lock” the thread to a single CPU:
ThreadCtl(_NTO_TCTL_RUNMASK, …)
that’s not 100% true, many intel processor have their counter synchronised. Even better on the later model I believe the counter frequency won’t be affected by power saving throttling of the processor frequency.
If you want to measure CPU time used by a thread you can do it manually with pidin ti. If you want to do it programatically get the source of pidin and check out how it does it.