@@ -27,7 +27,11 @@ static char hostname[HOST_LEN + 1];
2727// only used `stats_ctx.thread` currently
2828static struct context stats_ctx ;
2929
30- struct stats cumulation ;
30+ static struct stats cumulation ;
31+ static struct {
32+ double sys ;
33+ double user ;
34+ } used_cpu ;
3135
3236static inline void stats_get_cpu_usage (struct stats * stats )
3337{
@@ -90,6 +94,16 @@ void stats_get_simple(struct stats *stats, bool reset)
9094 }
9195
9296 stats_get_cpu_usage (stats );
97+ if (reset ) {
98+ double temp_sys = stats -> used_cpu_sys ;
99+ double temp_user = stats -> used_cpu_user ;
100+
101+ stats -> used_cpu_sys -= used_cpu .sys ;
102+ stats -> used_cpu_user -= used_cpu .user ;
103+
104+ used_cpu .sys = temp_sys ;
105+ used_cpu .user = temp_user ;
106+ }
93107
94108 struct context * contexts = get_contexts ();
95109
@@ -140,9 +154,9 @@ void stats_node_info_agg(struct bytes *bytes)
140154 b -> completed = 0 ;
141155 dict_set (& bytes_map , b -> key , (void * )b );
142156 }
143- b -> send += ATOMIC_GET (server -> info -> send_bytes );
144- b -> recv += ATOMIC_GET (server -> info -> recv_bytes );
145- b -> completed += ATOMIC_GET (server -> info -> completed_commands );
157+ b -> send += ATOMIC_IGET (server -> info -> send_bytes , 0 );
158+ b -> recv += ATOMIC_IGET (server -> info -> recv_bytes , 0 );
159+ b -> completed += ATOMIC_IGET (server -> info -> completed_commands , 0 );
146160 }
147161 }
148162}
@@ -223,6 +237,7 @@ int stats_init()
223237 dict_init (& bytes_map );
224238
225239 memset (& cumulation , 0 , sizeof (cumulation ));
240+ memset (& used_cpu , 0 , sizeof (used_cpu ));
226241
227242 gethostname (hostname , HOST_LEN + 1 );
228243 len = strlen (hostname );
0 commit comments