Re: measure the execution time of each thread

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

On 04/24/2011 04:22 PM, moktar_bouain wrote:

You don't want to modify that code, just look at how it computes time
at a nanosecond scale.
Look at the function show_time_in_us() which uses time values
based on the function HAL_CLOCK_READ() that reads the system timer
(whatever that may be) and calculates time to the most accurate
value available in the system.  This is based on the raw clock
(often the hardware system clock) that's used to run the system
'tick' timer.  On most systems, this value is accurate to micro-seconds,
sometimes even nano-seconds.

Hi Gary,
I found the function gettimeofday() which returns the time  in  us.
I create a simple application with eCos containing 1 thread,i like to
measure the
execution time(us) of the thread.

void taska(cyg_addrword_t data)
struct timeval tv1,tv2;
long long diff;

gettimeofday (&tv1, NULL);

printf("TASKA \n");


gettimeofday (&tv2, NULL);
diff=(tv2.tv_sec-tv1.tv_sec) * 1000000 + (tv2.tv_usec-tv1.tv_usec);

printf("Time tv1 is %d\n",tv1.tv_usec);
printf("Time tv2 is %d\n",tv2.tv_usec);
printf("The diff is =%d usec\n",diff);

when i run this application in Tsim(simulator of Leon3):
Time tv1 is 286326803
Time tv2 is 286326801
The diff is -1 usec
Can you tell me what the fault in my program?

Looks like HAL_CLOCK_READ() isn't working on your hardware.
What's your target hardware?  Is it part of the public eCos tree?

Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world

Before posting, please read the FAQ:
and search the list archive:

[Linux Embedded]     [U-Boot V2]     [Linux Kernel]     [Linux MIPS]     [Linux ARM]     [Linux for the Blind]     [Linux Resources]     [Photo]     [Yosemite]     [ISDN Cause Codes]     [ECOS Home]

Add to Google Powered by Linux