X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fevent-notifier-error-accounting.cpp;h=285cdbf5992376d9a975af2049f6ed9894876787;hb=f149493493fbd8a3efa4748832c03278c96c38ca;hp=c99c39338fbe1fbcf6c5237d75fd28fb1fde4b16;hpb=7966af5763c4aaca39df9bbfa9277ff15715c720;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp b/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp index c99c39338..285cdbf59 100644 --- a/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp +++ b/src/bin/lttng-sessiond/event-notifier-error-accounting.cpp @@ -12,19 +12,20 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include -#include "event-notifier-error-accounting.h" -#include "lttng-ust-error.h" -#include "ust-app.h" +#include "event-notifier-error-accounting.hpp" +#include "lttng-ust-error.hpp" +#include "ust-app.hpp" #define ERROR_COUNTER_INDEX_HT_INITIAL_SIZE 16 +namespace { struct index_ht_entry { struct lttng_ht_node_u64 node; uint64_t error_counter_index; @@ -53,10 +54,10 @@ struct kernel_error_accounting_entry { int error_counter_fd; }; -static struct kernel_error_accounting_entry kernel_error_accounting_entry; +struct kernel_error_accounting_entry kernel_error_accounting_entry; /* Hashtable mapping uid to error_account_entry. */ -static struct lttng_ht *error_counter_uid_ht; +struct lttng_ht *error_counter_uid_ht; struct error_accounting_state { struct lttng_index_allocator *index_allocator; @@ -65,8 +66,9 @@ struct error_accounting_state { uint64_t number_indices; }; -static struct error_accounting_state ust_state; -static struct error_accounting_state kernel_state; +struct error_accounting_state ust_state; +struct error_accounting_state kernel_state; +} /* namespace */ static inline void get_trigger_info_for_log(const struct lttng_trigger *trigger, const char **trigger_name, @@ -113,12 +115,14 @@ const char *error_accounting_status_str( } #ifdef HAVE_LIBLTTNG_UST_CTL +namespace { struct event_notifier_counter { pthread_mutex_t lock; long count; }; -static struct event_notifier_counter the_event_notifier_counter; +struct event_notifier_counter the_event_notifier_counter; +} /* namespace */ static void free_ust_error_accounting_entry(struct rcu_head *head) { @@ -369,7 +373,7 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_find( */ static struct ust_error_accounting_entry *ust_error_accounting_entry_create( - struct lttng_ht *uid_ht, const struct ust_app *app) + const struct ust_app *app) { int i, ret, *cpu_counter_fds = NULL; struct lttng_ust_ctl_daemon_counter *daemon_counter; @@ -387,7 +391,7 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create( goto error; } - entry = (ust_error_accounting_entry *) zmalloc(sizeof(struct ust_error_accounting_entry)); + entry = zmalloc(); if (!entry) { PERROR("Failed to allocate event notifier error acounting entry") goto error; @@ -397,7 +401,7 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create( entry->uid = app->uid; entry->nr_counter_cpu_fds = lttng_ust_ctl_get_nr_cpu_per_counter(); - cpu_counter_fds = (int *) zmalloc(entry->nr_counter_cpu_fds * sizeof(*cpu_counter_fds)); + cpu_counter_fds = calloc(entry->nr_counter_cpu_fds); if (!cpu_counter_fds) { PERROR("Failed to allocate event notifier error counter file descriptors array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu", (int) app->uid, app->name, (int) app->pid, @@ -410,7 +414,7 @@ struct ust_error_accounting_entry *ust_error_accounting_entry_create( cpu_counter_fds[i] = -1; } - cpu_counters = (lttng_ust_abi_object_data **) zmalloc(entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *)); + cpu_counters = calloc(entry->nr_counter_cpu_fds); if (!cpu_counters) { PERROR("Failed to allocate event notifier error counter lttng_ust_abi_object_data array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu", (int) app->uid, app->name, (int) app->pid, @@ -611,8 +615,7 @@ event_notifier_error_accounting_register_app(struct ust_app *app) */ pthread_mutex_lock(&the_event_notifier_counter.lock); - entry = ust_error_accounting_entry_create(error_counter_uid_ht, - app); + entry = ust_error_accounting_entry_create(app); if (!entry) { status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_ERR; pthread_mutex_unlock(&the_event_notifier_counter.lock); @@ -654,7 +657,7 @@ event_notifier_error_accounting_register_app(struct ust_app *app) goto error_send_counter_data; } - cpu_counters = (lttng_ust_abi_object_data **) zmalloc(entry->nr_counter_cpu_fds * sizeof(struct lttng_ust_abi_object_data *)); + cpu_counters = calloc(entry->nr_counter_cpu_fds); if (!cpu_counters) { PERROR("Failed to allocate event notifier error counter lttng_ust_abi_object_data array: application uid = %d, application name = '%s', pid = %d, allocation size = %zu", (int) app->uid, app->name, (int) app->pid, @@ -982,6 +985,9 @@ event_notifier_error_accounting_register_kernel( LTTNG_KERNEL_ABI_COUNTER_BITNESS_64, .number_dimensions = 1, .global_sum_step = 0, + .dimensions = {}, + .coalesce_hits = 0, + .padding = {}, }; error_counter_conf.dimensions[0].size = kernel_state.number_indices; error_counter_conf.dimensions[0].has_underflow = false; @@ -1048,7 +1054,7 @@ enum event_notifier_error_accounting_status create_error_counter_index_for_token goto end; } - index_entry = (index_ht_entry *) zmalloc(sizeof(*index_entry)); + index_entry = zmalloc(); if (index_entry == NULL) { PERROR("Failed to allocate event notifier error counter hash table entry"); status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_NOMEM; @@ -1119,8 +1125,8 @@ event_notifier_error_accounting_register_event_notifier( trigger_name, trigger_owner_uid); goto end; } - /* fall-through. */ } + /* fall-through. */ case EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK: *error_counter_index = local_error_counter_index; status = EVENT_NOTIFIER_ERROR_ACCOUNTING_STATUS_OK;