wireshark/wsutil/time_util.h

79 lines
2.0 KiB
C
Raw Permalink Normal View History

/** @file
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef __TIME_UTIL_H__
#define __TIME_UTIL_H__
#include <wireshark.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** Converts a broken down date representation, relative to UTC,
* to a timestamp
*/
WS_DLL_PUBLIC
time_t mktime_utc(struct tm *tm);
/** 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
gboolean tm_is_valid(struct tm *tm);
Add string function times to wmem_test. The system, GLib, and wmem string functions can perform differently, particularly on Windows. Start adding performance tests to wmem_test so that we can see the differences. With this change applied "wmem_test --verbose" prints out the following on a Windows 7 x64 VM here. wmem_test is linked against GLib 2.4.20. (MINPERF:g_printf_string_upper_bound (via g_snprintf) 1 string: u 327.602 ms s 0 .000 ms) (MINPERF:g_printf_string_upper_bound (via g_snprintf) 5 strings: u 1419.609 ms s 0.000 ms) (MINPERF:g_printf_string_upper_bound (via g_snprintf) mixed args: u 1606.810 ms s 0.000 ms) (MINPERF:_snprintf_s upper bound 1 string: u 124.801 ms s 0.000 ms) (MINPERF:_snprintf_s upper bound 5 strings: u 140.401 ms s 0.000 ms) (MINPERF:_snprintf_s upper bound mixed args: u 124.801 ms s 0.000 ms) (MINPERF:g_strdup_printf 2 strings: u 702.005 ms s 0.156 ms) (MINPERF:g_strconcat 2 strings: u 78.000 ms s 0.000 ms) (MINPERF:g_strdup_printf 5 strings: u 1419.609 ms s 0.156 ms) (MINPERF:g_strconcat 5 strings: u 93.601 ms s 0.156 ms) (MINPERF:wmem_strdup_printf 2 strings: u 343.202 ms s 0.312 ms) (MINPERF:wmem_strconcat 2 strings: u 93.601 ms s 0.468 ms) (MINPERF:wmem_strdup_printf 5 strings: u 327.602 ms s 8.268 ms) (MINPERF:wmem_strconcat 5 strings: u 62.400 ms s 3.432 ms) Change-Id: Id9b23918829db1719d141e7f830b9eba6245a25b Reviewed-on: https://code.wireshark.org/review/14857 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
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.
*
* @param user_time Seconds spent in user mode.
* @param sys_time Seconds spent in system (kernel) mode.
Add string function times to wmem_test. The system, GLib, and wmem string functions can perform differently, particularly on Windows. Start adding performance tests to wmem_test so that we can see the differences. With this change applied "wmem_test --verbose" prints out the following on a Windows 7 x64 VM here. wmem_test is linked against GLib 2.4.20. (MINPERF:g_printf_string_upper_bound (via g_snprintf) 1 string: u 327.602 ms s 0 .000 ms) (MINPERF:g_printf_string_upper_bound (via g_snprintf) 5 strings: u 1419.609 ms s 0.000 ms) (MINPERF:g_printf_string_upper_bound (via g_snprintf) mixed args: u 1606.810 ms s 0.000 ms) (MINPERF:_snprintf_s upper bound 1 string: u 124.801 ms s 0.000 ms) (MINPERF:_snprintf_s upper bound 5 strings: u 140.401 ms s 0.000 ms) (MINPERF:_snprintf_s upper bound mixed args: u 124.801 ms s 0.000 ms) (MINPERF:g_strdup_printf 2 strings: u 702.005 ms s 0.156 ms) (MINPERF:g_strconcat 2 strings: u 78.000 ms s 0.000 ms) (MINPERF:g_strdup_printf 5 strings: u 1419.609 ms s 0.156 ms) (MINPERF:g_strconcat 5 strings: u 93.601 ms s 0.156 ms) (MINPERF:wmem_strdup_printf 2 strings: u 343.202 ms s 0.312 ms) (MINPERF:wmem_strconcat 2 strings: u 93.601 ms s 0.468 ms) (MINPERF:wmem_strdup_printf 5 strings: u 327.602 ms s 8.268 ms) (MINPERF:wmem_strconcat 5 strings: u 62.400 ms s 3.432 ms) Change-Id: Id9b23918829db1719d141e7f830b9eba6245a25b Reviewed-on: https://code.wireshark.org/review/14857 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-04-07 22:31:21 +00:00
*/
WS_DLL_PUBLIC
void get_resource_usage(double *user_time, double *sys_time);
Add string function times to wmem_test. The system, GLib, and wmem string functions can perform differently, particularly on Windows. Start adding performance tests to wmem_test so that we can see the differences. With this change applied "wmem_test --verbose" prints out the following on a Windows 7 x64 VM here. wmem_test is linked against GLib 2.4.20. (MINPERF:g_printf_string_upper_bound (via g_snprintf) 1 string: u 327.602 ms s 0 .000 ms) (MINPERF:g_printf_string_upper_bound (via g_snprintf) 5 strings: u 1419.609 ms s 0.000 ms) (MINPERF:g_printf_string_upper_bound (via g_snprintf) mixed args: u 1606.810 ms s 0.000 ms) (MINPERF:_snprintf_s upper bound 1 string: u 124.801 ms s 0.000 ms) (MINPERF:_snprintf_s upper bound 5 strings: u 140.401 ms s 0.000 ms) (MINPERF:_snprintf_s upper bound mixed args: u 124.801 ms s 0.000 ms) (MINPERF:g_strdup_printf 2 strings: u 702.005 ms s 0.156 ms) (MINPERF:g_strconcat 2 strings: u 78.000 ms s 0.000 ms) (MINPERF:g_strdup_printf 5 strings: u 1419.609 ms s 0.156 ms) (MINPERF:g_strconcat 5 strings: u 93.601 ms s 0.156 ms) (MINPERF:wmem_strdup_printf 2 strings: u 343.202 ms s 0.312 ms) (MINPERF:wmem_strconcat 2 strings: u 93.601 ms s 0.468 ms) (MINPERF:wmem_strdup_printf 5 strings: u 327.602 ms s 8.268 ms) (MINPERF:wmem_strconcat 5 strings: u 62.400 ms s 3.432 ms) Change-Id: Id9b23918829db1719d141e7f830b9eba6245a25b Reviewed-on: https://code.wireshark.org/review/14857 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-04-07 22:31:21 +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.
*
* @param reset_delta Reset the delta times. This will typically be TRUE when
* logging the first measurement and FALSE thereafter.
* @param format Printf-style format string. Passed to g_string_vprintf.
* @param ... Parameters for the format string.
*/
WS_DLL_PUBLIC
void log_resource_usage(gboolean reset_delta, const char *format, ...);
/**
* Fetch the number of microseconds since midnight (0 hour), January 1, 1970.
*/
WS_DLL_PUBLIC
guint64 create_timestamp(void);
WS_DLL_PUBLIC
struct timespec *ws_clock_get_realtime(struct timespec *ts);
/*
* Portability wrapper around strptime().
*/
WS_DLL_PUBLIC
char *ws_strptime(const char *s, const char *format, struct tm *tm);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __TIME_UTIL_H__ */