<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Profiling Code Using clock_gettime</title>
	<atom:link href="http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/</link>
	<description>Keeping track of what I do</description>
	<lastBuildDate>Tue, 07 Feb 2012 23:33:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: jg4545</title>
		<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/comment-page-1/#comment-133971</link>
		<dc:creator>jg4545</dc:creator>
		<pubDate>Sun, 13 Nov 2011 21:08:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/#comment-133971</guid>
		<description>Hi,
Like Chandim I tried the code but the second count is not incrementing even if I use sleep(3).
Can anyone help please?
The program works fine if I use CLOCK_MONOTONIC.

Thanks.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Like Chandim I tried the code but the second count is not incrementing even if I use sleep(3).<br />
Can anyone help please?<br />
The program works fine if I use CLOCK_MONOTONIC.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: newbee</title>
		<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/comment-page-1/#comment-118419</link>
		<dc:creator>newbee</dc:creator>
		<pubDate>Mon, 03 Oct 2011 15:53:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/#comment-118419</guid>
		<description>hi again, 
After research, I found that iosream compile on g++, 
but new problem came.

I got error look like below :

&#039;timespec&#039; does not name of a type
in function &#039;int main()&#039;;
timespec,CLOCK_PROCESS_CPUTIME_ID&#039;, time1, clock_gettime, time2, diff was not declare on this scope

