diff -ur valgrind-1.9.4/coregrind/vg_errcontext.c valgrind-1.9.4-e4/coregrind/vg_errcontext.c --- valgrind-1.9.4/coregrind/vg_errcontext.c Thu Feb 6 10:15:36 2003 +++ valgrind-1.9.4-e4/coregrind/vg_errcontext.c Tue Mar 18 21:33:52 2003 @@ -54,6 +54,8 @@ /* forwards ... */ static Supp* is_suppressible_error ( Error* err ); +/* get current time */ +static void vg_report_time_stamp (void); /*------------------------------------------------------------*/ /*--- Helper fns ---*/ @@ -98,6 +100,8 @@ VG_(pp_ExeContext) ( err->where ); } + if (VG_(clo_time_stamp) == True) + vg_report_time_stamp (); if (printCount) VG_(message)(Vg_UserMsg, "Observed %d times:", err->count ); if (err->tid > 1) @@ -762,6 +766,19 @@ } #undef STREQ + +static void vg_report_time_stamp (void) +{ + vg_time_t t; + struct vg_tm tm; + + t = VG_(time) (NULL); + tm = *VG_(localtime) (&t); + + VG_(message)(Vg_UserMsg, "Time: %d/%02d/%02d %02d:%02d:%02d", + tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec ); +} /*--------------------------------------------------------------------*/ /*--- end vg_errcontext.c ---*/ diff -ur valgrind-1.9.4/coregrind/vg_include.h valgrind-1.9.4-e4/coregrind/vg_include.h --- valgrind-1.9.4/coregrind/vg_include.h Tue Feb 25 08:21:53 2003 +++ valgrind-1.9.4-e4/coregrind/vg_include.h Tue Mar 18 21:45:48 2003 @@ -246,7 +246,9 @@ extern Bool VG_(clo_run_libc_freeres); /* Use the basic-block chaining optimisation? Default: YES */ extern Bool VG_(clo_chain_bb); - +/* report time of errors */ +extern Bool VG_(clo_time_stamp); +extern Int VG_(clo_time_zone); /* --------------------------------------------------------------------- Debugging and profiling stuff @@ -998,6 +1000,23 @@ /* --- Connecting over the network --- */ extern Int VG_(connect_via_socket)( UChar* str ); + +typedef Int vg_time_t; + +struct vg_tm { + int tm_sec; /* Seconds. [0-60] (1 leap second) */ + int tm_min; /* Minutes. [0-59] */ + int tm_hour; /* Hours. [0-23] */ + int tm_mday; /* Day. [1-31] */ + int tm_mon; /* Month. [0-11] */ + int tm_year; /* Year - 1900. */ + int tm_wday; /* Day of week. [0-6] */ + int tm_yday; /* Days in year.[0-365] */ + int tm_isdst; /* DST. [-1/0/1]*/ +}; + +extern vg_time_t VG_(time) (vg_time_t *timep); +extern struct vg_tm * VG_(localtime) (vg_time_t *timep); /* --------------------------------------------------------------------- Exports of vg_message.c diff -ur valgrind-1.9.4/coregrind/vg_main.c valgrind-1.9.4-e4/coregrind/vg_main.c --- valgrind-1.9.4/coregrind/vg_main.c Tue Feb 25 08:21:54 2003 +++ valgrind-1.9.4-e4/coregrind/vg_main.c Tue Mar 18 21:35:20 2003 @@ -487,6 +487,8 @@ Char* VG_(clo_weird_hacks) = NULL; Bool VG_(clo_run_libc_freeres) = True; Bool VG_(clo_chain_bb) = True; +Bool VG_(clo_time_stamp) = False; +Int VG_(clo_time_zone) = 0; /* This Bool is needed by wrappers in vg_clientmalloc.c to decide how @@ -567,6 +569,8 @@ " suppressions file \n" " --weird-hacks=hack1,hack2,... [no hacks selected]\n" " recognised hacks are: ioctl-VTIME truncate-writes lax-ioctls\n" +" --time-stamp=no|yes timestamp error reports? [no]\n" +" --time-zone=[+|-]mmm timezone minutes offset [0]\n" "\n" " %s skin user options:\n"; @@ -972,6 +976,22 @@ VG_(clo_backtrace_size) = 2; if (VG_(clo_backtrace_size) >= VG_DEEPEST_BACKTRACE) VG_(clo_backtrace_size) = VG_DEEPEST_BACKTRACE; + } + + else if (STREQ(argv[i], "--time-stamp=yes")) + VG_(clo_time_stamp) = True; + else if (STREQ(argv[i], "--time-stamp=no")) + VG_(clo_time_stamp) = False; + else if (STREQN(12, argv[i], "--time-zone=")) { + int sign = 1; + int off = 12; + + if ('-' == argv[i][off]) { + sign = -1; + ++off; + } else if ('+' == argv[i][off]) + ++off; + VG_(clo_time_zone) = (Int)(sign * VG_(atoll)(&argv[i][off])); } else if (VG_(needs).command_line_options) { diff -ur valgrind-1.9.4/coregrind/vg_mylibc.c valgrind-1.9.4-e4/coregrind/vg_mylibc.c --- valgrind-1.9.4/coregrind/vg_mylibc.c Tue Feb 25 08:53:48 2003 +++ valgrind-1.9.4-e4/coregrind/vg_mylibc.c Tue Mar 18 22:09:38 2003 @@ -1295,6 +1295,18 @@ } +ULong VG_(read_microsecond_timer) ( void ) +{ + ULong rdtsc_now; + vg_assert(rdtsc_calibration_state == 2); + rdtsc_now = do_rdtsc_insn(); + vg_assert(rdtsc_now > rdtsc_cal_end_raw); + rdtsc_now -= rdtsc_cal_end_raw; + rdtsc_now = rdtsc_now/(rdtsc_ticks_per_millisecond/1000); + return rdtsc_now; +} + + void VG_(start_rdtsc_calibration) ( void ) { Int res; @@ -1652,6 +1664,94 @@ return res; } +vg_time_t VG_(time) (vg_time_t *timep) +{ + Int res; + struct vki_timeval t_now; + vg_time_t t; + + res = vg_do_syscall2(__NR_gettimeofday, (int)&t_now, (int)NULL); + vg_assert(res == 0); + t = (vg_time_t)t_now.tv_sec; + + if (NULL != timep) + *timep = t; + return (t); +} + +/* This function is designed to work for unix dates (1970-2037) + * where a year is leap if !(year%4) + * + * Note that we use a static 'tm' as the return value, not good + * if multuthreaded +*/ + +#define STARTOFTIME 1970 +#define leapyear(year) ((year) % 4 == 0) + +#define FEBRUARY 1 +static Int month_days[12] = { + 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +}; + +struct vg_tm * VG_(localtime) (vg_time_t *timep) +{ + static struct vg_tm tm[1]; + Int day; + Int i; + + day = (Long)*timep; + + tm->tm_sec = day % 60; + day /= 60; + + day += VG_(clo_time_zone); /* in minutes */ + + tm->tm_min = day % 60; + day /= 60; + + tm->tm_hour = day % 24; + day /= 24; + +/* 1970/01/01 was a Wednesday +*/ + tm->tm_wday = (day + 4) % 7; + + tm->tm_year = day / 365; + day = day % 365; + +/* deduct one day for each leap year +*/ + day -= (tm->tm_year+1) / 4; + +/* need actual year for leapyear() +*/ + tm->tm_year += STARTOFTIME; + if (day < 0) { + --tm->tm_year; + day += 365 + leapyear (tm->tm_year); + } + + tm->tm_yday = day; + +/* tally days in months +*/ + if (leapyear (tm->tm_year)) + month_days[FEBRUARY] = 29; + for (i = 0; day >= month_days[i]; i++) + day -= month_days[i]; + month_days[FEBRUARY] = 28; + + tm->tm_mon = i; + tm->tm_mday = day + 1; + + vg_assert (tm->tm_year >= 1900); + tm->tm_year -= 1900; + + tm->tm_isdst = 0; + + return (tm); +} /*--------------------------------------------------------------------*/ /*--- end vg_mylibc.c ---*/