From: Florian Krohm Date: Thu, 8 Jan 2015 14:43:29 +0000 (+0000) Subject: Add VG_(gettimeofday) such that callgrind can use it without X-Git-Tag: svn/VALGRIND_3_11_0~729 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d64b630f9a401640133145aa13eea9ee16b9009e;p=thirdparty%2Fvalgrind.git Add VG_(gettimeofday) such that callgrind can use it without a bloody hack. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14857 --- diff --git a/callgrind/main.c b/callgrind/main.c index 30a0cce17c..ad61d459a9 100644 --- a/callgrind/main.c +++ b/callgrind/main.c @@ -1706,10 +1706,6 @@ Bool CLG_(handle_client_request)(ThreadId tid, UWord *args, UWord *ret) /* struct timeval syscalltime[VG_N_THREADS]; */ #if CLG_MICROSYSTIME -#include -#include -extern Int VG_(do_syscall) ( UInt, ... ); - ULong syscalltime[VG_N_THREADS]; #else UInt syscalltime[VG_N_THREADS]; @@ -1722,7 +1718,7 @@ void CLG_(pre_syscalltime)(ThreadId tid, UInt syscallno, if (CLG_(clo).collect_systime) { #if CLG_MICROSYSTIME struct vki_timeval tv_now; - VG_(do_syscall)(__NR_gettimeofday, (UInt)&tv_now, (UInt)NULL); + VG_(gettimeofday)(&tv_now, NULL); syscalltime[tid] = tv_now.tv_sec * 1000000ULL + tv_now.tv_usec; #else syscalltime[tid] = VG_(read_millisecond_timer)(); @@ -1741,7 +1737,7 @@ void CLG_(post_syscalltime)(ThreadId tid, UInt syscallno, struct vki_timeval tv_now; ULong diff; - VG_(do_syscall)(__NR_gettimeofday, (UInt)&tv_now, (UInt)NULL); + VG_(gettimeofday)(&tv_now, NULL); diff = (tv_now.tv_sec * 1000000ULL + tv_now.tv_usec) - syscalltime[tid]; #else UInt diff = VG_(read_millisecond_timer)() - syscalltime[tid]; @@ -1750,7 +1746,8 @@ void CLG_(post_syscalltime)(ThreadId tid, UInt syscallno, /* offset o is for "SysCount", o+1 for "SysTime" */ o = fullOffset(EG_SYS); CLG_ASSERT(o>=0); - CLG_DEBUG(0," Time (Off %d) for Syscall %d: %ull\n", o, syscallno, diff); + CLG_DEBUG(0," Time (Off %d) for Syscall %u: %llu\n", o, syscallno, + (ULong)diff); CLG_(current_state).cost[o] ++; CLG_(current_state).cost[o+1] += diff; diff --git a/coregrind/m_libcproc.c b/coregrind/m_libcproc.c index a371ce310e..ec6b0c8b04 100644 --- a/coregrind/m_libcproc.c +++ b/coregrind/m_libcproc.c @@ -666,6 +666,20 @@ UInt VG_(read_millisecond_timer) ( void ) return (now - base) / 1000; } +Int VG_(gettimeofday)(struct vki_timeval *tv, struct vki_timezone *tz) +{ + SysRes res; + res = VG_(do_syscall2)(__NR_gettimeofday, (UWord)tv, (UWord)tz); + + if (! sr_isError(res)) return 0; + + /* Make sure, argument values are determinstic upon failure */ + if (tv) *tv = (struct vki_timeval){ .tv_sec = 0, .tv_usec = 0 }; + if (tz) *tz = (struct vki_timezone){ .tz_minuteswest = 0, .tz_dsttime = 0 }; + + return -1; +} + /* --------------------------------------------------------------------- atfork() diff --git a/include/pub_tool_libcproc.h b/include/pub_tool_libcproc.h index 585cbd7ad7..cbd159f133 100644 --- a/include/pub_tool_libcproc.h +++ b/include/pub_tool_libcproc.h @@ -88,6 +88,7 @@ extern Int VG_(getegid) ( void ); // (roughly; it gets initialised partway through Valgrind's initialisation // steps). extern UInt VG_(read_millisecond_timer) ( void ); +extern Int VG_(gettimeofday)(struct vki_timeval *tv, struct vki_timezone *tz); /* --------------------------------------------------------------------- atfork