program that tracks statistics More...
#include "platform.h"#include "gnunet_util_lib.h"#include "gnunet_protocols.h"#include "gnunet_time_lib.h"#include "statistics.h"Go to the source code of this file.
| Data Structures | |
| struct | WatchEntry | 
| Watch entry.  More... | |
| struct | StatsEntry | 
| Entry in the statistics list.  More... | |
| struct | SubsystemEntry | 
| We keep the statistics organized by subsystem for faster lookup during SET operations.  More... | |
| struct | ClientEntry | 
| Information about one of our clients.  More... | |
| Functions | |
| static void | save () | 
| Write persistent statistics to disk. | |
| static void | transmit (struct ClientEntry *ce, const struct StatsEntry *e) | 
| Transmit the given stats value. | |
| static void * | client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq) | 
| Callback called when a client connects to the service. | |
| static int | check_get (void *cls, const struct GNUNET_MessageHeader *message) | 
| Check integrity of GET-message. | |
| static void | handle_get (void *cls, const struct GNUNET_MessageHeader *message) | 
| Handle GET-message. | |
| static void | notify_change (struct StatsEntry *se) | 
| Notify all clients listening about a change to a value. | |
| static struct SubsystemEntry * | find_subsystem_entry (struct ClientEntry *ce, const char *service) | 
| Find the subsystem entry of the given name for the specified client. | |
| static struct StatsEntry * | find_stat_entry (struct SubsystemEntry *se, const char *name) | 
| Find the statistics entry of the given subsystem. | |
| static int | check_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg) | 
| Check format of SET-message. | |
| static void | handle_set (void *cls, const struct GNUNET_STATISTICS_SetMessage *msg) | 
| Handle SET-message. | |
| static int | check_watch (void *cls, const struct GNUNET_MessageHeader *message) | 
| Check integrity of WATCH-message. | |
| static void | handle_watch (void *cls, const struct GNUNET_MessageHeader *message) | 
| Handle WATCH-message. | |
| static void | handle_disconnect (void *cls, const struct GNUNET_MessageHeader *message) | 
| Handle DISCONNECT-message. | |
| static void | do_shutdown () | 
| Actually perform the shutdown. | |
| static void | shutdown_task (void *cls) | 
| Task run during shutdown. | |
| static void | client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_cls) | 
| A client disconnected. | |
| static int | inject_message (void *cls, const struct GNUNET_MessageHeader *message) | 
| We've read a struct GNUNET_STATISTICS_SetMessage *from disk. | |
| static void | load () | 
| Load persistent values from disk. | |
| static void | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service) | 
| Process statistics requests. | |
| GNUNET_SERVICE_MAIN (GNUNET_OS_project_data_gnunet(), "statistics", GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(set, GNUNET_MESSAGE_TYPE_STATISTICS_SET, struct GNUNET_STATISTICS_SetMessage, NULL), GNUNET_MQ_hd_var_size(get, GNUNET_MESSAGE_TYPE_STATISTICS_GET, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_var_size(watch, GNUNET_MESSAGE_TYPE_STATISTICS_WATCH, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_fixed_size(disconnect, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_handler_end()) | |
| Define "main" method using service macro. | |
| Variables | |
| static const struct GNUNET_CONFIGURATION_Handle * | cfg | 
| Our configuration. | |
| static struct SubsystemEntry * | sub_head | 
| Head of linked list of subsystems with active statistics. | |
| static struct SubsystemEntry * | sub_tail | 
| Tail of linked list of subsystems with active statistics. | |
| static unsigned int | client_count | 
| Number of connected clients. | |
| static struct GNUNET_NotificationContext * | nc | 
| Our notification context. | |
| static uint32_t | uidgen | 
| Counter used to generate unique values. | |
| static int | in_shutdown | 
| Set to GNUNET_YES if we are shutting down as soon as possible. | |
program that tracks statistics
Definition in file gnunet-service-statistics.c.
| 
 | static | 
Write persistent statistics to disk.
Definition at line 237 of file gnunet-service-statistics.c.
References _, cfg, GNUNET_assert, GNUNET_BIO_write(), GNUNET_BIO_write_close(), GNUNET_BIO_write_open_file(), GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONTAINER_DLL_remove, GNUNET_DISK_directory_create_for_file(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_htonll(), GNUNET_log, GNUNET_log_config_missing(), GNUNET_log_strerror_file, GNUNET_malloc, GNUNET_MESSAGE_TYPE_STATISTICS_SET, GNUNET_OK, GNUNET_STATISTICS_SETFLAG_PERSISTENT, GNUNET_STRINGS_buffer_fill(), msg, StatsEntry::name, StatsEntry::persistent, SubsystemEntry::service, GNUNET_MessageHeader::size, size, SubsystemEntry::stat_head, SubsystemEntry::stat_tail, sub_head, sub_tail, GNUNET_MessageHeader::type, and StatsEntry::value.
Referenced by do_shutdown(), GNUNET_STRINGS_parse_ipv6_policy(), iterate_save_entries(), iterate_save_epochs(), iterate_save_links(), iterate_save_messages(), and save_message_store().
| 
 | static | 
Transmit the given stats value.
| ce | receiver of the value | 
| e | value to transmit | 
Definition at line 328 of file gnunet-service-statistics.c.
References env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_htonll(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_MESSAGE_TYPE_STATISTICS_VALUE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_STATISTICS_PERSIST_BIT, GNUNET_STRINGS_buffer_fill(), m, ClientEntry::mq, StatsEntry::name, StatsEntry::persistent, SubsystemEntry::service, size, StatsEntry::subsystem, StatsEntry::uid, and StatsEntry::value.
Referenced by handle_get().
| 
 | static | 
Callback called when a client connects to the service.
| cls | closure for the service | 
| c | the new client that connected to the service | 
| mq | the message queue used to send messages to the client | 
Definition at line 365 of file gnunet-service-statistics.c.
References ClientEntry::client, client_count, GNUNET_new, GNUNET_notification_context_add(), mq, ClientEntry::mq, and nc.
| 
 | static | 
Check integrity of GET-message.
| cls | identification of the client | 
| message | the actual message | 
Definition at line 388 of file gnunet-service-statistics.c.
References GNUNET_break, GNUNET_OK, GNUNET_STRINGS_buffer_tokenize(), GNUNET_SYSERR, name, service, GNUNET_MessageHeader::size, and size.
| 
 | static | 
Handle GET-message.
| cls | identification of the client | 
| message | the actual message | 
Definition at line 415 of file gnunet-service-statistics.c.
References ClientEntry::client, end, env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_STATISTICS_END, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_SERVICE_client_continue(), GNUNET_STRINGS_buffer_tokenize(), ClientEntry::mq, name, StatsEntry::name, StatsEntry::next, SubsystemEntry::next, service, SubsystemEntry::service, GNUNET_MessageHeader::size, size, SubsystemEntry::stat_head, sub_head, and transmit().
| 
 | static | 
Notify all clients listening about a change to a value.
| se | value that changed | 
Definition at line 464 of file gnunet-service-statistics.c.
References WatchEntry::ce, env, GNUNET_STATISTICS_WatchValueMessage::flags, GNUNET_htonll(), GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_STATISTICS_SETFLAG_PERSISTENT, GNUNET_YES, WatchEntry::last_value, WatchEntry::last_value_set, ClientEntry::mq, WatchEntry::next, StatsEntry::persistent, GNUNET_STATISTICS_WatchValueMessage::reserved, StatsEntry::value, GNUNET_STATISTICS_WatchValueMessage::value, StatsEntry::we_head, WatchEntry::wid, and GNUNET_STATISTICS_WatchValueMessage::wid.
Referenced by handle_set(), and handle_watch().
| 
 | static | 
Find the subsystem entry of the given name for the specified client.
| ce | client looking for the subsystem, may contain a hint to find the entry faster, can be NULL | 
| service | name of the subsystem to look for | 
Definition at line 502 of file gnunet-service-statistics.c.
References GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, SubsystemEntry::next, service, SubsystemEntry::service, sub_head, sub_tail, and ClientEntry::subsystem.
Referenced by handle_set(), and handle_watch().
| 
 | static | 
Find the statistics entry of the given subsystem.
| se | subsystem to look in | 
| name | name of the entry to look for | 
Definition at line 543 of file gnunet-service-statistics.c.
References name, StatsEntry::name, StatsEntry::next, and SubsystemEntry::stat_head.
Referenced by handle_set(), and handle_watch().
| 
 | static | 
Check format of SET-message.
| cls | the struct ClientEntry | 
| msg | the actual message | 
Definition at line 562 of file gnunet-service-statistics.c.
References GNUNET_break, GNUNET_OK, GNUNET_STRINGS_buffer_tokenize(), GNUNET_SYSERR, msg, name, service, and GNUNET_MessageHeader::size.
Referenced by inject_message().
| 
 | static | 
Handle SET-message.
| cls | the struct ClientEntry | 
| msg | the actual message | 
Definition at line 589 of file gnunet-service-statistics.c.
References ClientEntry::client, delta, find_stat_entry(), find_subsystem_entry(), GNUNET_STATISTICS_SetMessage::flags, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_ntohll(), GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_SETFLAG_PERSISTENT, GNUNET_STATISTICS_SETFLAG_RELATIVE, GNUNET_STRINGS_buffer_tokenize(), GNUNET_YES, msg, name, StatsEntry::name, notify_change(), StatsEntry::persistent, service, StatsEntry::set, GNUNET_MessageHeader::size, size, SubsystemEntry::stat_head, SubsystemEntry::stat_tail, StatsEntry::subsystem, StatsEntry::uid, uidgen, value, and StatsEntry::value.
Referenced by inject_message().
| 
 | static | 
Check integrity of WATCH-message.
| cls | the struct ClientEntry * | 
| message | the actual message | 
Definition at line 705 of file gnunet-service-statistics.c.
References GNUNET_break, GNUNET_OK, GNUNET_STRINGS_buffer_tokenize(), GNUNET_SYSERR, name, service, GNUNET_MessageHeader::size, and size.
| 
 | static | 
Handle WATCH-message.
| cls | the struct ClientEntry * | 
| message | the actual message | 
Definition at line 732 of file gnunet-service-statistics.c.
References WatchEntry::ce, ClientEntry::client, find_stat_entry(), find_subsystem_entry(), GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_SERVICE_client_mark_monitor(), GNUNET_STRINGS_buffer_tokenize(), WatchEntry::last_value_set, ClientEntry::max_wid, name, StatsEntry::name, nc, notify_change(), service, StatsEntry::set, GNUNET_MessageHeader::size, size, SubsystemEntry::stat_head, SubsystemEntry::stat_tail, StatsEntry::subsystem, StatsEntry::uid, uidgen, StatsEntry::value, StatsEntry::we_head, StatsEntry::we_tail, and WatchEntry::wid.
| 
 | static | 
Handle DISCONNECT-message.
Sync to disk and send back a GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM message.
| cls | the struct ClientEntry * | 
| message | the actual message | 
Definition at line 800 of file gnunet-service-statistics.c.
References ClientEntry::client, env, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_SERVICE_client_continue(), ClientEntry::mq, and msg.
| 
 | static | 
Actually perform the shutdown.
Definition at line 816 of file gnunet-service-statistics.c.
References client_count, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_notification_context_destroy(), nc, save(), SubsystemEntry::stat_head, SubsystemEntry::stat_tail, sub_head, sub_tail, StatsEntry::we_head, and StatsEntry::we_tail.
Referenced by client_disconnect_cb(), and shutdown_task().
| 
 | static | 
Task run during shutdown.
| cls | unused | 
Definition at line 853 of file gnunet-service-statistics.c.
References client_count, do_shutdown(), GNUNET_YES, and in_shutdown.
| 
 | static | 
A client disconnected.
Remove all of its data structure entries.
| cls | closure, NULL | 
| client | identification of the client | 
| app_cls | the struct ClientEntry * | 
Definition at line 870 of file gnunet-service-statistics.c.
References WatchEntry::ce, client_count, do_shutdown(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_YES, in_shutdown, WatchEntry::next, StatsEntry::next, SubsystemEntry::next, SubsystemEntry::stat_head, sub_head, StatsEntry::we_head, and StatsEntry::we_tail.
| 
 | static | 
We've read a struct GNUNET_STATISTICS_SetMessage * from disk. 
Check that it is well-formed, and if so pass it to the handler for set messages.
| cls | NULL | 
| message | the message found on disk | 
Definition at line 914 of file gnunet-service-statistics.c.
References check_set(), GNUNET_break, GNUNET_OK, GNUNET_SYSERR, handle_set(), and GNUNET_MessageHeader::size.
Referenced by load().
| 
 | static | 
Load persistent values from disk.
Disk format is exactly the same format that we also use for setting the values over the network.
Definition at line 936 of file gnunet-service-statistics.c.
References _, cfg, GNUNET_BIO_read(), GNUNET_BIO_read_close(), GNUNET_BIO_read_open_file(), GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_DISK_file_size(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_log_strerror_file, GNUNET_malloc, GNUNET_MST_create(), GNUNET_MST_destroy(), GNUNET_MST_from_buffer(), GNUNET_NO, GNUNET_OK, GNUNET_YES, inject_message(), and GNUNET_MessageStreamTokenizer::off.
Referenced by calculate_load(), GNUNET_LOAD_get_average(), GNUNET_LOAD_get_load(), GNUNET_LOAD_update(), GNUNET_LOAD_value_set_decline(), internal_update(), and run().
| 
 | static | 
Process statistics requests.
| cls | closure | 
| c | configuration to use | 
| service | the initialized service | 
Definition at line 1000 of file gnunet-service-statistics.c.
References cfg, GNUNET_notification_context_create(), GNUNET_SCHEDULER_add_shutdown(), load(), nc, GNUNET_MessageStreamTokenizer::off, and shutdown_task.
| GNUNET_SERVICE_MAIN | ( | GNUNET_OS_project_data_gnunet() | , | 
| "statistics" | , | ||
| GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN | , | ||
| & | run, | ||
| & | client_connect_cb, | ||
| & | client_disconnect_cb, | ||
| NULL | , | ||
| GNUNET_MQ_hd_var_size(set, GNUNET_MESSAGE_TYPE_STATISTICS_SET, struct GNUNET_STATISTICS_SetMessage, NULL) | , | ||
| GNUNET_MQ_hd_var_size(get, GNUNET_MESSAGE_TYPE_STATISTICS_GET, struct GNUNET_MessageHeader, NULL) | , | ||
| GNUNET_MQ_hd_var_size(watch, GNUNET_MESSAGE_TYPE_STATISTICS_WATCH, struct GNUNET_MessageHeader, NULL) | , | ||
| GNUNET_MQ_hd_fixed_size(disconnect, GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT, struct GNUNET_MessageHeader, NULL) | , | ||
| GNUNET_MQ_handler_end() | |||
| ) | 
Define "main" method using service macro.
| 
 | static | 
Our configuration.
Definition at line 200 of file gnunet-service-statistics.c.
| 
 | static | 
Head of linked list of subsystems with active statistics.
Definition at line 205 of file gnunet-service-statistics.c.
Referenced by client_disconnect_cb(), do_shutdown(), find_subsystem_entry(), handle_get(), and save().
| 
 | static | 
Tail of linked list of subsystems with active statistics.
Definition at line 210 of file gnunet-service-statistics.c.
Referenced by do_shutdown(), find_subsystem_entry(), and save().
| 
 | static | 
Number of connected clients.
Definition at line 215 of file gnunet-service-statistics.c.
Referenced by client_connect_cb(), client_disconnect_cb(), do_shutdown(), and shutdown_task().
| 
 | static | 
Our notification context.
Definition at line 220 of file gnunet-service-statistics.c.
Referenced by client_connect_cb(), do_shutdown(), handle_watch(), and run().
| 
 | static | 
Counter used to generate unique values.
Definition at line 225 of file gnunet-service-statistics.c.
Referenced by handle_set(), and handle_watch().
| 
 | static | 
Set to GNUNET_YES if we are shutting down as soon as possible.
Definition at line 230 of file gnunet-service-statistics.c.
Referenced by client_disconnect_cb(), and shutdown_task().