aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/gnunet-statistics.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/statistics/gnunet-statistics.c')
-rw-r--r--src/statistics/gnunet-statistics.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c
index 0cbafa68f..5267e38cf 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -65,13 +65,12 @@ static int persistent;
65static int 65static int
66printer (void *cls, 66printer (void *cls,
67 const char *subsystem, 67 const char *subsystem,
68 const char *name, 68 const char *name, uint64_t value, int is_persistent)
69 uint64_t value, int is_persistent)
70{ 69{
71 FPRINTF (stdout, 70 FPRINTF (stdout,
72 "%s%-12s %-50s: %16llu\n", 71 "%s%-12s %-50s: %16llu\n",
73 is_persistent ? "!" : " ", subsystem, _(name), 72 is_persistent ? "!" : " ", subsystem, _(name),
74 (unsigned long long) value); 73 (unsigned long long) value);
75 return GNUNET_OK; 74 return GNUNET_OK;
76} 75}
77 76
@@ -89,14 +88,12 @@ cleanup (void *cls, int success)
89 struct GNUNET_STATISTICS_Handle *h = cls; 88 struct GNUNET_STATISTICS_Handle *h = cls;
90 89
91 if (success != GNUNET_OK) 90 if (success != GNUNET_OK)
92 { 91 {
93 fprintf (stderr, 92 fprintf (stderr, _("Failed to obtain statistics.\n"));
94 _("Failed to obtain statistics.\n")); 93 ret = 1;
95 ret = 1; 94 }
96 }
97 if (h != NULL) 95 if (h != NULL)
98 GNUNET_STATISTICS_destroy (h, 96 GNUNET_STATISTICS_destroy (h, GNUNET_NO);
99 GNUNET_NO);
100} 97}
101 98
102 99
@@ -111,39 +108,39 @@ cleanup (void *cls, int success)
111static void 108static void
112run (void *cls, 109run (void *cls,
113 char *const *args, 110 char *const *args,
114 const char *cfgfile, 111 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
115 const struct GNUNET_CONFIGURATION_Handle *cfg)
116{ 112{
117 struct GNUNET_STATISTICS_Handle *h; 113 struct GNUNET_STATISTICS_Handle *h;
118 unsigned long long val; 114 unsigned long long val;
119 115
120 if (args[0] != NULL) 116 if (args[0] != NULL)
117 {
118 if ((1 != SSCANF (args[0], "%llu", &val)) ||
119 (subsystem == NULL) || (name == NULL))
121 { 120 {
122 if ((1 != SSCANF (args[0], "%llu", &val)) || 121 FPRINTF (stderr, _("Invalid argument `%s'\n"), args[0]);
123 (subsystem == NULL) || (name == NULL)) 122 ret = 1;
124 {
125 FPRINTF (stderr, _("Invalid argument `%s'\n"), args[0]);
126 ret = 1;
127 return;
128 }
129 h = GNUNET_STATISTICS_create (subsystem, cfg);
130 if (h == NULL)
131 {
132 ret = 1;
133 return;
134 }
135 GNUNET_STATISTICS_set (h, name, (uint64_t) val, persistent);
136 GNUNET_STATISTICS_destroy (h, GNUNET_YES);
137 return; 123 return;
138 } 124 }
139 h = GNUNET_STATISTICS_create ("gnunet-statistics", cfg); 125 h = GNUNET_STATISTICS_create (subsystem, cfg);
140 if (h == NULL) 126 if (h == NULL)
141 { 127 {
142 ret = 1; 128 ret = 1;
143 return; 129 return;
144 } 130 }
131 GNUNET_STATISTICS_set (h, name, (uint64_t) val, persistent);
132 GNUNET_STATISTICS_destroy (h, GNUNET_YES);
133 return;
134 }
135 h = GNUNET_STATISTICS_create ("gnunet-statistics", cfg);
136 if (h == NULL)
137 {
138 ret = 1;
139 return;
140 }
145 if (NULL == GNUNET_STATISTICS_get (h, 141 if (NULL == GNUNET_STATISTICS_get (h,
146 subsystem, name, GET_TIMEOUT, &cleanup, &printer, h)) 142 subsystem, name, GET_TIMEOUT, &cleanup,
143 &printer, h))
147 cleanup (h, GNUNET_SYSERR); 144 cleanup (h, GNUNET_SYSERR);
148} 145}
149 146