Measure thread execution (in C, unix)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Measure thread execution (in C, unix)
# 1  
Old 03-23-2011
Measure thread execution (in C, unix)

Hi,

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 Smilie



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.

Last edited by jim mcnamara; 03-24-2011 at 12:50 PM.. Reason: duplicate topics merged
# 2  
Old 03-23-2011
I'm not quite sure I understand the question. Sorry. Smilie What's the difference between thread time and system time?
# 3  
Old 03-23-2011
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 :
Code:
void ReadWithWait_##Type (_C_ReadWithWait_##Type *C){ \
    _int Length_ = 0; \
    SYSTEM_TIME_TYPE entry; \
    SYSTEM_TIME_TYPE curr; \
    RETURN_CODE_TYPE retCode; \
    Dur waitDur = 0; \
 \
    GET_TIME(&entry, &retCode); \
    C->_O0_Validity_ = INVALID; \
\
    if (C->_M_init == true) \
    { \
        CREATE_SAMPLING_PORT(...)\
        (C->_O1_Message_) = *(C->_I3_InitMessage_); \
        C->_PrevMsg = *(C->_I3_InitMessage_); \
        C->_M_init = false; \
    } \
    while((waitDur <= (C->_I2_TimeOut_)) && ((C->_O0_Validity_) == INVALID)) \
    { \
        READ_SAMPLING_MESSAGE( ... ); \
        GET_TIME(&curr, &retCode); \
        waitDur = (Dur)(curr - entry); \
    } \
    if (waitDur > (C->_I2_TimeOut_)) \
    { \
        (C->_O0_Validity_) = INVALID; \
        (C->_O2_ReturnCode_)= (ReturnCode)TIMED_OUT; \
 printf("TIME OUT 2 : %d > %d\n",waitDur,(C->_I2_TimeOut_));\
    } \
    (...)
    C->_PrevMsg = (C->_O1_Message_); \
}

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.
# 4  
Old 03-23-2011
So, something to count CPU time the thread has spent running since last, but not count time the thread has spent suspended?
# 5  
Old 03-23-2011
Exactly.
another topic explains this problem better than me but doesn't give a solution : http://www.linuxforums.org/forum/pro...cess-time.html

Last edited by Tinkh; 03-23-2011 at 02:42 PM..
# 6  
Old 03-23-2011
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.
This User Gave Thanks to fpmurphy For This Post:
# 7  
Old 03-24-2011
Thank you for reply Smilie

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 :


Code:
void GET_TIME(SYSTEM_TIME_TYPE * SystemTime, RETURN_CODE_TYPE * ReturnCode)
{ 
* SystemTime = gethrtime(); *ReturnCode=NO_ERROR;
}

The new one :



Code:
void GET_TIME2(SYSTEM_TIME_TYPE * SystemTime, RETURN_CODE_TYPE * ReturnCode)
{
    ret = getrusage(RUSAGE_SELF, &usage);
    * SystemTime = (usage.ru_utime.tv_sec*1000000 + usage.ru_utime.tv_usec)*1000;
    *ReturnCode=NO_ERROR;
}

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... Smilie

Last edited by Tinkh; 03-24-2011 at 10:17 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python Thread Execution Issue . . .

Greetings! I set up a basic threading specimen which does the job:#!/usr/bin/python import threading class a(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): print("thread a finished") class b(threading.Thread): ... (0 Replies)
Discussion started by: LinQ
0 Replies

2. Solaris

How to measure IOPS?

Hi I have a system running solaris 10, and I intend to use a NetApp as its storage system. The application requires a throughput between the server and the storage 7000 disk IOPS (random IO sustained throughput with response time of 20 mili second and 16k block size). How to make sure that I... (6 Replies)
Discussion started by: fretagi
6 Replies

3. AIX

How to measure waiting time in run queue?

Hello guys, I am doing a performance analysis on one of our psystem. Most of time I am using Nmon analyser to do my trend graph. But I can't find any help with it. We are interesting in the time spend by tasks in Aix run queue. After looking the Aix documentation, I am pessimist to find any... (3 Replies)
Discussion started by: GiiGii
3 Replies

4. UNIX for Advanced & Expert Users

Implementing thread in UNIX

Hi For our load testing , we are using stubs (unix shell script) which send the response to the request coming from the application. As the unix stub is single threaded , it is responding to only one request whereas multiple requests come in parallely. I haven't worked on thread concepts... (5 Replies)
Discussion started by: jenanee
5 Replies

5. Solaris

What exactly does 'zpool iostat' measure?

hi there, i'd like to know what exactly zpool's iostat (-v) output measure, especially the writes. Is it only the writes to the ZIL or all writes (including commmits) to the disks? if anyone knows, that'd be helpful roti (1 Reply)
Discussion started by: rotunda
1 Replies

6. UNIX for Advanced & Expert Users

How to measure g++ performance?

I am working on an application with some rather interesting build performance issues. If we build on Solaris/Linux x86/AMD64 the build is rather fast, but it takes more than five times as long on our Solaris Sparc servers (single-threaded builds on the workstations, but multi-threaded on the... (5 Replies)
Discussion started by: Elric of Grans
5 Replies

7. Shell Programming and Scripting

Is there a command to measure compile speed?

Hello Ive written 2 programs in shell and I need to compare their speed (Compile) against one another. what methods could I go about doing this? Is there a feature in shell do accommodate this? (2 Replies)
Discussion started by: Darklight
2 Replies

8. Forum Support Area for Unregistered Users & Account Problems

How to post a new thread (Regarding Unix related doubts) in Unix Forums

How to post a new thread (Regarding Unix related doubts) in Unix Forums. I registered my id but I am unable to post my Questions to Forum. Thanks & Regards, indusri (1 Reply)
Discussion started by: indusri
1 Replies

9. UNIX for Dummies Questions & Answers

CPU load unit of measure?

If unix says my cpu load is 2.15 exactly what does that mean? --Jason (1 Reply)
Discussion started by: Mac J
1 Replies
Login or Register to Ask a Question