minor optimizations

This commit is contained in:
proddy
2025-12-23 23:28:10 +01:00
parent 537cf19e97
commit 790371a9e2

View File

@@ -322,18 +322,16 @@ void System::get_partition_info() {
// Partitions can be app0, app1, factory, boot // Partitions can be app0, app1, factory, boot
esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, nullptr); esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, nullptr);
uint64_t buffer; uint64_t buffer;
bool is_valid;
while (it != nullptr) { while (it != nullptr) {
is_valid = true; bool is_valid = true;
const esp_partition_t * part = esp_partition_get(it); const esp_partition_t * part = esp_partition_get(it);
if (part->label != nullptr && part->label[0] != '\0') { if (part->label != nullptr && part->label[0] != '\0') {
// check if part is valid and not empty // check if part is valid and not empty
esp_partition_read(part, 0, &buffer, 8); esp_partition_read(part, 0, &buffer, 8);
if (buffer == 0xFFFFFFFFFFFFFFFF) { if (buffer == 0xFFFFFFFFFFFFFFFF) {
// skip this partition is_valid = false; // skip this partition
is_valid = false;
} }
} }
@@ -1765,7 +1763,7 @@ std::string System::get_metrics_prometheus() {
for (JsonPair p : obj) { for (JsonPair p : obj) {
std::string key = p.key().c_str(); std::string key = p.key().c_str();
std::string path = prefix.empty() ? key : prefix + "." + key; // std::string path = prefix.empty() ? key : prefix + "." + key;
std::string metric_name = prefix.empty() ? key : prefix + "_" + key; std::string metric_name = prefix.empty() ? key : prefix + "_" + key;
if (should_ignore(prefix, key)) { if (should_ignore(prefix, key)) {
@@ -1898,25 +1896,23 @@ std::string System::get_metrics_prometheus() {
if (!local_info_labels.empty() && !prefix.empty() && !has_nested_objects) { if (!local_info_labels.empty() && !prefix.empty() && !has_nested_objects) {
std::string info_metric = "emsesp_" + sanitize_name(prefix) + "_info"; std::string info_metric = "emsesp_" + sanitize_name(prefix) + "_info";
if (seen_metrics.find(info_metric) == seen_metrics.end()) { if (seen_metrics.find(info_metric) == seen_metrics.end()) {
result += "# HELP " + info_metric + " info\n"; result += "# HELP " + info_metric + " info\n# TYPE " + info_metric + " gauge\n";
result += "# TYPE " + info_metric + " gauge\n";
seen_metrics[info_metric] = true; seen_metrics[info_metric] = true;
} }
result += info_metric; result += info_metric;
if (!local_info_labels.empty()) { result += '{';
result += "{"; for (size_t i = 0; i < local_info_labels.size(); ++i) {
bool first = true; if (i > 0) {
for (const auto & label : local_info_labels) {
if (!first) {
result += ", "; result += ", ";
} }
result += label.first + "=\"" + escape_label(label.second) + "\""; const auto & label = local_info_labels[i];
first = false; result += label.first;
result += "=\"";
result += escape_label(label.second);
result += '"';
} }
result += "}"; result += "} 1\n";
}
result += " 1\n";
} }
}; };