Received: from eggs.gnu.org ([208.118.235.92]:52274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US6JC-00063z-Un for qemu-devel@nongnu.org; Tue, 16 Apr 2013 09:52:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1US6IJ-0003jN-30 for qemu-devel@nongnu.org; Tue, 16 Apr 2013 09:51:37 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:44913) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US6II-0003ir-LD for qemu-devel@nongnu.org; Tue, 16 Apr 2013 09:51:35 -0400 Received: from gw.ac.upc.edu (gw.ac.upc.es [147.83.30.3]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id r3GDpXt7030932 for ; Tue, 16 Apr 2013 15:51:33 +0200 Received: from localhost (unknown [84.88.51.85]) by gw.ac.upc.edu (Postfix) with ESMTP id 9CB3F6B01C9 for ; Tue, 16 Apr 2013 15:51:33 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova Date: Tue, 16 Apr 2013 15:51:33 +0200 Message-Id: <20130416135133.21588.14232.stgit@fimbulvetr.bsc.es> In-Reply-To: <20130416134949.21588.80064.stgit@fimbulvetr.bsc.es> References: <20130416134949.21588.80064.stgit@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 18/23] instrument: Add client-side API to enumerate events List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Signed-off-by: Llu=C3=ADs Vilanova --- .gitignore | 1=20 Makefile | 1=20 configure | 1=20 instrument/Makefile.objs | 13 +++ instrument/api-control.c | 14 +++ instrument/qemu-instr/control-internal.h | 53 ++++++++++++ instrument/qemu-instr/control.h | 124 +++++++++++++++++++++= ++++++ instrument/qemu-instr/visibility-internal.h | 94 ++++++++++++++++++++ scripts/tracetool/backend/instr_dynamic.py | 3 + scripts/tracetool/backend/instr_none.py | 3 + scripts/tracetool/backend/instr_static.py | 3 + scripts/tracetool/format/api_events_h.py | 56 ++++++++++++ 12 files changed, 366 insertions(+) create mode 100644 instrument/api-control.c create mode 100644 instrument/qemu-instr/control-internal.h create mode 100644 instrument/qemu-instr/control.h create mode 100644 instrument/qemu-instr/visibility-internal.h create mode 100644 scripts/tracetool/format/api_events_h.py diff --git a/.gitignore b/.gitignore index 2a0ea2f..59acb2a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ libcacard/trace/generated-tracers.c instrument/generated-tracers.h instrument/generated-tracers.c instrument/qemu-instr/events.h +instrument/qemu-instr/events-list.h *-timestamp *-softmmu *-darwin-user diff --git a/Makefile b/Makefile index 8280273..7916152 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,7 @@ ifdef CONFIG_TRACE_INSTRUMENT_DYNAMIC GENERATED_SOURCES +=3D instrument/generated-tracers.c endif GENERATED_HEADERS +=3D instrument/qemu-instr/events.h +GENERATED_HEADERS +=3D instrument/qemu-instr/events-list.h =20 GENERATED_HEADERS +=3D trace/generated-events.h GENERATED_SOURCES +=3D trace/generated-events.c diff --git a/configure b/configure index d2e0b90..32142f9 100755 --- a/configure +++ b/configure @@ -301,6 +301,7 @@ QEMU_CFLAGS=3D"-fno-strict-aliasing $QEMU_CFLAGS" QEMU_CFLAGS=3D"-Wall -Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_= CFLAGS" QEMU_CFLAGS=3D"-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" QEMU_CFLAGS=3D"-D_GNU_SOURCE -D_FILE_OFFSET_BITS=3D64 -D_LARGEFILE_SOURC= E $QEMU_CFLAGS" +QEMU_CFLAGS=3D"-DBUILDING_QEMU $QEMU_CFLAGS" QEMU_INCLUDES=3D"-I. -I\$(SRC_PATH) -I\$(SRC_PATH)/include" if test "$debug_info" =3D "yes"; then CFLAGS=3D"-g $CFLAGS" diff --git a/instrument/Makefile.objs b/instrument/Makefile.objs index 453330f..1438626 100644 --- a/instrument/Makefile.objs +++ b/instrument/Makefile.objs @@ -41,6 +41,15 @@ $(obj)/qemu-instr/events.h-timestamp: $(TRACE_EVENTS) = $(BUILD_DIR)/config-host.m < $< > $@," GEN $(patsubst %-timestamp,%,$@)") @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp= ,%,$@) =20 +$(obj)/qemu-instr/events-list.h: $(obj)/qemu-instr/events-list.h-timesta= mp +$(obj)/qemu-instr/events-list.h-timestamp: $(TRACE_EVENTS) $(BUILD_DIR)/= config-host.mak + $(call quiet-command,$(TRACETOOL) \ + --format=3Dapi-events-h \ + --backend=3D$(TRACE_INSTRUMENT_BACKEND) \ + $(TRACETOOL_INSTR_STATIC) \ + < $< > $@," GEN $(patsubst %-timestamp,%,$@)") + @cmp -s $@ $(patsubst %-timestamp,%,$@) || cp $@ $(patsubst %-timestamp= ,%,$@) + =20 ###################################################################### # User code (static instrumentation) @@ -71,3 +80,7 @@ target-obj-y +=3D control.o =20 common-obj-$(CONFIG_SOFTMMU) +=3D hmp.o common-obj-$(CONFIG_SOFTMMU) +=3D qmp.o + +target-obj-y +=3D api-control.o + +QEMU_CFLAGS +=3D -I$(BUILD_DIR)/instrument -I$(SRC_PATH)/instrument diff --git a/instrument/api-control.c b/instrument/api-control.c new file mode 100644 index 0000000..e3aac49 --- /dev/null +++ b/instrument/api-control.c @@ -0,0 +1,14 @@ +/* + * Interface for controlling the state of events. + * + * Copyright (C) 2012-2013 Llu=C3=ADs Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. + * See the COPYING file in the top-level directory. + */ + +#include "instrument/qemu-instr/control.h" + +#if defined(QI_TYPE_DYNAMIC) +#include "instrument/qemu-instr/control-internal.h" +#endif diff --git a/instrument/qemu-instr/control-internal.h b/instrument/qemu-i= nstr/control-internal.h new file mode 100644 index 0000000..6e419e7 --- /dev/null +++ b/instrument/qemu-instr/control-internal.h @@ -0,0 +1,53 @@ +/* + * Interface for controlling the state of events. + * + * Copyright (C) 2012-2013 Llu=C3=ADs Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. + * See the COPYING file in the top-level directory. + */ + +#ifndef QI__CONTROL_INTERNAL_H +#define QI__CONTROL_INTERNAL_H + +#include "trace/control.h" + + +QI_IDEF QIEvent* qi_ctrl_event_id(QIEventID id) +{ + return (QIEvent*)trace_event_id(id); +} + +QI_IDEF QIEvent* qi_ctrl_event_name(const char *name) +{ + return (QIEvent*)trace_event_name(name); +} + +QI_IDEF QIEvent* qi_ctrl_event_pattern(const char *pat, QIEvent *ev) +{ + return (QIEvent*)trace_event_pattern(pat, (TraceEvent*)ev); +} + +QI_IDEF bool qi_ctrl_event_is_pattern(const char *str) +{ + return trace_event_is_pattern(str); +} + +QI_IDEF QIEventID qi_ctrl_event_count(void) +{ + return (QIEventID)trace_event_count(); +} + + + +QI_IDEF QIEventID qi_ctrl_event_get_id(QIEvent *ev) +{ + return (QIEventID)trace_event_get_id((TraceEvent*)ev); +} + +QI_IDEF const char * qi_ctrl_event_get_name(QIEvent *ev) +{ + return trace_event_get_name((TraceEvent*)ev); +} + +#endif /* QI__CONTROL_INTERNAL_H */ diff --git a/instrument/qemu-instr/control.h b/instrument/qemu-instr/cont= rol.h new file mode 100644 index 0000000..d3fadd1 --- /dev/null +++ b/instrument/qemu-instr/control.h @@ -0,0 +1,124 @@ +/* + * Interface for controlling the state of events. + * + * Copyright (C) 2012-2013 Llu=C3=ADs Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. + * See the COPYING file in the top-level directory. + */ + +#ifndef QI__CONTROL_H +#define QI__CONTROL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include +#include + + +/** + * SECTION:control + * @section_id: qi-control + * @title: QEMU instrumentation event control interface + */ + +/** + * QIEvent: + * + * Opaque structure defining an instrumentation event. + */ +struct QIEvent; +typedef struct QIEvent QIEvent; + +/** + * QIEventID: + * + * Unique instrumentation event identifier. + * + * These are named as 'QI_EVENT_${EVENT}'. + * + * See also: qemu-instr/events-list.h + */ + +/** + * qi_ctrl_event_id: + * @id: Event identifier. + * + * Get an event by its identifier. + * + * This routine has a constant cost, as opposed to qi_ctrl_event_name() = and + * qi_ctrl_event_pattern(). + * + * Pre-conditions: @id is valid. + * + * Returns: Pointer to selected #QIEvent. + * + */ +QI_IDECL QIEvent* qi_ctrl_event_id(QIEventID id); + +/** + * qi_ctrl_event_name: + * @id: Event name. + * + * Search an event by its name. + * + * Returns: Pointer to #QIEvent or #NULL if not found. + */ +QI_IDECL QIEvent* qi_ctrl_event_name(const char *name); + +/** + * qi_ctrl_event_pattern: + * @pat: Event name pattern. + * @ev: Event to start searching from (not included). + * + * Iteratively get all events with a given name pattern. + * + * Returns: pointer to #TraceEvent or #NULL if not found. + */ +QI_IDECL QIEvent* qi_ctrl_event_pattern(const char *pat, QIEvent *ev); + +/** + * qi_ctrl_event_is_pattern: + * + * Whether the given string is an event name pattern. + */ +QI_IDECL bool qi_ctrl_event_is_pattern(const char *str); + +/** + * qi_ctrl_event_count: + * + * Return the number of events. + */ +QI_IDECL QIEventID qi_ctrl_event_count(void); + + + +/** + * qi_ctrl_event_get_id: + * + * Get the identifier of an event. + */ +QI_IDECL QIEventID qi_ctrl_event_get_id(QIEvent *ev); + +/** + * qi_ctrl_event_get_name: + * + * Get the name of an event. + */ +QI_IDECL const char * qi_ctrl_event_get_name(QIEvent *ev); + + +#if !defined(QI_TYPE_DYNAMIC) +#include "instrument/qemu-instr/control-internal.h" +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* QI__CONTROL_H */ diff --git a/instrument/qemu-instr/visibility-internal.h b/instrument/qem= u-instr/visibility-internal.h new file mode 100644 index 0000000..f5a66da --- /dev/null +++ b/instrument/qemu-instr/visibility-internal.h @@ -0,0 +1,94 @@ +/* + * Macros for symbol visibility. + * + * Copyright (C) 2012-2013 Llu=C3=ADs Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. + * See the COPYING file in the top-level directory of QEMU. + */ + +#ifndef QI__VISIBILITY_INTERNAL_H +#define QI__VISIBILITY_INTERNAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + +/** + * SECTION:visibility + * @section_id: qi-visibility + * @title: Symbol visibility + * + * This code is taken from http://gcc.gnu.org/wiki/Visibility. + */ + +/** + * QI_VPUBLIC: + * + * Make an element public to third-party code. + */ + +/** + * QI_VLOCAL: + * + * Make an element not visible to third-party code. + */ + +#if defined _WIN32 || defined __CYGWIN__ + #ifdef BUILDING_QEMU + #ifdef __GNUC__ + #define QI_VPUBLIC __attribute__ ((dllexport)) + #else + #define QI_VPUBLIC __declspec(dllexport) + #endif + #else + #ifdef __GNUC__ + #define QI_VPUBLIC __attribute__ ((dllimport)) + #else + #define QI_VPUBLIC __declspec(dllimport) + #endif + #endif + #define QI_VLOCAL +#else + #if __GNUC__ >=3D 4 + #define QI_VPUBLIC __attribute__ ((visibility ("default"))) + #define QI_VLOCAL __attribute__ ((visibility ("hidden"))) + #else + #define QI_VPUBLIC + #define QI_VLOCAL + #endif +#endif + +/** + * QI_IDECL: + * + * Instrumentation-type dependant declaration attribute for inlined rout= ines. + */ + +#if defined(QI_TYPE_DYNAMIC) +#define QI_IDECL QI_VPUBLIC +#else +#define QI_IDECL static +#endif + +/** + * QI_IDEF: + * + * Instrumentation-type dependant definition attribute for inlined routi= nes. + */ + +#if defined(QI_TYPE_DYNAMIC) +#define QI_IDEF +#else +#define QI_IDEF static inline +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /* QI__VISIBILITY_INTERNAL_H */ diff --git a/scripts/tracetool/backend/instr_dynamic.py b/scripts/traceto= ol/backend/instr_dynamic.py index 12d0503..013893a 100644 --- a/scripts/tracetool/backend/instr_dynamic.py +++ b/scripts/tracetool/backend/instr_dynamic.py @@ -88,3 +88,6 @@ def api_c(events): args =3D e.args, argnames =3D ", ".join(e.args.names()), ) + +def api_events_h(events): + pass diff --git a/scripts/tracetool/backend/instr_none.py b/scripts/tracetool/= backend/instr_none.py index a1327c0..2c2fe68 100644 --- a/scripts/tracetool/backend/instr_none.py +++ b/scripts/tracetool/backend/instr_none.py @@ -39,3 +39,6 @@ def api_h(events): qemu_backend =3D e.api(e.QEMU_TRACE_BACKEND), argnames =3D ", ".join(e.args.names()), ) + +def api_events_h(events): + pass diff --git a/scripts/tracetool/backend/instr_static.py b/scripts/tracetoo= l/backend/instr_static.py index ecebbda..df99656 100644 --- a/scripts/tracetool/backend/instr_static.py +++ b/scripts/tracetool/backend/instr_static.py @@ -77,3 +77,6 @@ def api_h(events): argnames =3D ", ".join(e.args.names()), upper_name =3D e.name.upper(), ) + +def api_events_h(events): + pass diff --git a/scripts/tracetool/format/api_events_h.py b/scripts/tracetool= /format/api_events_h.py new file mode 100644 index 0000000..95a4e93 --- /dev/null +++ b/scripts/tracetool/format/api_events_h.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Generate .h with event description for trace instrumentation clients. +""" + +__author__ =3D "Llu=C3=ADs Vilanova " +__copyright__ =3D "Copyright 2012-2013, Llu=C3=ADs Vilanova " +__license__ =3D "GPL version 2 or (at your option) any later version" + +__maintainer__ =3D "Stefan Hajnoczi" +__email__ =3D "stefanha@linux.vnet.ibm.com" + + +from tracetool import out + + +def begin(events): + out('/* This file is autogenerated by tracetool, do not edit. */', + '', + '#ifndef QI__EVENTS_LIST_H', + '#define QI__EVENTS_LIST_H', + '', + '#ifdef __cplusplus', + 'extern "C" {', + '#endif', + '', + ) + + # event identifiers + out('typedef enum {') + + for e in events: + out(' QI_EVENT_%s,' % e.name.upper()) + + out(' QI_EVENT_COUNT', + '} QIEventID;', + '', + ) + + # static state + for e in events: + if 'disable' in e.properties: + enabled =3D 0 + else: + enabled =3D 1 + out('#define QI_EVENT_%s_ENABLED %d' % (e.name.upper(), enabled)= ) + + out('#ifdef __cplusplus', + '}', + '#endif', + '', + '#endif /* QI__EVENTS_LIST_H */', + '', + )