qom: add trace events for object/property lifecycle

This adds tracing around object allocation & finalization, the addition &
deletion of properties, and the addition & deletion of children.

Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé
2026-04-17 15:06:34 +01:00
parent d1ebe4a53a
commit e89cff07a9
2 changed files with 37 additions and 9 deletions

View File

@@ -594,6 +594,8 @@ static void object_property_del_all(Object *obj)
object_property_iter_init(&iter, obj);
while ((prop = object_property_iter_next(&iter)) != NULL) {
if (g_hash_table_add(done, prop)) {
trace_object_property_del(obj, obj->class->type->name,
prop->name, prop->opaque);
if (prop->release) {
prop->release(obj, prop->name, prop->opaque);
released = true;
@@ -612,10 +614,14 @@ static void object_property_del_child(Object *obj, Object *child)
GHashTableIter iter;
gpointer key, value;
trace_object_property_del_child(obj, obj->class->type->name,
child, child->class->type->name);
g_hash_table_iter_init(&iter, obj->properties);
while (g_hash_table_iter_next(&iter, &key, &value)) {
prop = value;
if (object_property_is_child(prop) && prop->opaque == child) {
trace_object_property_del(obj, obj->class->type->name,
prop->name, prop->opaque);
if (prop->release) {
prop->release(obj, prop->name, prop->opaque);
prop->release = NULL;
@@ -655,7 +661,7 @@ static void object_finalize(void *data)
{
Object *obj = data;
TypeImpl *ti = obj->class->type;
trace_object_finalize(obj, obj->class->type->name);
object_property_del_all(obj);
object_deinit(obj, ti);
@@ -705,6 +711,7 @@ static Object *object_new_with_type(Type type)
object_initialize_with_type(obj, size, type);
obj->free = obj_free;
trace_object_new(obj, obj->class->type->name);
return obj;
}
@@ -835,8 +842,9 @@ Object *object_dynamic_cast(Object *obj, const char *typename)
Object *object_dynamic_cast_assert(Object *obj, const char *typename,
const char *file, int line, const char *func)
{
trace_object_dynamic_cast_assert(obj ? obj->class->type->name : "(null)",
typename, file, line, func);
trace_object_dynamic_cast_assert(
obj, obj ? obj->class->type->name : "(null)",
typename, file, line, func);
#ifdef CONFIG_QOM_CAST_DEBUG
int i;
@@ -926,8 +934,9 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
{
ObjectClass *ret;
trace_object_class_dynamic_cast_assert(class ? class->type->name : "(null)",
typename, file, line, func);
trace_object_class_dynamic_cast_assert(
class ? class->type->name : "(null)",
typename, file, line, func);
#ifdef CONFIG_QOM_CAST_DEBUG
int i;
@@ -1211,6 +1220,8 @@ object_property_try_add(Object *obj, const char *name, const char *type,
prop->release = release;
prop->opaque = opaque;
trace_object_property_add(obj, obj->class->type->name,
prop->name, prop->opaque);
g_hash_table_insert(obj->properties, prop->name, prop);
return prop;
}
@@ -1249,6 +1260,8 @@ object_class_property_add(ObjectClass *klass,
prop->release = release;
prop->opaque = opaque;
trace_object_class_property_add(klass->type->name, prop->name,
prop->opaque);
g_hash_table_insert(klass->properties, prop->name, prop);
return prop;
@@ -1337,6 +1350,8 @@ void object_property_del(Object *obj, const char *name)
{
ObjectProperty *prop = g_hash_table_lookup(obj->properties, name);
trace_object_property_del(obj, obj->class->type->name, prop->name,
prop->opaque);
if (prop->release) {
prop->release(obj, name, prop->opaque);
}
@@ -1625,8 +1640,11 @@ int object_property_get_enum(Object *obj, const char *name,
bool object_property_parse(Object *obj, const char *name,
const char *string, Error **errp)
{
Visitor *v = string_input_visitor_new(string);
bool ok = object_property_set(obj, name, v, errp);
Visitor *v;
bool ok;
trace_object_property_parse(obj, obj->class->type->name, name, string);
v = string_input_visitor_new(string);
ok = object_property_set(obj, name, v, errp);
visit_free(v);
return ok;
@@ -1757,6 +1775,8 @@ object_property_try_add_child(Object *obj, const char *name,
g_autofree char *type = NULL;
ObjectProperty *op;
trace_object_property_add_child(obj, obj->class->type->name, name,
child, child->class->type->name);
assert(!child->parent);
type = g_strdup_printf("child<%s>", object_get_typename(child));

View File

@@ -1,5 +1,13 @@
# See docs/devel/tracing.rst for syntax documentation.
# object.c
object_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
object_class_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "%s->%s (%s:%d:%s)"
object_dynamic_cast_assert(void *obj, const char *type, const char *target, const char *file, int line, const char *func) "obj=%p type=%s->%s (%s:%d:%s)"
object_finalize(void *obj, const char *type) "obj=%p type=%s"
object_new(void *obj, const char *type) "obj=%p type=%s"
object_property_add(void *obj, const char *type, const char *name, void *value) "obj=%p type=%s name=%s value=%p"
object_property_add_child(void *obj, const char *type, const char *name, void *child, const char *childtype) "obj=%p type=%s name=%s child=%p child-type=%s"
object_property_del(void *obj, const char *type, const char *name, void *value) "obj=%p type=%s name=%s value=%p"
object_property_del_child(void *obj, const char *type, void *child, const char *childtype) "obj=%p type=%s child=%p child-type=%s"
object_property_parse(void *obj, const char *type, const char *name, const char *value) "obj=%p type=%s prop=%s value=%s"
object_class_dynamic_cast_assert(const char *type, const char *target, const char *file, int line, const char *func) "type=%s->%s (%s:%d:%s)"
object_class_property_add(const char *type, const char *name, void *value) "type=%s name=%s value=%p"