various: log memory events

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I6a6a69643b6d00277bb9bcfeb4cd01dc78d7cd3d
This commit is contained in:
raf 2025-09-30 20:11:06 +03:00
commit bc77b887ad
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
7 changed files with 280 additions and 47 deletions

View file

@ -78,6 +78,9 @@ static int add_output_mapping(chroma_config_t *config, const char *output_name,
config->mapping_count++;
chroma_log("DEBUG", "Added mapping: %s -> %s", output_name, image_path);
chroma_log("TRACE", "Output mapping %d: '%s' -> '%s' (path length: %zu)",
config->mapping_count, output_name, image_path,
strlen(image_path));
return CHROMA_OK;
}
@ -138,11 +141,16 @@ static int parse_config_line(chroma_config_t *config, char *line,
strncpy(config->default_image, value, sizeof(config->default_image) - 1);
config->default_image[sizeof(config->default_image) - 1] = '\0';
chroma_log("DEBUG", "Set default image: %s", value);
chroma_log("TRACE", "Default image path set: length=%zu, expanded='%s'",
strlen(value), value);
} else if (strcasecmp(key, "daemon") == 0 ||
strcasecmp(key, "daemon_mode") == 0) {
config->daemon_mode = parse_bool(value);
chroma_log("DEBUG", "Set daemon mode: %s",
config->daemon_mode ? "true" : "false");
chroma_log("TRACE",
"Daemon mode configuration: key='%s', value='%s', parsed=%s",
key, value, config->daemon_mode ? "true" : "false");
} else if (strncasecmp(key, "output.", 7) == 0) {
// Output-specific mapping: e.g., output.DP-1=/path/to/image.jpg
const char *output_name = key + 7;
@ -167,6 +175,8 @@ static int parse_config_line(chroma_config_t *config, char *line,
} else {
chroma_log("WARN", "Unknown configuration key line %d: %s", line_number,
key);
chroma_log("TRACE", "Unrecognized config line %d: key='%s', value='%s'",
line_number, key, value);
}
return CHROMA_OK;
@ -200,6 +210,9 @@ int chroma_config_load(chroma_config_t *config, const char *config_file) {
}
chroma_log("INFO", "Loading configuration from: %s", config_file);
chroma_log("TRACE",
"Starting configuration parsing, estimated config size: %ld bytes",
chroma_get_file_size(config_file));
char line[1024];
int line_number = 0;
@ -229,6 +242,14 @@ int chroma_config_load(chroma_config_t *config, const char *config_file) {
"Loaded configuration: %d output mappings, default image: %s",
config->mapping_count, config->default_image);
// Log configuration memory usage
size_t config_size =
sizeof(chroma_config_t) +
(config->mapping_count * sizeof(chroma_config_mapping_t));
chroma_log_resource_allocation("config_data", config_size,
"configuration structure");
chroma_log_memory_stats("post-config-load");
return CHROMA_OK;
}
@ -238,6 +259,15 @@ void chroma_config_free(chroma_config_t *config) {
return;
}
// Log configuration deallocation
size_t config_size =
sizeof(chroma_config_t) +
(config->mapping_count * sizeof(chroma_config_mapping_t));
chroma_log_resource_deallocation("config_data", config_size,
"configuration structure");
chroma_log("TRACE", "Clearing %d output mappings from configuration",
config->mapping_count);
memset(config->mappings, 0, sizeof(config->mappings));
config->mapping_count = 0;
@ -321,6 +351,10 @@ void chroma_config_print(const chroma_config_t *config) {
for (int i = 0; i < config->mapping_count; i++) {
chroma_log("INFO", " %s -> %s", config->mappings[i].output_name,
config->mappings[i].image_path);
chroma_log(
"TRACE", " Mapping %d: output='%s', image='%s', path_exists=%s", i,
config->mappings[i].output_name, config->mappings[i].image_path,
chroma_path_exists(config->mappings[i].image_path) ? "yes" : "no");
}
chroma_log("INFO", "====================");
}