thanks in advance.</description>
		<content:encoded><![CDATA[<p>hi again,<br />
After research, I found that iosream compile on g++,<br />
but new problem came.</p>
<p>I got error look like below :</p>
<p>&#8216;timespec&#8217; does not name of a type<br />
in function &#8216;int main()&#8217;;<br />
timespec,CLOCK_PROCESS_CPUTIME_ID&#8217;, time1, clock_gettime, time2, diff was not declare on this scope</p>
<p>thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: newbee</title>
		<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/comment-page-1/#comment-118368</link>
		<dc:creator>newbee</dc:creator>
		<pubDate>Mon, 03 Oct 2011 13:11:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/#comment-118368</guid>
		<description>hi, 
I&#039;m very new in c, 
while try to understand you explanation, I got this

fatal error: iostream: No such file or directory

I&#039;m use mingw and codeblock to run you example, 
would you like to explain to me what wrong ?

thanks in advance.</description>
		<content:encoded><![CDATA[<p>hi,<br />
I&#8217;m very new in c,<br />
while try to understand you explanation, I got this</p>
<p>fatal error: iostream: No such file or directory</p>
<p>I&#8217;m use mingw and codeblock to run you example,<br />
would you like to explain to me what wrong ?</p>
<p>thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/comment-page-1/#comment-101869</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Sat, 20 Aug 2011 01:21:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/#comment-101869</guid>
		<description>Hi,

I am trying to use your code with gcc. I did add -lrt in the command line, however it doesnt seem like its recognizing timespec structure. As a result its erroring out. Any clue? Also, where can I find my time.h and sys/time.h files? I&#039;m running on my company server.

thanks
-M.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I am trying to use your code with gcc. I did add -lrt in the command line, however it doesnt seem like its recognizing timespec structure. As a result its erroring out. Any clue? Also, where can I find my time.h and sys/time.h files? I&#8217;m running on my company server.</p>
<p>thanks<br />
-M.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JRG</title>
		<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/comment-page-1/#comment-94381</link>
		<dc:creator>JRG</dc:creator>
		<pubDate>Sat, 30 Jul 2011 21:06:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/#comment-94381</guid>
		<description>Jomat, your version contains needless sophistries and your sample as written will leak memory.  Your code demonstrates very poor programming practice by forcing memory to be freed at a different level from which it was allocated.

One assumes you are attempting to optimize Mr. Rutenberg&#039;s original code.  Your attempt is both unnecessary and ineffective.  gcc has automatically optimized out the temporaries in both the parameters and the return value for many years now.  Your modifications are not only unnecessary, but they failed to achieve your aim, since the malloc() call consumes many more cycles than your conversion to pointers saves.  Mr. Rutenberg&#039;s code is better than yours.</description>
		<content:encoded><![CDATA[<p>Jomat, your version contains needless sophistries and your sample as written will leak memory.  Your code demonstrates very poor programming practice by forcing memory to be freed at a different level from which it was allocated.</p>
<p>One assumes you are attempting to optimize Mr. Rutenberg&#8217;s original code.  Your attempt is both unnecessary and ineffective.  gcc has automatically optimized out the temporaries in both the parameters and the return value for many years now.  Your modifications are not only unnecessary, but they failed to achieve your aim, since the malloc() call consumes many more cycles than your conversion to pointers saves.  Mr. Rutenberg&#8217;s code is better than yours.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chandim</title>
		<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/comment-page-1/#comment-67414</link>
		<dc:creator>Chandim</dc:creator>
		<pubDate>Tue, 15 Mar 2011 07:02:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/#comment-67414</guid>
		<description>Guy,

Your example given for the clock_gettime(CLOCK_PROCESS_CPUTIME_ID) is not working when the sec count is increased. Is is something with the function call. I always get the sec count as 0 even I put a sleep between the start and end of clock_getttime functions.
Can you explain this?

Thanks in advance.</description>
		<content:encoded><![CDATA[<p>Guy,</p>
<p>Your example given for the clock_gettime(CLOCK_PROCESS_CPUTIME_ID) is not working when the sec count is increased. Is is something with the function call. I always get the sec count as 0 even I put a sleep between the start and end of clock_getttime functions.<br />
Can you explain this?</p>
<p>Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jomat</title>
		<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/comment-page-1/#comment-62864</link>
		<dc:creator>Jomat</dc:creator>
		<pubDate>Fri, 11 Feb 2011 02:20:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/#comment-62864</guid>
		<description>If you are using Linux (Eg Ubuntu) and programming in C (GCC Compiler) you need to perform the following changes:

static struct timespec*
clock_diff(struct timespec *start, struct timespec *end) {
	struct timespec *diff;

	if(!(diff = malloc(sizeof(struct timespec)))) {
		return NULL;
	} else if((end-&gt;tv_nsec - start-&gt;tv_nsec) tv_sec = end-&gt;tv_sec - start-&gt;tv_sec - 1;
		diff-&gt;tv_nsec = 1000000000 + end-&gt;tv_nsec - start-&gt;tv_nsec;
	} else {
		diff-&gt;tv_sec = end-&gt;tv_sec - start-&gt;tv_sec;
		diff-&gt;tv_nsec = end-&gt;tv_nsec - start-&gt;tv_nsec;
	}
	return diff;
}

// Where you want to use it
struct timespec start, stop;

// Start Counter
if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &amp;start) &lt; 0) {
		goto return_failed;
}

// Put here whatever you want to test here

// Where you want to stop
if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &amp;stop) diff = clock_diff(&amp;start, &amp;stop))) {
		goto return_failed;
	}

return_failed:
// Free whatever you need to free in case it crashes...
		return NULL;</description>
		<content:encoded><![CDATA[<p>If you are using Linux (Eg Ubuntu) and programming in C (GCC Compiler) you need to perform the following changes:</p>
<p>static struct timespec*<br />
clock_diff(struct timespec *start, struct timespec *end) {<br />
	struct timespec *diff;</p>
<p>	if(!(diff = malloc(sizeof(struct timespec)))) {<br />
		return NULL;<br />
	} else if((end-&gt;tv_nsec &#8211; start-&gt;tv_nsec) tv_sec = end-&gt;tv_sec &#8211; start-&gt;tv_sec &#8211; 1;<br />
		diff-&gt;tv_nsec = 1000000000 + end-&gt;tv_nsec &#8211; start-&gt;tv_nsec;<br />
	} else {<br />
		diff-&gt;tv_sec = end-&gt;tv_sec &#8211; start-&gt;tv_sec;<br />
		diff-&gt;tv_nsec = end-&gt;tv_nsec &#8211; start-&gt;tv_nsec;<br />
	}<br />
	return diff;<br />
}</p>
<p>// Where you want to use it<br />
struct timespec start, stop;</p>
<p>// Start Counter<br />
if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &amp;start) &lt; 0) {<br />
		goto return_failed;<br />
}</p>
<p>// Put here whatever you want to test here</p>
<p>// Where you want to stop<br />
if(clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &amp;stop) diff = clock_diff(&amp;start, &amp;stop))) {<br />
		goto return_failed;<br />
	}</p>
<p>return_failed:<br />
// Free whatever you need to free in case it crashes&#8230;<br />
		return NULL;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guy</title>
		<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/comment-page-1/#comment-55091</link>
		<dc:creator>Guy</dc:creator>
		<pubDate>Thu, 23 Dec 2010 20:26:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/#comment-55091</guid>
		<description>It is possible. However, it&#039;s very unlikely to happen to you. The exact time it will happen depends on the clock you choose. For the CLOCK_REALTIME you should expect it to happen in 2038, and for the other two clocks, CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID, it&#039;s even less likely, as it will take 138 years.</description>
		<content:encoded><![CDATA[<p>It is possible. However, it&#8217;s very unlikely to happen to you. The exact time it will happen depends on the clock you choose. For the CLOCK_REALTIME you should expect it to happen in 2038, and for the other two clocks, CLOCK_PROCESS_CPUTIME_ID and CLOCK_THREAD_CPUTIME_ID, it&#8217;s even less likely, as it will take 138 years.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Data</title>
		<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/comment-page-1/#comment-54364</link>
		<dc:creator>Data</dc:creator>
		<pubDate>Mon, 20 Dec 2010 11:06:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/#comment-54364</guid>
		<description>tv_sec might be a 32 bit field, is it possible that this field will overflow? (i.e. reach its largest value and reset?) Shouldn&#039;t you take this into consideration in your &quot;diff&quot; function?</description>
		<content:encoded><![CDATA[<p>tv_sec might be a 32 bit field, is it possible that this field will overflow? (i.e. reach its largest value and reset?) Shouldn&#8217;t you take this into consideration in your &#8220;diff&#8221; function?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Albert</title>
		<link>http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/comment-page-1/#comment-53681</link>
		<dc:creator>Albert</dc:creator>
		<pubDate>Wed, 15 Dec 2010 15:59:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/#comment-53681</guid>
		<description>Hi, it seems like CLOCK_PROCESS_CPUTIME_ID timer summarizes times spent by each thread. So that I can compute the
scalability = time(CLOCK_PROCESS_CPUTIME_ID)/
              time(CLOCK_THREAD_CPUTIME_ID).
E.g.:
clock_gettime(CLOCK_PROCESS_CPUTIME_ID ...);
clock_gettime(CLOCK_THREAD_CPUTIME_ID ...);
#pragma omp parallel
{
// do mt-job here
}
clock_gettime(CLOCK_PROCESS_CPUTIME_ID ...);
clock_gettime(CLOCK_THREAD_CPUTIME_ID ...);

Is that a right conclusion?
At least on my Fedora13-64 I guess it is true.</description>
		<content:encoded><![CDATA[<p>Hi, it seems like CLOCK_PROCESS_CPUTIME_ID timer summarizes times spent by each thread. So that I can compute the<br />
scalability = time(CLOCK_PROCESS_CPUTIME_ID)/<br />
              time(CLOCK_THREAD_CPUTIME_ID).<br />
E.g.:<br />
clock_gettime(CLOCK_PROCESS_CPUTIME_ID &#8230;);<br />
clock_gettime(CLOCK_THREAD_CPUTIME_ID &#8230;);<br />
#pragma omp parallel<br />
{<br />
// do mt-job here<br />
}<br />
clock_gettime(CLOCK_PROCESS_CPUTIME_ID &#8230;);<br />
clock_gettime(CLOCK_THREAD_CPUTIME_ID &#8230;);</p>
<p>Is that a right conclusion?<br />
At least on my Fedora13-64 I guess it is true.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.240 seconds -->
<!-- Cached page served by WP-Cache -->

