I have a simulation program which creates two threads and I would like to know if I can measure the time of each individual thread. Threads communicate (I use pthread to manage them) and I want to measure communication time. I found a solution with clock_gettime and CLOCK_THREAD_CPUTIME_ID but nothing for Solaris OS.
French forums are insufficient, so I hope to find help here
Note: two threads on identical topic merged. Please do not post twice on the same topic - this kind of hodge-podge results from doing that.
I have two threads with WRITE/READ between them. The synchronisation works (I use pthread library) but I must calculate the execution of the READ function.
A part of my program :
Actually, GET_TIME uses gethrtime() => it's system time. But between my two GET_TIME, I'm not sure that only this function is executed. Processor switchs between thread 1 and 2 so waitdur is variable, that's why I want to know a solution to calculate only thread time.
Which version of Solaris are you using? I believe that CLOCK_THREAD_CPUTIME_ID was added in one of the later Solaris 10 updates. However, it might have only been added to the header to pass the UNIX03 VSTH test suite and not actually implemented.
Another possible way is to use getrusage(RUSAGE_LWP, ....) In Solaris 9 and above the default correspondence between threads and LWPs is 1x1, not MxN.
I already try to use CLOCK_THREAD_CPUTIME_ID but it does'nt work with Solaris 8.
I'm trying to use getrusage with RUSAGE_SELF (RUSAGE_LWP is not available in sys/resource.h, there's just RUSEGE_SELF and RUSAGE_CHILDREN). I hope it's a way to find solution ...
---------- Post updated at 11:37 AM ---------- Previous update was at 11:36 AM ----------
Bad news, I have a strange behaviour with getrusage.
My old function GET_TIME :
Between two GET_TIME, time is 200 000 ns approximately.
With GET_TIME2, this value can reach 10 000 000 or -7000 and it's equal to 0 majority... :wall:
That is two scripts, I hope, or what is the second #! for?
exit 0 is the free default implicitly, you just need it for other returns.
No, I meant put in the wrapper to collect any wandering output that occurs under cron. The () are only necessary if the are multiple commands on the line separated with ';'.
So, cron started the outer script OK, and is out of the picture.
In cron, you have not tty or environment. The closest interactive analog to cron is to run it under "rsh/rexec/remsh/ssh/ssh2 localhost <command>". You can even truss/tusc/strace in this mode: "rsh/rexec/remsh/ssh/ssh2 localhost truss -faelo /tmp/truss.tr <command>". You might need some environment (to test and to fix the problem). I have my ~/.profile set to support non-tty calls, by putting all the tty bits in one place, inside an "if [ `tty 2>&1` != 'not a tty' ] ; then". Then your <command> becomes ". $HOME/.profile;<command>" unless you do this inside "<command>".
Put logging in to ensure you get to that line, and test if you get past.
Anywhere you want to detect passing through, put:
date "+%Y-%m-%d %H:%M:%S ($$) $0 Line $LINENO" >>/tmp/croncheck.log
To emphasise what others have noticed, you cannot have two shebang lines in the same script. Only the shebang line on the very first line will be have any effect. The second shebang line is just a comment line but I don't think it matters.
./hash.pl robtest > $newfiles
This line is very dodgy for many reasons but to correct it we need to know what is in hash.pl and the full path to hash.pl .