3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #ifndef __TIME_UTIL_H__
11 #define __TIME_UTIL_H__
13 #include <wireshark.h>
18 #endif /* __cplusplus */
20 /** Converts a broken down date representation, relative to UTC,
24 time_t mktime_utc(struct tm
*tm
);
26 /** Validate the values in a time_t.
27 * Currently checks tm_year, tm_mon, tm_mday, tm_hour, tm_min, and tm_sec;
28 * disregards tm_wday, tm_yday, and tm_isdst.
30 * @param tm The struct tm to validate.
33 bool tm_is_valid(struct tm
*tm
);
35 /** Fetch the process CPU time.
37 * Fetch the current process user and system CPU times, convert them to
38 * seconds, and store them in the provided parameters.
40 * @param user_time Seconds spent in user mode.
41 * @param sys_time Seconds spent in system (kernel) mode.
44 void get_resource_usage(double *user_time
, double *sys_time
);
46 /** Print the process CPU time followed by a log message.
48 * Print the current process user and system CPU times along with the times
49 * elapsed since the times were last reset.
51 * @param reset_delta Reset the delta times. This will typically be true when
52 * logging the first measurement and false thereafter.
53 * @param format Printf-style format string. Passed to g_string_vprintf.
54 * @param ... Parameters for the format string.
57 void log_resource_usage(bool reset_delta
, const char *format
, ...);
60 * Fetch the number of microseconds since midnight (0 hour), January 1, 1970.
63 uint64_t create_timestamp(void);
69 struct timespec
*ws_clock_get_realtime(struct timespec
*ts
);
72 struct tm
*ws_localtime_r(const time_t *timep
, struct tm
*result
);
75 struct tm
*ws_gmtime_r(const time_t *timep
, struct tm
*result
);
79 #endif /* __cplusplus */
81 #endif /* __TIME_UTIL_H__ */