"Daniel P. Berrange" <berra...@redhat.com> writes: > On Fri, Oct 07, 2016 at 03:59:07PM +0200, Markus Armbruster wrote: >> "Daniel P. Berrange" <berra...@redhat.com> writes: >> >> > Allow tracing of the operation of visitors >> > >> > Signed-off-by: Daniel P. Berrange <berra...@redhat.com> >> > --- >> > Makefile.objs | 1 + >> > qapi/qapi-visit-core.c | 27 +++++++++++++++++++++++++++ >> > qapi/trace-events | 33 +++++++++++++++++++++++++++++++++ >> > 3 files changed, 61 insertions(+) >> > create mode 100644 qapi/trace-events >> > >> > diff --git a/Makefile.objs b/Makefile.objs >> > index a8e0224..b3e8aef 100644 >> > --- a/Makefile.objs >> > +++ b/Makefile.objs >> > @@ -160,3 +160,4 @@ trace-events-y += target-s390x/trace-events >> > trace-events-y += target-ppc/trace-events >> > trace-events-y += qom/trace-events >> > trace-events-y += linux-user/trace-events >> > +trace-events-y += qapi/trace-events >> > diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c >> > index 55f5876..bfcb276 100644 >> > --- a/qapi/qapi-visit-core.c >> > +++ b/qapi/qapi-visit-core.c >> > @@ -19,10 +19,12 @@ >> > #include "qapi/qmp/qerror.h" >> > #include "qapi/visitor.h" >> > #include "qapi/visitor-impl.h" >> > +#include "trace.h" >> > >> > void visit_complete(Visitor *v, void *opaque) >> > { >> > assert(v->type != VISITOR_OUTPUT || v->complete); >> > + trace_visit_complete(v, opaque); >> >> Trace after or before checking the precondition? Preferences, anyone? > > I'm ambivalent, as the assert will crash you either way so > whether you get a trace event just before the crash seems > mostly irrelevant to me - the abort stack trace is what > you'll use to diagnose the crash.
I have a slight preference for trace first, because trace is one call, while precondition checking can be several. However, grep shows neither order is prevalent. Not worth a respin. >> > if (v->complete) { >> > v->complete(v, opaque); >> > } >> > @@ -30,6 +32,7 @@ void visit_complete(Visitor *v, void *opaque) >> > >> > void visit_free(Visitor *v) >> > { >> > + trace_visit_free(v); >> > if (v) { >> > v->free(v); >> > } >> > @@ -40,6 +43,7 @@ void visit_start_struct(Visitor *v, const char *name, >> > void **obj, >> > { >> > Error *err = NULL; >> > >> > + trace_visit_start_struct(v, name, obj, size); >> > if (obj) { >> > assert(size); >> > assert(!(v->type & VISITOR_OUTPUT) || *obj); >> > @@ -53,6 +57,7 @@ void visit_start_struct(Visitor *v, const char *name, >> > void **obj, >> > >> > void visit_check_struct(Visitor *v, Error **errp) >> > { >> > + trace_visit_check_struct(v); >> > if (v->check_struct) { >> > v->check_struct(v, errp); >> > } >> > @@ -60,6 +65,7 @@ void visit_check_struct(Visitor *v, Error **errp) >> > >> > void visit_end_struct(Visitor *v, void **obj) >> > { >> > + trace_visit_end_struct(v, obj); >> > v->end_struct(v, obj); >> > } >> > >> > @@ -69,6 +75,7 @@ void visit_start_list(Visitor *v, const char *name, >> > GenericList **list, >> > Error *err = NULL; >> > >> > assert(!list || size >= sizeof(GenericList)); >> > + trace_visit_start_list(v, name, list, size); >> > v->start_list(v, name, list, size, &err); >> > if (list && (v->type & VISITOR_INPUT)) { >> > assert(!(err && *list)); >> > @@ -79,11 +86,13 @@ void visit_start_list(Visitor *v, const char *name, >> > GenericList **list, >> > GenericList *visit_next_list(Visitor *v, GenericList *tail, size_t size) >> > { >> > assert(tail && size >= sizeof(GenericList)); >> > + trace_visit_next_list(v, tail, size); >> > return v->next_list(v, tail, size); >> > } >> > >> > void visit_end_list(Visitor *v, void **obj) >> > { >> > + trace_visit_end_list(v, obj); >> > v->end_list(v, obj); >> > } >> > >> > @@ -95,6 +104,7 @@ void visit_start_alternate(Visitor *v, const char *name, >> > >> > assert(obj && size >= sizeof(GenericAlternate)); >> > assert(!(v->type & VISITOR_OUTPUT) || *obj); >> > + trace_visit_start_alternate(v, name, obj, size, promote_int); >> > if (v->start_alternate) { >> > v->start_alternate(v, name, obj, size, promote_int, &err); >> > } >> > @@ -106,6 +116,7 @@ void visit_start_alternate(Visitor *v, const char >> > *name, >> > >> > void visit_end_alternate(Visitor *v, void **obj) >> > { >> > + trace_visit_end_alternate(v, obj); >> > if (v->end_alternate) { >> > v->end_alternate(v, obj); >> > } >> > @@ -113,6 +124,7 @@ void visit_end_alternate(Visitor *v, void **obj) >> > >> > bool visit_optional(Visitor *v, const char *name, bool *present) >> > { >> > + trace_visit_optional(v, name, present); >> > if (v->optional) { >> > v->optional(v, name, present); >> > } >> > @@ -127,6 +139,7 @@ bool visit_is_input(Visitor *v) >> > void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error >> > **errp) >> > { >> > assert(obj); >> > + trace_visit_type_int(v, name, obj); >> > v->type_int64(v, name, obj, errp); >> > } >> > >> > @@ -151,6 +164,7 @@ void visit_type_uint8(Visitor *v, const char *name, >> > uint8_t *obj, >> > Error **errp) >> > { >> > uint64_t value = *obj; >> > + trace_visit_type_uint8(v, name, obj); >> > visit_type_uintN(v, &value, name, UINT8_MAX, "uint8_t", errp); >> > *obj = value; >> > } >> >> Putting the trace in the middle of the "value = *obj; >> visit_type_uintN(v, &value, ...); *obj = value" pattern makes it less >> visible. >> >> Preserving the pattern requires replacing the initializer by an >> assignment: >> >> uint64_t value; >> >> trace_visit_type_uint8(v, name, obj); >> value = *obj; >> visit_type_uintN(v, &value, name, UINT8_MAX, "uint8_t", errp); >> *obj = value; >> >> Looks slightly more legible to me. What do you think? > > I'm fine with whatever you prefer. I can touch up this one on commit.