1
#if !defined(lint) && !defined(DOS)
2
static char rcsid[] = "$Id: debugtime.c 165 2006-10-04 01:09:47Z jpf@u.washington.edu $";
6
* ========================================================================
7
* Copyright 2006 University of Washington
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* ========================================================================
21
#include "debugtime.h"
26
* Returns a pointer to static string for a timestamp.
28
* If timestamp is set .subseconds are added if available.
29
* If include_date is set the date is appended.
32
debug_time(int include_date, int include_subseconds)
40
struct _timeb timebuffer;
42
static char timestring[23];
49
if(gettimeofday(&tp, &tzp) == 0){
50
t = (time_t)tp.tv_sec;
52
tm_now = localtime(&t);
53
snprintf(datestr, sizeof(datestr), " %d/%d", tm_now->tm_mon+1, tm_now->tm_mday);
58
if(include_subseconds)
59
snprintf(subsecond, sizeof(subsecond), ".%06ld", tp.tv_usec);
63
snprintf(timestring, sizeof(timestring), "%.8s%.7s%.6s", ctime(&t)+11, subsecond, datestr);
65
#else /* !HAVE_GETTIMEOFDAY */
66
/* Should be _WINDOWS */
67
t = time((time_t *)0);
69
tm_now = localtime(&t);
70
snprintf(datestr, sizeof(datestr), " %d/%d", tm_now->tm_mon+1, tm_now->tm_mday);
75
if(include_subseconds){
77
snprintf(subsecond, sizeof(subsecond), ".%03ld", timebuffer.millitm);
82
snprintf(timestring, sizeof(timestring), "%.8s%.7s%.6s", ctime(&t)+11, subsecond, datestr);
83
#endif /* HAVE_GETTIMEOFDAY */
91
* Fills in the passed in structure with the current time.
97
get_time(TIMEVAL_S *our_time_val)
103
if(gettimeofday(&tp, &tzp) == 0){
104
our_time_val->sec = tp.tv_sec;
105
our_time_val->usec = tp.tv_usec;
115
* Returns the difference between the two values, in microseconds.
116
* Value returned is first - second.
119
time_diff(TIMEVAL_S *first, TIMEVAL_S *second)
121
return(1000000L*(first->sec - second->sec) + (first->usec - second->usec));