2021-11-26 03:31:05 +00:00
|
|
|
/** @file
|
2014-04-24 19:56:31 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2014-04-24 19:56:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TIME_UTIL_H__
|
|
|
|
#define __TIME_UTIL_H__
|
|
|
|
|
2021-12-27 02:03:26 +00:00
|
|
|
#include <wireshark.h>
|
2021-03-16 11:33:00 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2016-07-11 22:40:03 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2021-01-08 09:18:39 +00:00
|
|
|
/** Converts a broken down date representation, relative to UTC,
|
|
|
|
* to a timestamp
|
|
|
|
*/
|
2014-04-24 19:56:31 +00:00
|
|
|
WS_DLL_PUBLIC
|
|
|
|
time_t mktime_utc(struct tm *tm);
|
|
|
|
|
2021-01-08 09:18:39 +00:00
|
|
|
/** Validate the values in a time_t.
|
|
|
|
* Currently checks tm_year, tm_mon, tm_mday, tm_hour, tm_min, and tm_sec;
|
|
|
|
* disregards tm_wday, tm_yday, and tm_isdst.
|
|
|
|
*
|
|
|
|
* @param tm The struct tm to validate.
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC
|
2023-09-22 20:42:49 +00:00
|
|
|
bool tm_is_valid(struct tm *tm);
|
2021-01-08 09:18:39 +00:00
|
|
|
|
2016-04-07 22:31:21 +00:00
|
|
|
/** Fetch the process CPU time.
|
|
|
|
*
|
|
|
|
* Fetch the current process user and system CPU times, convert them to
|
|
|
|
* seconds, and store them in the provided parameters.
|
|
|
|
*
|
2016-08-30 09:12:44 +00:00
|
|
|
* @param user_time Seconds spent in user mode.
|
|
|
|
* @param sys_time Seconds spent in system (kernel) mode.
|
2016-04-07 22:31:21 +00:00
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC
|
2016-08-30 09:12:44 +00:00
|
|
|
void get_resource_usage(double *user_time, double *sys_time);
|
2016-04-07 22:31:21 +00:00
|
|
|
|
2016-07-11 22:40:03 +00:00
|
|
|
/** Print the process CPU time followed by a log message.
|
|
|
|
*
|
|
|
|
* Print the current process user and system CPU times along with the times
|
|
|
|
* elapsed since the times were last reset.
|
|
|
|
*
|
2023-09-22 20:42:49 +00:00
|
|
|
* @param reset_delta Reset the delta times. This will typically be true when
|
|
|
|
* logging the first measurement and false thereafter.
|
2016-07-11 22:40:03 +00:00
|
|
|
* @param format Printf-style format string. Passed to g_string_vprintf.
|
|
|
|
* @param ... Parameters for the format string.
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC
|
2023-09-22 20:42:49 +00:00
|
|
|
void log_resource_usage(bool reset_delta, const char *format, ...);
|
2016-07-11 22:40:03 +00:00
|
|
|
|
2017-12-16 22:15:28 +00:00
|
|
|
/**
|
|
|
|
* Fetch the number of microseconds since midnight (0 hour), January 1, 1970.
|
|
|
|
*/
|
|
|
|
WS_DLL_PUBLIC
|
2023-09-22 20:42:49 +00:00
|
|
|
uint64_t create_timestamp(void);
|
2017-12-16 22:15:28 +00:00
|
|
|
|
2023-09-21 08:31:00 +00:00
|
|
|
WS_DLL_PUBLIC
|
|
|
|
void ws_tzset(void);
|
|
|
|
|
2021-12-15 13:06:57 +00:00
|
|
|
WS_DLL_PUBLIC
|
|
|
|
struct timespec *ws_clock_get_realtime(struct timespec *ts);
|
|
|
|
|
2023-09-03 00:35:31 +00:00
|
|
|
WS_DLL_PUBLIC
|
|
|
|
struct tm *ws_localtime_r(const time_t *timep, struct tm *result);
|
|
|
|
|
Add a routine to format an nstime as an ISO 8601-style date/time.
This replaces code in both absolute_time_string(), in capinfos, and
set_abs_ymd_time(), in libwireshark. Like absolute_time_string(), it
reports, in the formatted string, an error if the seconds value in the
nstime can't be converted to a struct tm (looking at *you*, Visual
Studio C library),
Have that routine handle all time precision values from 0 (seconds) to 9
(nanoseconds).
Add a ws_gmtime_r(), matching ws_localtime_r(), for use by that routine.
2023-09-11 09:21:59 +00:00
|
|
|
WS_DLL_PUBLIC
|
|
|
|
struct tm *ws_gmtime_r(const time_t *timep, struct tm *result);
|
|
|
|
|
2016-07-11 22:40:03 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2014-04-24 19:56:31 +00:00
|
|
|
#endif /* __TIME_UTIL_H__ */
|