[gnome-system-monitor] Don't use deprecated GTimeVal



commit bb494d6e06f134bc538d732d0ca6dea263becf22
Author: Robert Roth <robert roth off gmail com>
Date:   Thu Jan 23 23:20:05 2020 +0200

    Don't use deprecated GTimeVal

 src/load-graph.cpp | 11 +++++------
 src/load-graph.h   |  2 +-
 src/util.cpp       |  4 +---
 3 files changed, 7 insertions(+), 10 deletions(-)
---
diff --git a/src/load-graph.cpp b/src/load-graph.cpp
index 8d79f985..74fe56ba 100644
--- a/src/load-graph.cpp
+++ b/src/load-graph.cpp
@@ -607,7 +607,7 @@ get_net (LoadGraph *graph)
     char **ifnames;
     guint32 i;
     guint64 in = 0, out = 0;
-    GTimeVal time;
+    guint64 time;
     guint64 din, dout;
     gboolean first = true;
     ifnames = glibtop_get_netlist(&netlist);
@@ -641,12 +641,11 @@ get_net (LoadGraph *graph)
 
     g_strfreev(ifnames);
 
-    g_get_current_time (&time);
+    time = g_get_monotonic_time ();
 
-    if (in >= graph->net.last_in && out >= graph->net.last_out && graph->net.time.tv_sec != 0) {
+    if (in >= graph->net.last_in && out >= graph->net.last_out && graph->net.time != 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;
+        dtime = time - graph->net.time;
         din   = static_cast<guint64>((in  - graph->net.last_in)  / dtime);
         dout  = static_cast<guint64>((out - graph->net.last_out) / dtime);
     } else {
@@ -656,7 +655,7 @@ get_net (LoadGraph *graph)
         dout = 0;
     }
 
-    first = first && (graph->net.time.tv_sec==0);
+    first = first && (graph->net.time==0);
     graph->net.last_in  = in;
     graph->net.last_out = out;
     graph->net.time     = time;
diff --git a/src/load-graph.h b/src/load-graph.h
index 16e399e7..58f3b4bd 100644
--- a/src/load-graph.h
+++ b/src/load-graph.h
@@ -90,7 +90,7 @@ struct LoadGraph
     struct
     {
         guint64 last_in, last_out;
-        GTimeVal time;
+        guint64 time;
         guint64 max;
         unsigned values[NUM_POINTS];
         size_t cur;
diff --git a/src/util.cpp b/src/util.cpp
index 8efebf34..044fc925 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -252,7 +252,6 @@ static double
 get_relative_time(void)
 {
     static unsigned long start_time;
-    GTimeVal tv;
 
     if (G_UNLIKELY(!start_time)) {
         glibtop_proc_time buf;
@@ -260,8 +259,7 @@ get_relative_time(void)
         start_time = buf.start_time;
     }
 
-    g_get_current_time(&tv);
-    return (tv.tv_sec - start_time) + 1e-6 * tv.tv_usec;
+    return 1e-6 * g_get_monotonic_time () - start_time;
 }
 
 static guint64


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]