-fix URIs
[oweals/gnunet.git] / src / statistics / statistics_api.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file statistics/statistics_api.c
23  * @brief API of the statistics service
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_statistics_service.h"
31 #include "statistics.h"
32
33 /**
34  * How long do we wait until a statistics request for setting
35  * a value times out?  (The update will be lost if the
36  * service does not react within this timeframe).
37  */
38 #define SET_TRANSMIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
39
40 #define LOG(kind,...) GNUNET_log_from (kind, "statistics-api",__VA_ARGS__)
41
42 /**
43  * Types of actions.
44  */
45 enum ActionType
46 {
47   /**
48    * Get a value.
49    */
50   ACTION_GET,
51
52   /**
53    * Set a value.
54    */
55   ACTION_SET,
56
57   /**
58    * Update a value.
59    */
60   ACTION_UPDATE,
61
62   /**
63    * Watch a value.
64    */
65   ACTION_WATCH
66 };
67
68
69 /**
70  * Entry kept for each value we are watching.
71  */
72 struct GNUNET_STATISTICS_WatchEntry
73 {
74
75   /**
76    * What subsystem is this action about? (never NULL)
77    */
78   char *subsystem;
79
80   /**
81    * What value is this action about? (never NULL)
82    */
83   char *name;
84
85   /**
86    * Function to call
87    */
88   GNUNET_STATISTICS_Iterator proc;
89
90   /**
91    * Closure for proc
92    */
93   void *proc_cls;
94
95 };
96
97
98 /**
99  * Linked list of things we still need to do.
100  */
101 struct GNUNET_STATISTICS_GetHandle
102 {
103
104   /**
105    * This is a doubly linked list.
106    */
107   struct GNUNET_STATISTICS_GetHandle *next;
108
109   /**
110    * This is a doubly linked list.
111    */
112   struct GNUNET_STATISTICS_GetHandle *prev;
113
114   /**
115    * Main statistics handle.
116    */
117   struct GNUNET_STATISTICS_Handle *sh;
118
119   /**
120    * What subsystem is this action about? (can be NULL)
121    */
122   char *subsystem;
123
124   /**
125    * What value is this action about? (can be NULL)
126    */
127   char *name;
128
129   /**
130    * Continuation to call once action is complete.
131    */
132   GNUNET_STATISTICS_Callback cont;
133
134   /**
135    * Function to call (for GET actions only).
136    */
137   GNUNET_STATISTICS_Iterator proc;
138
139   /**
140    * Closure for proc and cont.
141    */
142   void *cls;
143
144   /**
145    * Timeout for this action.
146    */
147   struct GNUNET_TIME_Absolute timeout;
148
149   /**
150    * Task run on timeout.
151    */
152   GNUNET_SCHEDULER_TaskIdentifier timeout_task;
153
154   /**
155    * Associated value.
156    */
157   uint64_t value;
158
159   /**
160    * Flag for SET/UPDATE actions.
161    */
162   int make_persistent;
163
164   /**
165    * Has the current iteration been aborted; for GET actions.
166    */
167   int aborted;
168
169   /**
170    * Is this a GET, SET, UPDATE or WATCH?
171    */
172   enum ActionType type;
173
174   /**
175    * Size of the message that we will be transmitting.
176    */
177   uint16_t msize;
178
179 };
180
181
182 /**
183  * Handle for the service.
184  */
185 struct GNUNET_STATISTICS_Handle
186 {
187   /**
188    * Name of our subsystem.
189    */
190   char *subsystem;
191
192   /**
193    * Configuration to use.
194    */
195   const struct GNUNET_CONFIGURATION_Handle *cfg;
196
197   /**
198    * Socket (if available).
199    */
200   struct GNUNET_CLIENT_Connection *client;
201
202   /**
203    * Currently pending transmission request.
204    */
205   struct GNUNET_CLIENT_TransmitHandle *th;
206
207   /**
208    * Head of the linked list of pending actions (first action
209    * to be performed).
210    */
211   struct GNUNET_STATISTICS_GetHandle *action_head;
212
213   /**
214    * Tail of the linked list of actions (for fast append).
215    */
216   struct GNUNET_STATISTICS_GetHandle *action_tail;
217
218   /**
219    * Action we are currently busy with (action request has been
220    * transmitted, we're now receiving the response from the
221    * service).
222    */
223   struct GNUNET_STATISTICS_GetHandle *current;
224
225   /**
226    * Array of watch entries.
227    */
228   struct GNUNET_STATISTICS_WatchEntry **watches;
229
230   /**
231    * Task doing exponential back-off trying to reconnect.
232    */
233   GNUNET_SCHEDULER_TaskIdentifier backoff_task;
234
235   /**
236    * Time for next connect retry.
237    */
238   struct GNUNET_TIME_Relative backoff;
239
240   /**
241    * Maximum heap size observed so far (if available).
242    */
243   uint64_t peak_heap_size;
244
245   /**
246    * Maximum resident set side observed so far (if available).
247    */
248   uint64_t peak_rss;
249
250   /**
251    * Size of the 'watches' array.
252    */
253   unsigned int watches_size;
254
255   /**
256    * Should this handle auto-destruct once all actions have
257    * been processed?
258    */
259   int do_destroy;
260
261   /**
262    * Are we currently receiving from the service?
263    */
264   int receiving;
265
266 };
267
268
269 /**
270  * Obtain statistics about this process's memory consumption and
271  * report those as well (if they changed).
272  */
273 static void
274 update_memory_statistics (struct GNUNET_STATISTICS_Handle *h)
275 {
276 #if ENABLE_HEAP_STATISTICS
277   uint64_t current_heap_size = 0;
278   uint64_t current_rss = 0;
279
280   if (GNUNET_NO != h->do_destroy)
281     return;
282 #if HAVE_MALLINFO
283   {
284     struct mallinfo mi;
285
286     mi = mallinfo();
287     current_heap_size = mi.uordblks + mi.fordblks;
288   }
289 #endif
290 #if HAVE_GETRUSAGE
291   {
292     struct rusage ru;
293
294     if (0 == getrusage (RUSAGE_SELF, &ru))
295     {
296       current_rss = 1024LL * ru.ru_maxrss;
297     }
298   }
299 #endif
300   if (current_heap_size > h->peak_heap_size)
301   {
302     h->peak_heap_size = current_heap_size;
303     GNUNET_STATISTICS_set (h, "# peak heap size", current_heap_size, GNUNET_NO);
304   }
305   if (current_rss > h->peak_rss)
306   {
307     h->peak_rss = current_rss;
308     GNUNET_STATISTICS_set (h, "# peak resident set size", current_rss, GNUNET_NO);
309   }
310 #endif
311 }
312
313
314 /**
315  * Schedule the next action to be performed.
316  *
317  * @param h statistics handle to reconnect
318  */
319 static void
320 schedule_action (struct GNUNET_STATISTICS_Handle *h);
321
322
323 /**
324  * Transmit request to service that we want to watch
325  * the development of a particular value.
326  *
327  * @param h statistics handle
328  * @param watch watch entry of the value to watch
329  */
330 static void
331 schedule_watch_request (struct GNUNET_STATISTICS_Handle *h,
332                         struct GNUNET_STATISTICS_WatchEntry *watch)
333 {
334   struct GNUNET_STATISTICS_GetHandle *ai;
335   size_t slen;
336   size_t nlen;
337   size_t nsize;
338
339   slen = strlen (watch->subsystem) + 1;
340   nlen = strlen (watch->name) + 1;
341   nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen;
342   if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
343   {
344     GNUNET_break (0);
345     return;
346   }
347   ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle);
348   ai->sh = h;
349   ai->subsystem = GNUNET_strdup (watch->subsystem);
350   ai->name = GNUNET_strdup (watch->name);
351   ai->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
352   ai->msize = nsize;
353   ai->type = ACTION_WATCH;
354   ai->proc = watch->proc;
355   ai->cls = watch->proc_cls;
356   GNUNET_CONTAINER_DLL_insert_tail (h->action_head, h->action_tail,
357                                     ai);
358   schedule_action (h);
359 }
360
361
362 /**
363  * Free memory associated with the given action item.
364  *
365  * @param gh action item to free
366  */
367 static void
368 free_action_item (struct GNUNET_STATISTICS_GetHandle *gh)
369 {
370   if (GNUNET_SCHEDULER_NO_TASK != gh->timeout_task)
371   {
372     GNUNET_SCHEDULER_cancel (gh->timeout_task);
373     gh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
374   }
375   GNUNET_free_non_null (gh->subsystem);
376   GNUNET_free_non_null (gh->name);
377   GNUNET_free (gh);
378 }
379
380
381 /**
382  * Disconnect from the statistics service.
383  *
384  * @param h statistics handle to disconnect from
385  */
386 static void
387 do_disconnect (struct GNUNET_STATISTICS_Handle *h)
388 {
389   struct GNUNET_STATISTICS_GetHandle *c;
390
391   if (NULL != h->th)
392   {
393     GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
394     h->th = NULL;
395   }
396   h->receiving = GNUNET_NO;
397   if (NULL != (c = h->current))
398   {
399     h->current = NULL;
400     if ( (NULL != c->cont) &&
401          (GNUNET_YES != c->aborted) )
402     {
403       c->cont (c->cls, GNUNET_SYSERR);
404       c->cont = NULL;
405     }
406     free_action_item (c);
407   }
408   if (NULL != h->client)
409   {
410     GNUNET_CLIENT_disconnect (h->client);
411     h->client = NULL;
412   }
413 }
414
415
416 /**
417  * Try to (re)connect to the statistics service.
418  *
419  * @param h statistics handle to reconnect
420  * @return #GNUNET_YES on success, #GNUNET_NO on failure.
421  */
422 static int
423 try_connect (struct GNUNET_STATISTICS_Handle *h)
424 {
425   struct GNUNET_STATISTICS_GetHandle *gh;
426   struct GNUNET_STATISTICS_GetHandle *gn;
427   unsigned int i;
428
429   if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
430     return GNUNET_NO;
431   if (NULL != h->client)
432     return GNUNET_YES;
433   h->client = GNUNET_CLIENT_connect ("statistics", h->cfg);
434   if (NULL != h->client)
435   {
436     gn = h->action_head;
437     while (NULL != (gh = gn))
438     {
439       gn = gh->next;
440       if (gh->type == ACTION_WATCH)
441       {
442         GNUNET_CONTAINER_DLL_remove (h->action_head,
443                                      h->action_tail,
444                                      gh);
445         free_action_item (gh);
446       }
447     }
448     for (i = 0; i < h->watches_size; i++)
449     {
450       if (NULL != h->watches[i])
451         schedule_watch_request (h, h->watches[i]);
452     }
453     return GNUNET_YES;
454   }
455   LOG (GNUNET_ERROR_TYPE_DEBUG,
456        "Failed to connect to statistics service!\n");
457   return GNUNET_NO;
458 }
459
460
461 /**
462  * We've waited long enough, reconnect now.
463  *
464  * @param cls the `struct GNUNET_STATISTICS_Handle` to reconnect
465  * @param tc scheduler context (unused)
466  */
467 static void
468 reconnect_task (void *cls,
469                 const struct GNUNET_SCHEDULER_TaskContext *tc)
470 {
471   struct GNUNET_STATISTICS_Handle *h = cls;
472
473   h->backoff_task = GNUNET_SCHEDULER_NO_TASK;
474   schedule_action (h);
475 }
476
477
478 /**
479  * Task used by 'reconnect_later' to shutdown the handle
480  *
481  * @param cls the statistics handle
482  * @param tc scheduler context
483  */
484 static void
485 do_destroy (void *cls,
486             const struct GNUNET_SCHEDULER_TaskContext *tc)
487 {
488   struct GNUNET_STATISTICS_Handle *h = cls;
489
490   GNUNET_STATISTICS_destroy (h, GNUNET_NO);
491 }
492
493
494 /**
495  * Reconnect at a later time, respecting back-off.
496  *
497  * @param h statistics handle
498  */
499 static void
500 reconnect_later (struct GNUNET_STATISTICS_Handle *h)
501 {
502   int loss;
503   struct GNUNET_STATISTICS_GetHandle *gh;
504
505   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->backoff_task);
506   if (GNUNET_YES == h->do_destroy)
507   {
508     /* So we are shutting down and the service is not reachable.
509      * Chances are that it's down for good and we are not going to connect to
510      * it anymore.
511      * Give up and don't sync the rest of the data.
512      */
513     loss = GNUNET_NO;
514     for (gh = h->action_head; NULL != gh; gh = gh->next)
515       if ( (gh->make_persistent) && (ACTION_SET == gh->type) )
516         loss = GNUNET_YES;
517     if (GNUNET_YES == loss)
518       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
519                   _("Could not save some persistent statistics\n"));
520     h->do_destroy = GNUNET_NO;
521     GNUNET_SCHEDULER_add_continuation (&do_destroy, h,
522                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
523     return;
524   }
525   h->backoff_task =
526     GNUNET_SCHEDULER_add_delayed (h->backoff, &reconnect_task, h);
527   h->backoff = GNUNET_TIME_STD_BACKOFF (h->backoff);
528 }
529
530
531 /**
532  * Process a #GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message.
533  *
534  * @param h statistics handle
535  * @param msg message received from the service, never NULL
536  * @return #GNUNET_OK if the message was well-formed
537  */
538 static int
539 process_statistics_value_message (struct GNUNET_STATISTICS_Handle *h,
540                                   const struct GNUNET_MessageHeader *msg)
541 {
542   char *service;
543   char *name;
544   const struct GNUNET_STATISTICS_ReplyMessage *smsg;
545   uint16_t size;
546
547   if (h->current->aborted)
548   {
549     LOG (GNUNET_ERROR_TYPE_DEBUG,
550          "Iteration was aborted, ignoring VALUE\n");
551     return GNUNET_OK;           /* don't bother */
552   }
553   size = ntohs (msg->size);
554   if (size < sizeof (struct GNUNET_STATISTICS_ReplyMessage))
555   {
556     GNUNET_break (0);
557     return GNUNET_SYSERR;
558   }
559   smsg = (const struct GNUNET_STATISTICS_ReplyMessage *) msg;
560   size -= sizeof (struct GNUNET_STATISTICS_ReplyMessage);
561   if (size !=
562       GNUNET_STRINGS_buffer_tokenize ((const char *) &smsg[1], size, 2,
563                                       &service, &name))
564   {
565     GNUNET_break (0);
566     return GNUNET_SYSERR;
567   }
568   LOG (GNUNET_ERROR_TYPE_DEBUG,
569        "Received valid statistic on `%s:%s': %llu\n",
570        service, name,
571        GNUNET_ntohll (smsg->value));
572   if (GNUNET_OK !=
573       h->current->proc (h->current->cls, service, name,
574                         GNUNET_ntohll (smsg->value),
575                         0 !=
576                         (ntohl (smsg->uid) & GNUNET_STATISTICS_PERSIST_BIT)))
577   {
578     LOG (GNUNET_ERROR_TYPE_DEBUG,
579          "Processing of remaining statistics aborted by client.\n");
580     h->current->aborted = GNUNET_YES;
581   }
582   LOG (GNUNET_ERROR_TYPE_DEBUG,
583        "VALUE processed successfully\n");
584   return GNUNET_OK;
585 }
586
587
588 /**
589  * We have received a watch value from the service.  Process it.
590  *
591  * @param h statistics handle
592  * @param msg the watch value message
593  * @return #GNUNET_OK if the message was well-formed, #GNUNET_SYSERR if not,
594  *         #GNUNET_NO if this watch has been cancelled
595  */
596 static int
597 process_watch_value (struct GNUNET_STATISTICS_Handle *h,
598                      const struct GNUNET_MessageHeader *msg)
599 {
600   const struct GNUNET_STATISTICS_WatchValueMessage *wvm;
601   struct GNUNET_STATISTICS_WatchEntry *w;
602   uint32_t wid;
603
604   if (sizeof (struct GNUNET_STATISTICS_WatchValueMessage) != ntohs (msg->size))
605   {
606     GNUNET_break (0);
607     return GNUNET_SYSERR;
608   }
609   wvm = (const struct GNUNET_STATISTICS_WatchValueMessage *) msg;
610   GNUNET_break (0 == ntohl (wvm->reserved));
611   wid = ntohl (wvm->wid);
612   if (wid >= h->watches_size)
613   {
614     GNUNET_break (0);
615     return GNUNET_SYSERR;
616   }
617   w = h->watches[wid];
618   if (NULL == w)
619     return GNUNET_NO;
620   (void) w->proc (w->proc_cls, w->subsystem, w->name,
621                   GNUNET_ntohll (wvm->value),
622                   0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
623   return GNUNET_OK;
624 }
625
626
627 /**
628  * Task used to destroy the statistics handle.
629  *
630  * @param cls the `struct GNUNET_STATISTICS_Handle`
631  * @param tc the scheduler context
632  */
633 static void
634 destroy_task (void *cls,
635               const struct GNUNET_SCHEDULER_TaskContext *tc)
636 {
637   struct GNUNET_STATISTICS_Handle *h = cls;
638
639   GNUNET_STATISTICS_destroy (h, GNUNET_NO);
640 }
641
642
643 /**
644  * Function called with messages from stats service.
645  *
646  * @param cls closure
647  * @param msg message received, NULL on timeout or fatal error
648  */
649 static void
650 receive_stats (void *cls,
651                const struct GNUNET_MessageHeader *msg)
652 {
653   struct GNUNET_STATISTICS_Handle *h = cls;
654   struct GNUNET_STATISTICS_GetHandle *c;
655   int ret;
656
657   if (NULL == msg)
658   {
659     LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
660          "Error receiving statistics from service, is the service running?\n");
661     do_disconnect (h);
662     reconnect_later (h);
663     return;
664   }
665   switch (ntohs (msg->type))
666   {
667   case GNUNET_MESSAGE_TYPE_TEST:
668     if (GNUNET_SYSERR != h->do_destroy)
669     {
670       /* not in shutdown, why do we get 'TEST'? */
671       GNUNET_break (0);
672       do_disconnect (h);
673       reconnect_later (h);
674       return;
675     }
676     h->do_destroy = GNUNET_NO;
677     GNUNET_SCHEDULER_add_continuation (&destroy_task, h,
678                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
679     break;
680   case GNUNET_MESSAGE_TYPE_STATISTICS_END:
681     LOG (GNUNET_ERROR_TYPE_DEBUG,
682          "Received end of statistics marker\n");
683     if (NULL == (c = h->current))
684     {
685       GNUNET_break (0);
686       do_disconnect (h);
687       reconnect_later (h);
688       return;
689     }
690     h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
691     if (h->watches_size > 0)
692     {
693       GNUNET_CLIENT_receive (h->client, &receive_stats, h,
694                              GNUNET_TIME_UNIT_FOREVER_REL);
695     }
696     else
697     {
698       h->receiving = GNUNET_NO;
699     }
700     h->current = NULL;
701     schedule_action (h);
702     if (NULL != c->cont)
703     {
704       c->cont (c->cls, GNUNET_OK);
705       c->cont = NULL;
706     }
707     free_action_item (c);
708     return;
709   case GNUNET_MESSAGE_TYPE_STATISTICS_VALUE:
710     if (GNUNET_OK != process_statistics_value_message (h, msg))
711     {
712       do_disconnect (h);
713       reconnect_later (h);
714       return;
715     }
716     /* finally, look for more! */
717     LOG (GNUNET_ERROR_TYPE_DEBUG,
718          "Processing VALUE done, now reading more\n");
719     GNUNET_CLIENT_receive (h->client, &receive_stats, h,
720                            GNUNET_TIME_absolute_get_remaining (h->
721                                                                current->timeout));
722     h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
723     return;
724   case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE:
725     if (GNUNET_OK !=
726         (ret = process_watch_value (h, msg)))
727     {
728       do_disconnect (h);
729       if (GNUNET_NO == ret)
730         h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
731       reconnect_later (h);
732       return;
733     }
734     h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
735     GNUNET_assert (h->watches_size > 0);
736     GNUNET_CLIENT_receive (h->client, &receive_stats, h,
737                            GNUNET_TIME_UNIT_FOREVER_REL);
738     return;
739   default:
740     GNUNET_break (0);
741     do_disconnect (h);
742     reconnect_later (h);
743     return;
744   }
745 }
746
747
748 /**
749  * Transmit a GET request (and if successful, start to receive
750  * the response).
751  *
752  * @param handle statistics handle
753  * @param size how many bytes can we write to @a buf
754  * @param buf where to write requests to the service
755  * @return number of bytes written to @a buf
756  */
757 static size_t
758 transmit_get (struct GNUNET_STATISTICS_Handle *handle,
759               size_t size,
760               void *buf)
761 {
762   struct GNUNET_STATISTICS_GetHandle *c;
763   struct GNUNET_MessageHeader *hdr;
764   size_t slen1;
765   size_t slen2;
766   uint16_t msize;
767
768   GNUNET_assert (NULL != (c = handle->current));
769   if (NULL == buf)
770   {
771     /* timeout / error */
772     LOG (GNUNET_ERROR_TYPE_DEBUG,
773          "Transmission of request for statistics failed!\n");
774     do_disconnect (handle);
775     reconnect_later (handle);
776     return 0;
777   }
778   slen1 = strlen (c->subsystem) + 1;
779   slen2 = strlen (c->name) + 1;
780   msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
781   GNUNET_assert (msize <= size);
782   hdr = (struct GNUNET_MessageHeader *) buf;
783   hdr->size = htons (msize);
784   hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_GET);
785   GNUNET_assert (slen1 + slen2 ==
786                  GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2,
787                                              c->subsystem,
788                                              c->name));
789   if (GNUNET_YES != handle->receiving)
790   {
791     LOG (GNUNET_ERROR_TYPE_DEBUG,
792          "Transmission of GET done, now reading response\n");
793     handle->receiving = GNUNET_YES;
794     GNUNET_CLIENT_receive (handle->client, &receive_stats, handle,
795                            GNUNET_TIME_absolute_get_remaining (c->timeout));
796   }
797   return msize;
798 }
799
800
801 /**
802  * Transmit a WATCH request (and if successful, start to receive
803  * the response).
804  *
805  * @param handle statistics handle
806  * @param size how many bytes can we write to @a buf
807  * @param buf where to write requests to the service
808  * @return number of bytes written to @a buf
809  */
810 static size_t
811 transmit_watch (struct GNUNET_STATISTICS_Handle *handle,
812                 size_t size,
813                 void *buf)
814 {
815   struct GNUNET_MessageHeader *hdr;
816   size_t slen1;
817   size_t slen2;
818   uint16_t msize;
819
820   if (NULL == buf)
821   {
822     /* timeout / error */
823     LOG (GNUNET_ERROR_TYPE_DEBUG,
824          "Transmission of request for statistics failed!\n");
825     do_disconnect (handle);
826     reconnect_later (handle);
827     return 0;
828   }
829   LOG (GNUNET_ERROR_TYPE_DEBUG,
830        "Transmitting watch request for `%s'\n",
831        handle->current->name);
832   slen1 = strlen (handle->current->subsystem) + 1;
833   slen2 = strlen (handle->current->name) + 1;
834   msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
835   GNUNET_assert (msize <= size);
836   hdr = (struct GNUNET_MessageHeader *) buf;
837   hdr->size = htons (msize);
838   hdr->type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_WATCH);
839   GNUNET_assert (slen1 + slen2 ==
840                  GNUNET_STRINGS_buffer_fill ((char *) &hdr[1], slen1 + slen2, 2,
841                                              handle->current->subsystem,
842                                              handle->current->name));
843   if (GNUNET_YES != handle->receiving)
844   {
845     handle->receiving = GNUNET_YES;
846     GNUNET_CLIENT_receive (handle->client, &receive_stats, handle,
847                            GNUNET_TIME_UNIT_FOREVER_REL);
848   }
849   GNUNET_assert (NULL == handle->current->cont);
850   free_action_item (handle->current);
851   handle->current = NULL;
852   return msize;
853 }
854
855
856 /**
857  * Transmit a SET/UPDATE request.
858  *
859  * @param handle statistics handle
860  * @param size how many bytes can we write to @a buf
861  * @param buf where to write requests to the service
862  * @return number of bytes written to @a buf
863  */
864 static size_t
865 transmit_set (struct GNUNET_STATISTICS_Handle *handle,
866               size_t size,
867               void *buf)
868 {
869   struct GNUNET_STATISTICS_SetMessage *r;
870   size_t slen;
871   size_t nlen;
872   size_t nsize;
873
874   if (NULL == buf)
875   {
876     do_disconnect (handle);
877     reconnect_later (handle);
878     return 0;
879   }
880   slen = strlen (handle->current->subsystem) + 1;
881   nlen = strlen (handle->current->name) + 1;
882   nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
883   if (size < nsize)
884   {
885     GNUNET_break (0);
886     do_disconnect (handle);
887     reconnect_later (handle);
888     return 0;
889   }
890   r = buf;
891   r->header.size = htons (nsize);
892   r->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_SET);
893   r->flags = 0;
894   r->value = GNUNET_htonll (handle->current->value);
895   if (handle->current->make_persistent)
896     r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_PERSISTENT);
897   if (handle->current->type == ACTION_UPDATE)
898     r->flags |= htonl (GNUNET_STATISTICS_SETFLAG_RELATIVE);
899   GNUNET_assert (slen + nlen ==
900                  GNUNET_STRINGS_buffer_fill ((char *) &r[1], slen + nlen, 2,
901                                              handle->current->subsystem,
902                                              handle->current->name));
903   GNUNET_assert (NULL == handle->current->cont);
904   free_action_item (handle->current);
905   handle->current = NULL;
906   update_memory_statistics (handle);
907   return nsize;
908 }
909
910
911 /**
912  * Function called when we are ready to transmit a request to the service.
913  *
914  * @param cls the `struct GNUNET_STATISTICS_Handle`
915  * @param size how many bytes can we write to @a buf
916  * @param buf where to write requests to the service
917  * @return number of bytes written to @a buf
918  */
919 static size_t
920 transmit_action (void *cls, size_t size, void *buf)
921 {
922   struct GNUNET_STATISTICS_Handle *h = cls;
923   size_t ret;
924
925   h->th = NULL;
926   ret = 0;
927   if (NULL != h->current)
928     switch (h->current->type)
929     {
930     case ACTION_GET:
931       ret = transmit_get (h, size, buf);
932       break;
933     case ACTION_SET:
934     case ACTION_UPDATE:
935       ret = transmit_set (h, size, buf);
936       break;
937     case ACTION_WATCH:
938       ret = transmit_watch (h, size, buf);
939       break;
940     default:
941       GNUNET_assert (0);
942       break;
943     }
944   schedule_action (h);
945   return ret;
946 }
947
948
949 /**
950  * Get handle for the statistics service.
951  *
952  * @param subsystem name of subsystem using the service
953  * @param cfg services configuration in use
954  * @return handle to use
955  */
956 struct GNUNET_STATISTICS_Handle *
957 GNUNET_STATISTICS_create (const char *subsystem,
958                           const struct GNUNET_CONFIGURATION_Handle *cfg)
959 {
960   struct GNUNET_STATISTICS_Handle *ret;
961
962   if (GNUNET_YES ==
963       GNUNET_CONFIGURATION_get_value_yesno (cfg, "statistics", "DISABLE"))
964     return NULL;
965   GNUNET_assert (NULL != subsystem);
966   GNUNET_assert (NULL != cfg);
967   ret = GNUNET_new (struct GNUNET_STATISTICS_Handle);
968   ret->cfg = cfg;
969   ret->subsystem = GNUNET_strdup (subsystem);
970   ret->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
971   return ret;
972 }
973
974
975 /**
976  * Destroy a handle (free all state associated with
977  * it).
978  *
979  * @param h statistics handle to destroy
980  * @param sync_first set to #GNUNET_YES if pending SET requests should
981  *        be completed
982  */
983 void
984 GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
985                            int sync_first)
986 {
987   struct GNUNET_STATISTICS_GetHandle *pos;
988   struct GNUNET_STATISTICS_GetHandle *next;
989   struct GNUNET_TIME_Relative timeout;
990   int i;
991
992   if (NULL == h)
993     return;
994   GNUNET_assert (GNUNET_NO == h->do_destroy); // Don't call twice.
995   if (GNUNET_SCHEDULER_NO_TASK != h->backoff_task)
996   {
997     GNUNET_SCHEDULER_cancel (h->backoff_task);
998     h->backoff_task = GNUNET_SCHEDULER_NO_TASK;
999   }
1000   if (sync_first)
1001   {
1002     if (NULL != h->current)
1003     {
1004       if (ACTION_GET == h->current->type)
1005       {
1006         if (NULL != h->th)
1007         {
1008           GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
1009           h->th = NULL;
1010         }
1011         free_action_item (h->current);
1012         h->current = NULL;
1013       }
1014     }
1015     next = h->action_head;
1016     while (NULL != (pos = next))
1017     {
1018       next = pos->next;
1019       if (ACTION_GET == pos->type)
1020       {
1021         GNUNET_CONTAINER_DLL_remove (h->action_head,
1022                                      h->action_tail,
1023                                      pos);
1024         free_action_item (pos);
1025       }
1026     }
1027     if ( (NULL == h->current) &&
1028          (NULL != (h->current = h->action_head)) )
1029       GNUNET_CONTAINER_DLL_remove (h->action_head,
1030                                    h->action_tail,
1031                                    h->current);
1032     h->do_destroy = GNUNET_YES;
1033     if ((NULL != h->current) && (NULL == h->th) &&
1034         (NULL != h->client))
1035     {
1036       timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
1037       h->th =
1038         GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize,
1039                                              timeout, GNUNET_YES,
1040                                              &transmit_action, h);
1041       GNUNET_assert (NULL != h->th);
1042     }
1043     if (NULL != h->th)
1044       return; /* do not finish destruction just yet */
1045   }
1046   while (NULL != (pos = h->action_head))
1047   {
1048     GNUNET_CONTAINER_DLL_remove (h->action_head,
1049                                  h->action_tail,
1050                                  pos);
1051     free_action_item (pos);
1052   }
1053   do_disconnect (h);
1054   for (i = 0; i < h->watches_size; i++)
1055   {
1056     if (NULL == h->watches[i])
1057       continue;
1058     GNUNET_free (h->watches[i]->subsystem);
1059     GNUNET_free (h->watches[i]->name);
1060     GNUNET_free (h->watches[i]);
1061   }
1062   GNUNET_array_grow (h->watches, h->watches_size, 0);
1063   GNUNET_free (h->subsystem);
1064   GNUNET_free (h);
1065 }
1066
1067
1068 /**
1069  * Function called to transmit TEST message to service to
1070  * confirm that the service has received all of our 'SET'
1071  * messages (during statistics disconnect/shutdown).
1072  *
1073  * @param cls the `struct GNUNET_STATISTICS_Handle`
1074  * @param size how many bytes can we write to @a buf
1075  * @param buf where to write requests to the service
1076  * @return number of bytes written to @a buf
1077  */
1078 static size_t
1079 transmit_test_on_shutdown (void *cls,
1080                            size_t size,
1081                            void *buf)
1082 {
1083   struct GNUNET_STATISTICS_Handle *h = cls;
1084   struct GNUNET_MessageHeader hdr;
1085
1086   h->th = NULL;
1087   if (NULL == buf)
1088   {
1089     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1090                 _("Failed to receive acknowledgement from statistics service, some statistics might have been lost!\n"));
1091     h->do_destroy = GNUNET_NO;
1092     GNUNET_SCHEDULER_add_continuation (&destroy_task, h,
1093                                        GNUNET_SCHEDULER_REASON_PREREQ_DONE);
1094     return 0;
1095   }
1096   hdr.type = htons (GNUNET_MESSAGE_TYPE_TEST);
1097   hdr.size = htons (sizeof (struct GNUNET_MessageHeader));
1098   memcpy (buf, &hdr, sizeof (hdr));
1099   if (GNUNET_YES != h->receiving)
1100   {
1101     h->receiving = GNUNET_YES;
1102     GNUNET_CLIENT_receive (h->client, &receive_stats, h,
1103                            GNUNET_TIME_UNIT_FOREVER_REL);
1104   }
1105   return sizeof (struct GNUNET_MessageHeader);
1106 }
1107
1108
1109 /**
1110  * Schedule the next action to be performed.
1111  *
1112  * @param h statistics handle
1113  */
1114 static void
1115 schedule_action (struct GNUNET_STATISTICS_Handle *h)
1116 {
1117   struct GNUNET_TIME_Relative timeout;
1118
1119   if ( (NULL != h->th) ||
1120        (GNUNET_SCHEDULER_NO_TASK != h->backoff_task) )
1121     return;                     /* action already pending */
1122   if (GNUNET_YES != try_connect (h))
1123   {
1124     reconnect_later (h);
1125     return;
1126   }
1127   if (NULL != h->current)
1128     return; /* action already pending */
1129   /* schedule next action */
1130   h->current = h->action_head;
1131   if (NULL == h->current)
1132   {
1133     if (GNUNET_YES == h->do_destroy)
1134     {
1135       h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */
1136       h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
1137                                                    sizeof (struct GNUNET_MessageHeader),
1138                                                    SET_TRANSMIT_TIMEOUT,
1139                                                    GNUNET_NO,
1140                                                    &transmit_test_on_shutdown, h);
1141     }
1142     return;
1143   }
1144   GNUNET_CONTAINER_DLL_remove (h->action_head, h->action_tail, h->current);
1145   timeout = GNUNET_TIME_absolute_get_remaining (h->current->timeout);
1146   if (NULL ==
1147       (h->th =
1148        GNUNET_CLIENT_notify_transmit_ready (h->client, h->current->msize,
1149                                             timeout, GNUNET_YES,
1150                                             &transmit_action, h)))
1151   {
1152     LOG (GNUNET_ERROR_TYPE_DEBUG,
1153          "Failed to transmit request to statistics service.\n");
1154     do_disconnect (h);
1155     reconnect_later (h);
1156   }
1157 }
1158
1159
1160 /**
1161  * We have run into a timeout on a #GNUNET_STATISTICS_get() operation,
1162  * call the continuation.
1163  *
1164  * @param cls the `struct GNUNET_STATISTICS_GetHandle`
1165  * @param tc scheduler context
1166  */
1167 static void
1168 run_get_timeout (void *cls,
1169                  const struct GNUNET_SCHEDULER_TaskContext *tc)
1170 {
1171   struct GNUNET_STATISTICS_GetHandle *gh = cls;
1172   GNUNET_STATISTICS_Callback cont = gh->cont;
1173   void *cont_cls = gh->cls;
1174
1175   gh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1176   GNUNET_STATISTICS_get_cancel (gh);
1177   cont (cont_cls, GNUNET_SYSERR);
1178 }
1179
1180
1181 /**
1182  * Get statistic from the peer.
1183  *
1184  * @param handle identification of the statistics service
1185  * @param subsystem limit to the specified subsystem, NULL for our subsystem
1186  * @param name name of the statistic value, NULL for all values
1187  * @param timeout after how long should we give up (and call
1188  *        cont with an error code)?
1189  * @param cont continuation to call when done (can be NULL)
1190  *        This callback CANNOT destroy the statistics handle in the same call.
1191  * @param proc function to call on each value
1192  * @param cls closure for @a cont and @a proc
1193  * @return NULL on error
1194  */
1195 struct GNUNET_STATISTICS_GetHandle *
1196 GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
1197                        const char *subsystem, const char *name,
1198                        struct GNUNET_TIME_Relative timeout,
1199                        GNUNET_STATISTICS_Callback cont,
1200                        GNUNET_STATISTICS_Iterator proc, void *cls)
1201 {
1202   size_t slen1;
1203   size_t slen2;
1204   struct GNUNET_STATISTICS_GetHandle *ai;
1205
1206   if (NULL == handle)
1207     return NULL;
1208   GNUNET_assert (NULL != proc);
1209   GNUNET_assert (GNUNET_NO == handle->do_destroy);
1210   if (NULL == subsystem)
1211     subsystem = "";
1212   if (NULL == name)
1213     name = "";
1214   slen1 = strlen (subsystem) + 1;
1215   slen2 = strlen (name) + 1;
1216   GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) <
1217                  GNUNET_SERVER_MAX_MESSAGE_SIZE);
1218   ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle);
1219   ai->sh = handle;
1220   ai->subsystem = GNUNET_strdup (subsystem);
1221   ai->name = GNUNET_strdup (name);
1222   ai->cont = cont;
1223   ai->proc = proc;
1224   ai->cls = cls;
1225   ai->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1226   ai->type = ACTION_GET;
1227   ai->msize = slen1 + slen2 + sizeof (struct GNUNET_MessageHeader);
1228   ai->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
1229                                                    &run_get_timeout,
1230                                                    ai);
1231   GNUNET_CONTAINER_DLL_insert_tail (handle->action_head, handle->action_tail,
1232                                     ai);
1233   schedule_action (handle);
1234   return ai;
1235 }
1236
1237
1238 /**
1239  * Cancel a 'get' request.  Must be called before the 'cont'
1240  * function is called.
1241  *
1242  * @param gh handle of the request to cancel
1243  */
1244 void
1245 GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh)
1246 {
1247   if (NULL == gh)
1248     return;
1249   if (GNUNET_SCHEDULER_NO_TASK != gh->timeout_task)
1250   {
1251     GNUNET_SCHEDULER_cancel (gh->timeout_task);
1252     gh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1253   }
1254   gh->cont = NULL;
1255   if (gh->sh->current == gh)
1256   {
1257     gh->aborted = GNUNET_YES;
1258   }
1259   else
1260   {
1261     GNUNET_CONTAINER_DLL_remove (gh->sh->action_head, gh->sh->action_tail, gh);
1262     GNUNET_free (gh->name);
1263     GNUNET_free (gh->subsystem);
1264     GNUNET_free (gh);
1265   }
1266 }
1267
1268
1269 /**
1270  * Watch statistics from the peer (be notified whenever they change).
1271  *
1272  * @param handle identification of the statistics service
1273  * @param subsystem limit to the specified subsystem, never NULL
1274  * @param name name of the statistic value, never NULL
1275  * @param proc function to call on each value
1276  * @param proc_cls closure for @a proc
1277  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1278  */
1279 int
1280 GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
1281                          const char *subsystem, const char *name,
1282                          GNUNET_STATISTICS_Iterator proc, void *proc_cls)
1283 {
1284   struct GNUNET_STATISTICS_WatchEntry *w;
1285
1286   if (NULL == handle)
1287     return GNUNET_SYSERR;
1288   w = GNUNET_new (struct GNUNET_STATISTICS_WatchEntry);
1289   w->subsystem = GNUNET_strdup (subsystem);
1290   w->name = GNUNET_strdup (name);
1291   w->proc = proc;
1292   w->proc_cls = proc_cls;
1293   GNUNET_array_append (handle->watches, handle->watches_size, w);
1294   schedule_watch_request (handle, w);
1295   return GNUNET_OK;
1296 }
1297
1298
1299 /**
1300  * Stop watching statistics from the peer.
1301  *
1302  * @param handle identification of the statistics service
1303  * @param subsystem limit to the specified subsystem, never NULL
1304  * @param name name of the statistic value, never NULL
1305  * @param proc function to call on each value
1306  * @param proc_cls closure for @a proc
1307  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (no such watch)
1308  */
1309 int
1310 GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle,
1311                                 const char *subsystem,
1312                                 const char *name,
1313                                 GNUNET_STATISTICS_Iterator proc,
1314                                 void *proc_cls)
1315 {
1316   struct GNUNET_STATISTICS_WatchEntry *w;
1317   unsigned int i;
1318
1319   if (NULL == handle)
1320     return GNUNET_SYSERR;
1321   for (i=0;i<handle->watches_size;i++)
1322   {
1323     w = handle->watches[i];
1324     if (NULL == w)
1325       continue;
1326     if ( (w->proc == proc) &&
1327          (w->proc_cls == proc_cls) &&
1328          (0 == strcmp (w->name, name)) &&
1329          (0 == strcmp (w->subsystem, subsystem)) )
1330     {
1331       GNUNET_free (w->name);
1332       GNUNET_free (w->subsystem);
1333       GNUNET_free (w);
1334       handle->watches[i] = NULL;
1335       return GNUNET_OK;
1336     }
1337   }
1338   return GNUNET_SYSERR;
1339 }
1340
1341
1342
1343 /**
1344  * Queue a request to change a statistic.
1345  *
1346  * @param h statistics handle
1347  * @param name name of the value
1348  * @param make_persistent  should the value be kept across restarts?
1349  * @param value new value or change
1350  * @param type type of the action (#ACTION_SET or #ACTION_UPDATE)
1351  */
1352 static void
1353 add_setter_action (struct GNUNET_STATISTICS_Handle *h,
1354                    const char *name,
1355                    int make_persistent,
1356                    uint64_t value,
1357                    enum ActionType type)
1358 {
1359   struct GNUNET_STATISTICS_GetHandle *ai;
1360   size_t slen;
1361   size_t nlen;
1362   size_t nsize;
1363   int64_t delta;
1364
1365   slen = strlen (h->subsystem) + 1;
1366   nlen = strlen (name) + 1;
1367   nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
1368   if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1369   {
1370     GNUNET_break (0);
1371     return;
1372   }
1373   for (ai = h->action_head; NULL != ai; ai = ai->next)
1374   {
1375     if (! ( (0 == strcmp (ai->subsystem, h->subsystem)) &&
1376             (0 == strcmp (ai->name, name)) &&
1377             ( (ACTION_UPDATE == ai->type) ||
1378               (ACTION_SET == ai->type) ) ) )
1379       continue;
1380     if (ACTION_SET == ai->type)
1381     {
1382       if (ACTION_UPDATE == type)
1383       {
1384         delta = (int64_t) value;
1385         if (delta > 0)
1386         {
1387           /* update old set by new delta */
1388           ai->value += delta;
1389         }
1390         else
1391         {
1392           /* update old set by new delta, but never go negative */
1393           if (ai->value < -delta)
1394             ai->value = 0;
1395           else
1396             ai->value += delta;
1397         }
1398       }
1399       else
1400       {
1401         /* new set overrides old set */
1402         ai->value = value;
1403       }
1404     }
1405     else
1406     {
1407       if (ACTION_UPDATE == type)
1408       {
1409         /* make delta cummulative */
1410         delta = (int64_t) value;
1411         ai->value += delta;
1412       }
1413       else
1414       {
1415         /* drop old 'update', use new 'set' instead */
1416         ai->value = value;
1417         ai->type = type;
1418       }
1419     }
1420     ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1421     ai->make_persistent = make_persistent;
1422     return;
1423   }
1424   /* no existing entry matches, create a fresh one */
1425   ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle);
1426   ai->sh = h;
1427   ai->subsystem = GNUNET_strdup (h->subsystem);
1428   ai->name = GNUNET_strdup (name);
1429   ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
1430   ai->make_persistent = make_persistent;
1431   ai->msize = nsize;
1432   ai->value = value;
1433   ai->type = type;
1434   GNUNET_CONTAINER_DLL_insert_tail (h->action_head, h->action_tail,
1435                                     ai);
1436   schedule_action (h);
1437 }
1438
1439
1440 /**
1441  * Set statistic value for the peer.  Will always use our
1442  * subsystem (the argument used when "handle" was created).
1443  *
1444  * @param handle identification of the statistics service
1445  * @param name name of the statistic value
1446  * @param value new value to set
1447  * @param make_persistent should the value be kept across restarts?
1448  */
1449 void
1450 GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
1451                        const char *name,
1452                        uint64_t value,
1453                        int make_persistent)
1454 {
1455   if (NULL == handle)
1456     return;
1457   GNUNET_assert (GNUNET_NO == handle->do_destroy);
1458   add_setter_action (handle, name, make_persistent, value, ACTION_SET);
1459 }
1460
1461
1462 /**
1463  * Set statistic value for the peer.  Will always use our
1464  * subsystem (the argument used when "handle" was created).
1465  *
1466  * @param handle identification of the statistics service
1467  * @param name name of the statistic value
1468  * @param delta change in value (added to existing value)
1469  * @param make_persistent should the value be kept across restarts?
1470  */
1471 void
1472 GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
1473                           const char *name,
1474                           int64_t delta,
1475                           int make_persistent)
1476 {
1477   if (NULL == handle)
1478     return;
1479   if (0 == delta)
1480     return;
1481   GNUNET_assert (GNUNET_NO == handle->do_destroy);
1482   add_setter_action (handle,
1483                      name,
1484                      make_persistent,
1485                      (uint64_t) delta,
1486                      ACTION_UPDATE);
1487 }
1488
1489
1490 /* end of statistics_api.c */