From 641129ad4eb509e6fc10324382562361ccb4e7a2 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Wed, 29 Nov 2017 16:20:37 -0500 Subject: [PATCH] param add perf counters --- src/modules/systemlib/param/param.c | 74 ++++++++++++++++------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/src/modules/systemlib/param/param.c b/src/modules/systemlib/param/param.c index 6e3e87133d..fed6d8e0b0 100644 --- a/src/modules/systemlib/param/param.c +++ b/src/modules/systemlib/param/param.c @@ -41,29 +41,20 @@ * and background parameter saving. */ -//#include -#include -#include -#include -#include -#include -#include +#include "param.h" + #include -#include -#include -#include -#include -#include -#include #include -#include - +#include +#include +#include +#include #include +#include -#include "systemlib/param/param.h" -#include "systemlib/uthash/utarray.h" -#include "systemlib/bson/tinybson.h" +#include +#include //#define PARAM_NO_ORB ///< if defined, avoid uorb dependency. This disables publication of parameter_update on param change //#define PARAM_NO_AUTOSAVE ///< if defined, do not autosave (avoids LP work queue dependency) @@ -171,6 +162,10 @@ static px4_sem_t param_sem; ///< this protects against concurrent access to para static int reader_lock_holders = 0; static px4_sem_t reader_lock_holders_lock; ///< this protects against concurrent access to reader_lock_holders +static perf_counter_t param_export_perf; +static perf_counter_t param_get_perf; +static perf_counter_t param_set_perf; + static px4_sem_t param_sem_save; ///< this protects against concurrent param saves (file or flash access). ///< we use a separate lock to allow concurrent param reads and saves. ///< a param_set could still be blocked by a param save, because it @@ -235,6 +230,10 @@ param_init(void) px4_sem_init(¶m_sem, 0, 1); px4_sem_init(¶m_sem_save, 0, 1); px4_sem_init(&reader_lock_holders_lock, 0, 1); + + param_export_perf = perf_alloc(PC_ELAPSED, "param_export"); + param_get_perf = perf_alloc(PC_ELAPSED, "param_get"); + param_set_perf = perf_alloc(PC_ELAPSED, "param_set"); } /** @@ -579,6 +578,7 @@ param_get(param_t param, void *val) int result = -1; param_lock_reader(); + perf_begin(param_get_perf); const void *v = param_get_value_ptr(param); @@ -587,6 +587,7 @@ param_get(param_t param, void *val) result = 0; } + perf_end(param_get_perf); param_unlock_reader(); return result; @@ -679,13 +680,14 @@ param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_ bool params_changed = false; param_lock_writer(); + perf_begin(param_set_perf); if (param_values == NULL) { utarray_new(param_values, ¶m_icd); } if (param_values == NULL) { - debug("failed to allocate modified values array"); + PX4_ERR("failed to allocate modified values array"); goto out; } @@ -736,7 +738,7 @@ param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_ } if (s->val.p == NULL) { - debug("failed to allocate parameter storage"); + PX4_ERR("failed to allocate parameter storage"); goto out; } } @@ -758,6 +760,7 @@ param_set_internal(param_t param, const void *val, bool mark_saved, bool notify_ } out: + perf_end(param_set_perf); param_unlock_writer(); /* @@ -895,6 +898,7 @@ param_reset_excludes(const char *excludes[], int num_excludes) if ((excludes[index][len - 1] == '*' && strncmp(name, excludes[index], len - 1) == 0) || strcmp(name, excludes[index]) == 0) { + exclude = true; break; } @@ -943,7 +947,7 @@ param_save_default(void) fd = PARAM_OPEN(filename, O_WRONLY | O_CREAT, PX4_O_MODE_666); if (fd < 0) { - warn("failed to open param file: %s", filename); + PX4_ERR("failed to open param file: %s", filename); return ERROR; } @@ -960,7 +964,7 @@ param_save_default(void) } if (res != OK) { - warnx("failed to write parameters to file: %s", filename); + PX4_ERR("failed to write parameters to file: %s", filename); } PARAM_CLOSE(fd); @@ -969,6 +973,7 @@ param_save_default(void) res = flash_param_save(); param_unlock_writer(); #endif + return res; } @@ -1010,6 +1015,8 @@ param_load_default(void) int param_export(int fd, bool only_unsaved) { + perf_begin(param_export_perf); + struct param_wbuf_s *s = NULL; struct bson_encoder_s encoder; int result = -1; @@ -1060,7 +1067,7 @@ param_export(int fd, bool only_unsaved) /* lock as short as possible */ if (bson_encoder_append_int(&encoder, name, i)) { - debug("BSON append failed for '%s'", name); + PX4_ERR("BSON append failed for '%s'", name); goto out; } } @@ -1072,7 +1079,7 @@ param_export(int fd, bool only_unsaved) const char *name = param_name(s->param); if (bson_encoder_append_double(&encoder, name, f)) { - debug("BSON append failed for '%s'", name); + PX4_ERR("BSON append failed for '%s'", name); goto out; } } @@ -1090,14 +1097,15 @@ param_export(int fd, bool only_unsaved) BSON_BIN_BINARY, size, value_ptr)) { - debug("BSON append failed for '%s'", name); + + PX4_ERR("BSON append failed for '%s'", name); goto out; } } break; default: - debug("unrecognized parameter type"); + PX4_ERR("unrecognized parameter type"); goto out; } @@ -1121,6 +1129,8 @@ out: px4_shutdown_unlock(); } + perf_end(param_export_perf); + return result; } @@ -1208,12 +1218,12 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node) } if (tmp == NULL) { - debug("failed allocating for '%s'", node->name); + PX4_ERR("failed allocating for '%s'", node->name); goto out; } if (bson_decoder_copy_data(decoder, tmp)) { - debug("failed copying data for '%s'", node->name); + PX4_ERR("failed copying data for '%s'", node->name); goto out; } @@ -1251,16 +1261,14 @@ static int param_import_internal(int fd, bool mark_saved) { struct bson_decoder_s decoder; - int result = -1; struct param_import_state state; - + int result = -1; if (bson_decoder_init_file(&decoder, fd, param_import_callback, &state)) { - debug("decoder init failed"); + PX4_ERR("decoder init failed"); goto out; } - state.mark_saved = mark_saved; do { @@ -1272,7 +1280,7 @@ param_import_internal(int fd, bool mark_saved) out: if (result < 0) { - debug("BSON error decoding parameters"); + PX4_ERR("BSON error decoding parameters"); } return result;