Compare commits

..

3 Commits

Author SHA1 Message Date
J. Nick Koston
5934b88d2e Merge remote-tracking branch 'upstream/dev' into statsd_stack 2026-01-16 11:35:55 -10:00
J. Nick Koston
5ce4b0c445 tweak 2026-01-16 11:35:52 -10:00
J. Nick Koston
0ea5d7abff [statsd] Use direct appends and stack buffer instead of str_sprintf 2026-01-14 15:27:04 -10:00
2 changed files with 30 additions and 8 deletions

View File

@@ -114,14 +114,23 @@ void StatsdComponent::update() {
// This implies you can't explicitly set a gauge to a negative number without first setting it to zero.
if (val < 0) {
if (this->prefix_) {
out.append(str_sprintf("%s.", this->prefix_));
out.append(this->prefix_);
out.append(".");
}
out.append(str_sprintf("%s:0|g\n", s.name));
out.append(s.name);
out.append(":0|g\n");
}
if (this->prefix_) {
out.append(str_sprintf("%s.", this->prefix_));
out.append(this->prefix_);
out.append(".");
}
out.append(str_sprintf("%s:%f|g\n", s.name, val));
out.append(s.name);
// Buffer for ":" + value + "|g\n".
// %g uses max 13 chars for value (sign + 6 significant digits + e+xxx)
// Total: 1 + 13 + 4 = 18 chars + null, use 24 for safety
char val_buf[24];
buf_append_printf(val_buf, sizeof(val_buf), 0, ":%g|g\n", val);
out.append(val_buf);
if (out.length() > SEND_THRESHOLD) {
this->send_(&out);

View File

@@ -1178,7 +1178,11 @@ std::string WebServer::date_json_(datetime::DateEntity *obj, JsonDetail start_co
// Format: YYYY-MM-DD (max 10 chars + null)
char value[12];
buf_append_printf(value, sizeof(value), 0, "%d-%02d-%02d", obj->year, obj->month, obj->day);
#ifdef USE_ESP8266
snprintf_P(value, sizeof(value), PSTR("%d-%02d-%02d"), obj->year, obj->month, obj->day);
#else
snprintf(value, sizeof(value), "%d-%02d-%02d", obj->year, obj->month, obj->day);
#endif
set_json_icon_state_value(root, obj, "date", value, value, start_config);
if (start_config == DETAIL_ALL) {
this->add_sorting_info_(root, obj);
@@ -1237,7 +1241,11 @@ std::string WebServer::time_json_(datetime::TimeEntity *obj, JsonDetail start_co
// Format: HH:MM:SS (8 chars + null)
char value[12];
buf_append_printf(value, sizeof(value), 0, "%02d:%02d:%02d", obj->hour, obj->minute, obj->second);
#ifdef USE_ESP8266
snprintf_P(value, sizeof(value), PSTR("%02d:%02d:%02d"), obj->hour, obj->minute, obj->second);
#else
snprintf(value, sizeof(value), "%02d:%02d:%02d", obj->hour, obj->minute, obj->second);
#endif
set_json_icon_state_value(root, obj, "time", value, value, start_config);
if (start_config == DETAIL_ALL) {
this->add_sorting_info_(root, obj);
@@ -1296,8 +1304,13 @@ std::string WebServer::datetime_json_(datetime::DateTimeEntity *obj, JsonDetail
// Format: YYYY-MM-DD HH:MM:SS (max 19 chars + null)
char value[24];
buf_append_printf(value, sizeof(value), 0, "%d-%02d-%02d %02d:%02d:%02d", obj->year, obj->month, obj->day, obj->hour,
obj->minute, obj->second);
#ifdef USE_ESP8266
snprintf_P(value, sizeof(value), PSTR("%d-%02d-%02d %02d:%02d:%02d"), obj->year, obj->month, obj->day, obj->hour,
obj->minute, obj->second);
#else
snprintf(value, sizeof(value), "%d-%02d-%02d %02d:%02d:%02d", obj->year, obj->month, obj->day, obj->hour, obj->minute,
obj->second);
#endif
set_json_icon_state_value(root, obj, "datetime", value, value, start_config);
if (start_config == DETAIL_ALL) {
this->add_sorting_info_(root, obj);