[PATCH 3/3] hw/display/qxl.c: Use trace_event_get_state_backends()

Peter Maydell posted 3 patches 6 years ago
Maintainers: Stefan Hajnoczi <stefanha@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
[PATCH 3/3] hw/display/qxl.c: Use trace_event_get_state_backends()
Posted by Peter Maydell 6 years ago
The preferred way to test whether a trace event is enabled is to
use trace_event_get_state_backends(), because this will give the
correct answer (allowing expensive computations to be skipped)
whether the trace event is compile-time or run-time disabled.
Convert the old-style direct use of TRACE_FOO_ENABLED.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/display/qxl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index 6d43b7433cf..80a4dcc40e4 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -1764,7 +1764,7 @@ async_common:
         qxl_set_mode(d, val, 0);
         break;
     case QXL_IO_LOG:
-        if (TRACE_QXL_IO_LOG_ENABLED || d->guestdebug) {
+        if (trace_event_get_state_backends(TRACE_QXL_IO_LOG) || d->guestdebug) {
             /* We cannot trust the guest to NUL terminate d->ram->log_buf */
             char *log_buf = g_strndup((const char *)d->ram->log_buf,
                                       sizeof(d->ram->log_buf));
-- 
2.20.1


Re: [PATCH 3/3] hw/display/qxl.c: Use trace_event_get_state_backends()
Posted by Gerd Hoffmann 6 years ago
On Mon, Jan 20, 2020 at 03:11:42PM +0000, Peter Maydell wrote:
> The preferred way to test whether a trace event is enabled is to
> use trace_event_get_state_backends(), because this will give the
> correct answer (allowing expensive computations to be skipped)
> whether the trace event is compile-time or run-time disabled.
> Convert the old-style direct use of TRACE_FOO_ENABLED.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  hw/display/qxl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/display/qxl.c b/hw/display/qxl.c
> index 6d43b7433cf..80a4dcc40e4 100644
> --- a/hw/display/qxl.c
> +++ b/hw/display/qxl.c
> @@ -1764,7 +1764,7 @@ async_common:
>          qxl_set_mode(d, val, 0);
>          break;
>      case QXL_IO_LOG:
> -        if (TRACE_QXL_IO_LOG_ENABLED || d->guestdebug) {
> +        if (trace_event_get_state_backends(TRACE_QXL_IO_LOG) || d->guestdebug) {

Acked-by: Gerd Hoffmann <kraxel@redhat.com>

>              /* We cannot trust the guest to NUL terminate d->ram->log_buf */
>              char *log_buf = g_strndup((const char *)d->ram->log_buf,
>                                        sizeof(d->ram->log_buf));
> -- 
> 2.20.1
>