Operating System - HP-UX
1752786 Members
6198 Online
108789 Solutions
New Discussion юеВ

Re: change CLK_TCK to get ms granularity ?

 
Laurent Laperrousaz
Regular Advisor

change CLK_TCK to get ms granularity ?

hello,
I started using times() function to get the CPU usage in programs and it's very helpful! but unfortunately the resolution of measure is 1/100 sec which does not help much for small pieces of code that I would like to optimize.

Is there a safe way to change CLK_TCK to a better value (1000 or 10000) without breaking everything?
Thanks

Laurent
6 REPLIES 6
Massimo Bianchi
Honored Contributor

Re: change CLK_TCK to get ms granularity ?

Hi,
looking at the man page:

"The times are in units of 1/CLK_TCK seconds,
where CLK_TCK is processor dependent The value of CLK_TCK can be
queried using the sysconf() function"


If CLK_TCK is cpu dependent, i don't think you can have luck...

HTH,
Massimo
Yogeeraj_1
Honored Contributor

Re: change CLK_TCK to get ms granularity ?

hi,

If you take a look at time.h header file, you will see:

#ifndef
#define CLOCKS_PER_SEC 1000000

I guess you can override the value with your own.

Worth a try.

regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Laurent Laperrousaz
Regular Advisor

Re: change CLK_TCK to get ms granularity ?

Thanks

Then if I can try, What do you suggest to do it?

I don't know where I should modify :
-should I change the include file? (risky!)
-should I move it to a my_include directory and compile with my_include?

What are your suggestion?
(I know I abuse of your time!)



Laurent
Massimo Bianchi
Honored Contributor

Re: change CLK_TCK to get ms granularity ?

Hi,
i wuold build a my_include, because that function could be used in many other programs, and i would not risk to compromise the stability of your system at the next kernel rebuild, in case you forget to put the original value back.

For example, i remember that the "top" program uses this value....

HTH,
Massimo
Yogeeraj_1
Honored Contributor

Re: change CLK_TCK to get ms granularity ?

hi laurent,

As Massimo mentioned above, it is much wiser to create your header files and include it because there might be other applications using this parameter too.

hope this helps!
regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Mike Stroyan
Honored Contributor

Re: change CLK_TCK to get ms granularity ?

It's not clear how you are using times() for optimization. If you want to measure how long it takes from start to stop of an activity you would be better served by gettimeofday, which reports time to the microsecond. It is only a wall-clock time, rather than distinct system time and user time. That should be good enough for most optimization activities.

You can also get good information about which functions are taking the most time using the prospect profiler available from http://www.hp.com/go/prospect .