From patchwork Tue Apr 16 13:51:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 236986 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4C9A32C00DC for ; Wed, 17 Apr 2013 00:41:27 +1000 (EST) Received: from localhost ([::1]:57270 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US74X-0004tA-JI for incoming@patchwork.ozlabs.org; Tue, 16 Apr 2013 10:41:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US6vH-00075y-8v for qemu-devel@nongnu.org; Tue, 16 Apr 2013 10:31:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1US6dD-00017T-4A for qemu-devel@nongnu.org; Tue, 16 Apr 2013 10:13:15 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:44895) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US6I1-0003av-1L for qemu-devel@nongnu.org; Tue, 16 Apr 2013 09:51:17 -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 r3GDpGs4030908 for ; Tue, 16 Apr 2013 15:51:16 +0200 Received: from localhost (unknown [84.88.51.85]) by gw.ac.upc.edu (Postfix) with ESMTP id 064406B01C9 for ; Tue, 16 Apr 2013 15:51:16 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Tue, 16 Apr 2013 15:51:15 +0200 Message-Id: <20130416135115.21588.60152.stgit@fimbulvetr.bsc.es> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <20130416134949.21588.80064.stgit@fimbulvetr.bsc.es> References: <20130416134949.21588.80064.stgit@fimbulvetr.bsc.es> User-Agent: StGit/0.16 MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id r3GDpGs4030908 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 147.83.33.10 Subject: [Qemu-devel] [PATCH v2 15/23] instrument: [qmp, qapi] Add control interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add QMP commands to control (un)loading of dynamic instrumentation library. Signed-off-by: Lluís Vilanova --- include/qapi/qmp/qerror.h | 9 +++++ instrument/Makefile.objs | 1 + instrument/qapi-schema.json | 33 ++++++++++++++++++++ instrument/qmp.c | 70 ++++++++++++++++++++++++++++++++++++++++++ qapi-schema.json | 2 + qmp-commands.hx | 71 +++++++++++++++++++++++++++++++++++++++++++ qmp.c | 4 ++ 7 files changed, 190 insertions(+) create mode 100644 instrument/qapi-schema.json create mode 100644 instrument/qmp.c diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h index 6c0a18d..67b4528 100644 --- a/include/qapi/qmp/qerror.h +++ b/include/qapi/qmp/qerror.h @@ -129,6 +129,15 @@ void assert_no_error(Error *err); #define QERR_FEATURE_DISABLED \ ERROR_CLASS_GENERIC_ERROR, "The feature '%s' is not enabled" +#define QERR_INSTR_LOAD_DL \ + ERROR_CLASS_GENERIC_ERROR, "Error loading dynamic library: %s" + +#define QERR_INSTR_LOAD_LOADED \ + ERROR_CLASS_GENERIC_ERROR, "Already loaded" + +#define QERR_INSTR_LOAD_UNLOADED \ + ERROR_CLASS_GENERIC_ERROR, "Already unloaded" + #define QERR_INVALID_BLOCK_FORMAT \ ERROR_CLASS_GENERIC_ERROR, "Invalid block format '%s'" diff --git a/instrument/Makefile.objs b/instrument/Makefile.objs index 02cc5b7..e3d4e9b 100644 --- a/instrument/Makefile.objs +++ b/instrument/Makefile.objs @@ -68,3 +68,4 @@ endif target-obj-y += control.o common-obj-$(CONFIG_SOFTMMU) += hmp.o +common-obj-$(CONFIG_SOFTMMU) += qmp.o diff --git a/instrument/qapi-schema.json b/instrument/qapi-schema.json new file mode 100644 index 0000000..0ecf31f --- /dev/null +++ b/instrument/qapi-schema.json @@ -0,0 +1,33 @@ +# *-*- Mode: Python -*-* + +## +# @instr-dynamic: +# +# Whether dynamic trace instrumentation is available. +# +# Since: 1.5 +## +{ 'command': 'instr-dynamic', + 'returns': 'bool' } + +## +# @instr-load: +# +# Load a dynamic instrumentation library. +# +# @path: path to the dynamic instrumentation library +# @iargs: arguments to the dynamic instrumentation library +# +# Since: 1.5 +## +{ 'command': 'instr-load', + 'data': { 'path': 'str', 'iargs': ['String'] } } + +## +# @instr-unload: +# +# Unload the current dynamic instrumentation library. +# +# Since: 1.5 +## +{ 'command': 'instr-unload' } diff --git a/instrument/qmp.c b/instrument/qmp.c new file mode 100644 index 0000000..f744250 --- /dev/null +++ b/instrument/qmp.c @@ -0,0 +1,70 @@ +/* + * QMP interface for dynamic trace instrumentation control commands. + * + * Copyright (C) 2012-2013 Lluís Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu-common.h" +#include "qapi/qmp/qerror.h" +#include "qmp-commands.h" + +#include + +#include "instrument/control.h" + + + +bool qmp_instr_dynamic(Error **errp) +{ + return instr_dynamic(); +} + +void qmp_instr_load(const char * path, StringList * iargs, Error **errp) +{ + int argc = 0; + const char **argv = NULL; + + StringList *entry; + while (entry != NULL) { + argv = realloc(argv, sizeof(*argv) * (argc + 1)); + argv[argc] = entry->value->str; + argc++; + entry = entry->next; + } + + InstrLoadError err = instr_load(path, argc, argv); + switch (err) { + case INSTR_LOAD_OK: + break; + case INSTR_LOAD_UNAVAILABLE: + error_set(errp, QERR_UNSUPPORTED); + break; + case INSTR_LOAD_LOADED: + error_set(errp, QERR_INSTR_LOAD_LOADED); + break; + case INSTR_LOAD_DL: + error_set(errp, QERR_INSTR_LOAD_DL, dlerror()); + break; + } +} + +void qmp_instr_unload(Error **errp) +{ + InstrLoadError err = instr_unload(); + switch (err) { + case INSTR_UNLOAD_OK: + break; + case INSTR_UNLOAD_UNAVAILABLE: + error_set(errp, QERR_UNSUPPORTED); + break; + case INSTR_UNLOAD_UNLOADED: + error_set(errp, QERR_INSTR_LOAD_UNLOADED); + break; + case INSTR_UNLOAD_DL: + error_set(errp, QERR_INSTR_LOAD_DL, dlerror()); + break; + } +} diff --git a/qapi-schema.json b/qapi-schema.json index db542f6..bc5fe06 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3513,3 +3513,5 @@ '*asl_compiler_rev': 'uint32', '*file': 'str', '*data': 'str' }} + +input("instrument/qapi-schema.json") diff --git a/qmp-commands.hx b/qmp-commands.hx index 1e0e11e..1ea6c38 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1510,6 +1510,77 @@ Notes: o Commands that prompt the user for data (eg. 'cont' when the block device is encrypted) don't currently work +instr-dynamic +------------- + +Whether dynamic trace instrumentation is available. + +Arguments: None. + +Example: + +-> { "execute": "instr-dyanmic" } +<- { "return": true } + +EQMP + + { + .name = "instr-dynamic", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_instr_dynamic, + }, + + +SQMP + +instr-load +---------- + +Load a dynamic instrumentation library. + +Arguments: + +- path: path to the dynamic instrumentation library +- args: arguments to the dynamic instrumentation library + +Example: + +-> { "execute": "instr-load", "arguments": { "path": "/tmp/libtrace-instrument.so" } } +<- { "return": {} } + +EQMP + + { + .name = "instr-load", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_instr_load, + }, + + +SQMP + +instr-unload +------------ + +Unload the current dynamic instrumentation library. + +Arguments: None. + +Example: + +-> { "execute": "instr-unload" } +<- { "return": {} } + +EQMP + + { + .name = "instr-unload", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_instr_unload, + }, + + +SQMP 3. Query Commands ================= diff --git a/qmp.c b/qmp.c index 55b056b..72abe03 100644 --- a/qmp.c +++ b/qmp.c @@ -24,6 +24,10 @@ #include "hw/qdev.h" #include "sysemu/blockdev.h" #include "qom/qom-qobject.h" +#if defined(TRACE_INSTRUMENT_DYNAMIC) +#include "instrument/qi-qmp-commands.h" +#endif + NameInfo *qmp_query_name(Error **errp) {