static void print_detailed(const matstat_state_t *states, size_t nelem, unsigned int test_min, const stat_limits_t *limits) { if (LOG2_STATS) { print_str(" interval count sum sum_sq min max mean variance\n"); for (unsigned int k = 0; k < nelem; ++k) { char buf[20]; unsigned int num = (1 << k); if (num >= TEST_NUM) { break; } unsigned int start = num + test_min; if (num == 1) { /* special case, bitarithm_msb will return 0 for both 0 and 1 */ start = test_min; } print(buf, fmt_lpad(buf, fmt_u32_dec(buf, start), 4, ' ')); print_str(" - "); print(buf, fmt_lpad(buf, fmt_u32_dec(buf, test_min + (num * 2) - 1), 4, ' ')); print_str(": "); print_statistics(&states[k], limits); } print_str(" TOTAL "); } else { print_str("interval count sum sum_sq min max mean variance\n"); for (unsigned int k = 0; k < nelem; ++k) { char buf[10]; print(buf, fmt_lpad(buf, fmt_u32_dec(buf, k + test_min), 7, ' ')); print_str(": "); print_statistics(&states[k], limits); } print_str(" TOTAL: "); } print_totals(states, nelem, limits); }
int cord_common_add_qstring(coap_pkt_t *pkt) { /* extend the url with some query string options */ int res = gcoap_add_qstring(pkt, "ep", cord_common_ep); if (res < 0) { return res; } /* [optional] set the lifetime parameter */ #if CORD_LT char lt[11]; lt[fmt_u32_dec(lt, CORD_LT)] = '\0'; res = gcoap_add_qstring(pkt, "lt", lt); if (res < 0) { return res; } #endif /* [optional] set the domain parameter */ #ifdef CORD_D res = gcoap_add_qstring(pkt, "d", CORD_D); if (res < 0) { return res; } #endif return 0; }
static void test_fmt_u32_dec(void) { char out[11] = "----------"; uint32_t val = 12345678; uint8_t chars = 0; chars = fmt_u32_dec(out, val); TEST_ASSERT_EQUAL_INT(8, chars); out[chars] = '\0'; TEST_ASSERT_EQUAL_STRING("12345678", (char *) out); memset(out, '-', sizeof(out)); val = 1234567890; chars = fmt_u32_dec(out, val); TEST_ASSERT_EQUAL_INT(10, chars); out[chars] = '\0'; TEST_ASSERT_EQUAL_STRING("1234567890", (char *) out); }
static void test_fmt_u32_dec(void) { char out[9] = "--------"; uint32_t val = 12345678; uint8_t chars = 0; chars = fmt_u32_dec(out, val); TEST_ASSERT_EQUAL_INT(8, chars); out[chars] = '\0'; TEST_ASSERT_EQUAL_STRING("12345678", (char *) out); }
static void print_statistics(const matstat_state_t *state, const stat_limits_t *limits) { if (state->count == 0) { print_str("no samples\n"); return; } if (state->count == 1) { print_str("single sample: "); print_s32_dec((int32_t)state->sum); print("\n", 1); return; } int32_t mean = matstat_mean(state); uint64_t variance = matstat_variance(state); char buf[20]; print(buf, fmt_lpad(buf, fmt_u32_dec(buf, state->count), 8, ' ')); print(" ", 1); print(buf, fmt_lpad(buf, fmt_s64_dec(buf, state->sum), 9, ' ')); print(" ", 1); print(buf, fmt_lpad(buf, fmt_u64_dec(buf, state->sum_sq), 12, ' ')); print(" ", 1); print(buf, fmt_lpad(buf, fmt_s32_dec(buf, state->min), 6, ' ')); print(" ", 1); print(buf, fmt_lpad(buf, fmt_s32_dec(buf, state->max), 5, ' ')); print(" ", 1); print(buf, fmt_lpad(buf, fmt_s32_dec(buf, mean), 5, ' ')); print(" ", 1); print(buf, fmt_lpad(buf, fmt_u64_dec(buf, variance), 6, ' ')); if (limits) { if ((mean < limits->mean_low) || (limits->mean_high < mean) || (variance < limits->variance_low) || (limits->variance_high < variance) ) { /* mean or variance is outside the expected range, alert the user */ print_str(" <=== SIC!"); } } print("\n", 1); }