TEST(util, histogram) { print("******************************************* testHistogram\r\n"); initHistogramsModule(); ASSERT_EQ(80, histogramGetIndex(239)); ASSERT_EQ(223, histogramGetIndex(239239)); ASSERT_EQ(364, histogramGetIndex(239239239)); histogram_s h; initHistogram(&h, "test"); int result[5]; ASSERT_EQ(0, hsReport(&h, result)); hsAdd(&h, 10); ASSERT_EQ(1, hsReport(&h, result)); ASSERT_EQ(10, result[0]); // let's add same value one more time hsAdd(&h, 10); ASSERT_EQ(2, hsReport(&h, result)); ASSERT_EQ(10, result[0]); ASSERT_EQ(10, result[1]); hsAdd(&h, 10); hsAdd(&h, 10); hsAdd(&h, 10); hsAdd(&h, 1000); hsAdd(&h, 100); ASSERT_EQ(5, hsReport(&h, result)); ASSERT_EQ(5, result[0]); ASSERT_EQ(10, result[1]); ASSERT_EQ(10, result[2]); ASSERT_EQ(100, result[3]); // values are not expected to be exactly the same, it's the shape what matters ASSERT_EQ(1011, result[4]); }
/** * @brief This function knows how to print a histogram_s summary */ void printHistogram(Logging *logging, histogram_s *histogram) { int report[5]; int len = hsReport(histogram, report); resetLogging(logging); appendMsgPrefix(logging); appendPrintf(logging, "histogram %s *", histogram->name); for (int i = 0; i < len; i++) appendPrintf(logging, "%d ", report[i]); appendPrintf(logging, "*"); appendMsgPostfix(logging); scheduleLogging(logging); }
/** * @brief This function knows how to print a histogram_s summary */ void printHistogram(Logging *logging, histogram_s *histogram) { #if EFI_HISTOGRAMS && ! EFI_UNIT_TEST int report[5]; int len = hsReport(histogram, report); resetLogging(logging); appendMsgPrefix(logging); appendPrintf(logging, "histogram %s *", histogram->name); for (int i = 0; i < len; i++) appendPrintf(logging, "%d ", report[i]); appendPrintf(logging, "*"); appendMsgPostfix(logging); scheduleLogging(logging); #else UNUSED(logging); UNUSED(histogram); #endif /* EFI_HISTOGRAMS */ }