Created
February 16, 2012 18:45
-
-
Save vi/1846970 to your computer and use it in GitHub Desktop.
A patch for [Yappi](http://code.google.com/p/yappi/) to measure CPU time instead of wall time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From vi0oss@gmail.com Thu Feb 16 21:43:27 2012 | |
Content-Type: text/plain; charset="us-ascii" | |
MIME-Version: 1.0 | |
Content-Transfer-Encoding: 7bit | |
Subject: [PATCH] Switch between measuring wall-clock time and CPU time with | |
YAPPI_CPUTIME environment variable | |
X-Mercurial-Node: f73ffd1c1bed66f0a95b39460788cc411ddc1003 | |
Message-Id: <f73ffd1c1bed66f0a95b.1329417806@localhost> | |
User-Agent: Mercurial-patchbomb/1.6.4 | |
Date: Thu, 16 Feb 2012 21:43:26 +0300 | |
From: Vitaly _Vi Shukela <vi0oss@gmail.com> | |
To: Vitaly _Vi Shukela <vi0oss@gmail.com> | |
# HG changeset patch | |
# User Vitaly "_Vi" Shukela <vi0oss@gmail.com> | |
# Date 1329417671 -10800 | |
# Node ID f73ffd1c1bed66f0a95b39460788cc411ddc1003 | |
# Parent 64e2ad93ee9bc5bdb27f213739f9191b3507718a | |
Switch between measuring wall-clock time and CPU time with YAPPI_CPUTIME environment variable | |
diff --git a/_ytiming.c b/_ytiming.c | |
--- a/_ytiming.c | |
+++ b/_ytiming.c | |
@@ -35,11 +35,25 @@ | |
#include <sys/times.h> | |
#endif | |
+int variant=0; | |
+ | |
long long | |
tickcount(void) | |
{ | |
struct timeval tv; | |
+ struct timespec tp; | |
+ | |
+ if (!variant) { | |
+ if(getenv("YAPPI_CPUTIME")) { | |
+ variant=2; | |
+ } else { | |
+ variant=1; | |
+ } | |
+ } | |
+ | |
long long rc; | |
+ if(variant==1) { | |
+ | |
#ifdef GETTIMEOFDAY_NO_TZ | |
gettimeofday(&tv); | |
#else | |
@@ -47,6 +61,16 @@ | |
#endif | |
rc = tv.tv_sec; | |
rc = rc * 1000000 + tv.tv_usec; | |
+ | |
+ } else | |
+ if (variant==2) { | |
+ | |
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp); | |
+ rc = tp.tv_sec; | |
+ rc = rc * 1000000 + 0.001*tp.tv_nsec; | |
+ | |
+ } | |
+ | |
return rc; | |
} | |
diff --git a/setup.py b/setup.py | |
--- a/setup.py | |
+++ b/setup.py | |
@@ -23,7 +23,7 @@ | |
#define_macros=[('YDEBUG', '1')], | |
#define_macros=[('DEBUG_CALL', '1')], | |
#define_macros=[('DEBUG_MEM', '1')], | |
- #extra_link_args = ["-lrt"] | |
+ extra_link_args = ["-lrt"] | |
#extra_compile_args = ["TEST"] | |
#extra_compile_args = ["-E"] | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment