diff options
author | rbuj <[email protected]> | 2020-02-03 20:21:33 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2020-02-17 13:17:24 +0100 |
commit | a50443572b52ace61f442a121d0ecc386c853173 (patch) | |
tree | 617242d3b55a76b09fc2a94a9afb7faa10b59ed4 /src | |
parent | 3a223d2f65da06859a6fd1d9e80fa923cfe66d40 (diff) | |
download | mate-system-monitor-a50443572b52ace61f442a121d0ecc386c853173.tar.bz2 mate-system-monitor-a50443572b52ace61f442a121d0ecc386c853173.tar.xz |
Remove GTimeVal deprecation warning for GLib 2.61.2+
Diffstat (limited to 'src')
-rw-r--r-- | src/load-graph.cpp | 13 | ||||
-rw-r--r-- | src/load-graph.h | 4 | ||||
-rw-r--r-- | src/util.cpp | 23 |
3 files changed, 38 insertions, 2 deletions
diff --git a/src/load-graph.cpp b/src/load-graph.cpp index 107cf92..f4ba83f 100644 --- a/src/load-graph.cpp +++ b/src/load-graph.cpp @@ -529,7 +529,11 @@ get_net (LoadGraph *graph) char **ifnames; guint32 i; guint64 in = 0, out = 0; +#if GLIB_CHECK_VERSION(2,61,2) + gint64 time; +#else GTimeVal time; +#endif guint64 din, dout; ifnames = glibtop_get_netlist(&netlist); @@ -563,13 +567,20 @@ get_net (LoadGraph *graph) g_strfreev(ifnames); - g_get_current_time (&time); +#if GLIB_CHECK_VERSION(2,61,2) + time = g_get_real_time (); if (in >= graph->net.last_in && out >= graph->net.last_out && + graph->net.time != 0) { + float dtime = (double) (time - graph->net.time) / G_USEC_PER_SEC; +#else + g_get_current_time (&time); + if (in >= graph->net.last_in && out >= graph->net.last_out && graph->net.time.tv_sec != 0) { float dtime; dtime = time.tv_sec - graph->net.time.tv_sec + (double) (time.tv_usec - graph->net.time.tv_usec) / G_USEC_PER_SEC; +#endif din = static_cast<guint64>((in - graph->net.last_in) / dtime); dout = static_cast<guint64>((out - graph->net.last_out) / dtime); } else { diff --git a/src/load-graph.h b/src/load-graph.h index 35bb62b..95e841b 100644 --- a/src/load-graph.h +++ b/src/load-graph.h @@ -86,7 +86,11 @@ struct LoadGraph { struct { guint64 last_in, last_out; +#if GLIB_CHECK_VERSION(2,61,2) + gint64 time; +#else GTimeVal time; +#endif guint64 max; unsigned values[NUM_POINTS]; size_t cur; diff --git a/src/util.cpp b/src/util.cpp index 8548249..e306935 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -240,6 +240,23 @@ is_debug_enabled(void) } +#if GLIB_CHECK_VERSION(2,61,2) +static gint64 +get_relative_time(void) +{ + static unsigned long start_time; + gint64 tv; + + if (G_UNLIKELY(!start_time)) { + glibtop_proc_time buf; + glibtop_get_proc_time(&buf, getpid()); + start_time = buf.start_time; + } + + tv = g_get_real_time (); + return tv - (gint64) start_time; +} +#else static double get_relative_time(void) { @@ -255,6 +272,7 @@ get_relative_time(void) g_get_current_time(&tv); return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec; } +#endif static guint64 get_size_from_column(GtkTreeModel* model, GtkTreeIter* first, @@ -296,8 +314,11 @@ procman_debug_real(const char *file, int line, const char *func, msg = g_strdup_vprintf(format, args); va_end(args); +#if GLIB_CHECK_VERSION(2,61,2) + g_debug("[%li %s:%d %s] %s", get_relative_time(), file, line, func, msg); +#else g_debug("[%.3f %s:%d %s] %s", get_relative_time(), file, line, func, msg); - +#endif g_free(msg); } |