From 4ec966cb67268edfb06b8b803fc73a0e08a1ace5 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Tue, 10 Sep 2024 09:33:32 +0200 Subject: [PATCH] Store loom name in metadata instead of path --- src/emu/loom.c | 28 +++++++++++++++------------- src/emu/loom.h | 3 ++- src/emu/stream.c | 4 ++++ src/emu/system.c | 15 +++++---------- src/rt/ovni.c | 3 +++ 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/emu/loom.c b/src/emu/loom.c index 9e2081f..99ebca8 100644 --- a/src/emu/loom.c +++ b/src/emu/loom.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) +/* Copyright (c) 2021-2024 Barcelona Supercomputing Center (BSC) * SPDX-License-Identifier: GPL-3.0-or-later */ #include "loom.h" @@ -8,15 +8,13 @@ #include "cpu.h" #include "path.h" #include "proc.h" +#include "stream.h" #include "uthash.h" -static const char *loom_prefix = "loom."; - static void set_hostname(char host[PATH_MAX], const char name[PATH_MAX]) { - /* Skip prefix */ - const char *start = name + strlen(loom_prefix); + const char *start = name; /* Copy until dot or end */ int i; @@ -30,10 +28,19 @@ set_hostname(char host[PATH_MAX], const char name[PATH_MAX]) host[i] = '\0'; } -int -loom_matches(const char *path) +const char * +loom_name(struct stream *s) { - return path_has_prefix(path, loom_prefix); + JSON_Object *meta = stream_metadata(s); + const char *loom = json_object_dotget_string(meta, "ovni.loom"); + + if (loom == NULL) { + err("cannot get attribute ovni.loom for stream: %s", + s->relpath); + return NULL; + } + + return loom; } int @@ -41,11 +48,6 @@ loom_init_begin(struct loom *loom, const char *name) { memset(loom, 0, sizeof(struct loom)); - if (!path_has_prefix(name, loom_prefix)) { - err("loom name must start with '%s': %s", loom_prefix, name); - return -1; - } - if (strchr(name, '/') != NULL) { err("loom name cannot contain '/': %s", name); return -1; diff --git a/src/emu/loom.h b/src/emu/loom.h index d175cf1..c8072a2 100644 --- a/src/emu/loom.h +++ b/src/emu/loom.h @@ -12,6 +12,7 @@ #include "cpu.h" #include "extend.h" struct proc; +struct stream; struct loom { int64_t gindex; @@ -50,7 +51,7 @@ struct loom { struct extend ext; }; -USE_RET int loom_matches(const char *relpath); +USE_RET const char *loom_name(struct stream *s); USE_RET int loom_init_begin(struct loom *loom, const char *name); USE_RET int loom_init_end(struct loom *loom); USE_RET int loom_add_cpu(struct loom *loom, struct cpu *cpu); diff --git a/src/emu/stream.c b/src/emu/stream.c index 52f0b59..04aba58 100644 --- a/src/emu/stream.c +++ b/src/emu/stream.c @@ -194,9 +194,13 @@ stream_data_get(struct stream *stream) return stream->data; } +/* Is never NULL */ JSON_Object * stream_metadata(struct stream *stream) { + if (stream->meta == NULL) + die("stream metadata is NULL: %s", stream->relpath); + return stream->meta; } diff --git a/src/emu/system.c b/src/emu/system.c index ec2a803..4e46781 100644 --- a/src/emu/system.c +++ b/src/emu/system.c @@ -131,16 +131,11 @@ find_loom(struct system *sys, const char *id) } static struct loom * -create_loom(struct system *sys, const char *relpath) +create_loom(struct system *sys, struct stream *s) { - char name[PATH_MAX]; - if (snprintf(name, PATH_MAX, "%s", relpath) >= PATH_MAX) { - err("path too long: %s", relpath); - return NULL; - } - - if (strtok(name, "/") == NULL) { - err("cannot find first '/': %s", relpath); + const char *name = loom_name(s); + if (name == NULL) { + err("loom_name failed"); return NULL; } @@ -268,7 +263,7 @@ create_system(struct system *sys, struct trace *trace) continue; } - struct loom *loom = create_loom(sys, s->relpath); + struct loom *loom = create_loom(sys, s); if (loom == NULL) { err("create_loom failed"); return -1; diff --git a/src/rt/ovni.c b/src/rt/ovni.c index dc6b2ac..cccad79 100644 --- a/src/rt/ovni.c +++ b/src/rt/ovni.c @@ -556,6 +556,9 @@ thread_metadata_populate(void) if (json_object_dotset_number(meta, "ovni.pid", (double) rproc.pid) != 0) die("json_object_dotset_number failed"); + + if (json_object_dotset_string(meta, "ovni.loom", rproc.loom) != 0) + die("json_object_dotset_string failed"); } static void