qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Prerna Saxena <prerna@linux.vnet.ibm.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: Ananth Narayan <ananth@linux.vnet.ibm.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [Tracing][PATCH] Add options to specify trace file name at startup and runtime.
Date: Wed, 04 Aug 2010 15:03:48 +0530	[thread overview]
Message-ID: <4C5933FC.2090902@linux.vnet.ibm.com> (raw)
In-Reply-To: <AANLkTi=KF+tGGLpE+WhGczNNxF+R7qBUUcUrAyUmB85X@mail.gmail.com>

On 08/03/2010 07:45 PM, Stefan Hajnoczi wrote:
> On Tue, Aug 3, 2010 at 6:37 AM, Prerna Saxena<prerna@linux.vnet.ibm.com>  wrote:
>> This patch adds an optional command line switch '-trace' to specify the
>> filename to write traces to, when qemu starts.
>> Eg, If compiled with the 'simple' trace backend,
>> [temp@system]$ qemu -trace FILENAME IMAGE
>> Allows the binary traces to be written to FILENAME instead of the option
>> set at config-time.
>>
>> Also, this adds monitor sub-command 'set' to trace-file commands to
>> dynamically change trace log file at runtime.
>> Eg,
>> (qemu)trace-file set FILENAME
>> This allows one to set trace outputs to FILENAME from the default
>> specified at startup.
>>
>> Signed-off-by: Prerna Saxena<prerna@linux.vnet.ibm.com>
>> ---
>>   monitor.c       |    6 ++++++
>>   qemu-monitor.hx |    6 +++---
>>   qemu-options.hx |   11 +++++++++++
>>   simpletrace.c   |   41 ++++++++++++++++++++++++++++++++---------
>>   tracetool       |    1 +
>>   vl.c            |   22 ++++++++++++++++++++++
>>   6 files changed, 75 insertions(+), 12 deletions(-)
>
> Looks like a good approach.  I checked that this also handles the case
> where trace events fire before the command-line option is handled and
> the trace filename is set.
>
>> diff --git a/monitor.c b/monitor.c
>> index 1e35a6b..8e2a3a6 100644
>> --- a/monitor.c
>> +++ b/monitor.c
>> @@ -544,6 +544,7 @@ static void do_change_trace_event_state(Monitor *mon, const QDict *qdict)
>>   static void do_trace_file(Monitor *mon, const QDict *qdict)
>>   {
>>      const char *op = qdict_get_try_str(qdict, "op");
>> +    const char *arg = qdict_get_try_str(qdict, "arg");
>>
>>      if (!op) {
>>          st_print_trace_file_status((FILE *)mon,&monitor_fprintf);
>> @@ -553,8 +554,13 @@ static void do_trace_file(Monitor *mon, const QDict *qdict)
>>          st_set_trace_file_enabled(false);
>>      } else if (!strcmp(op, "flush")) {
>>          st_flush_trace_buffer();
>> +    } else if (!strcmp(op, "set")) {
>> +        if (arg) {
>> +            st_set_trace_file(arg);
>> +        }
>>      } else {
>>          monitor_printf(mon, "unexpected argument \"%s\"\n", op);
>> +        monitor_printf(mon, "Options are: [on | off| flush| set FILENAME]");
>
> Can we use help_cmd() here to print the help text and avoid
> duplicating the options?

Agree, changed in v2.

>>      }
>>   }
>>   #endif
>> ...
>> ...
>>   static bool open_trace_file(void)
>>   {
>> -    char *filename;
>> +    trace_fp = fopen(trace_file_name, "w");
>> +    return trace_fp != NULL;
>> +}
>
> This could be inlined now.  The function is only used by one caller.
>

Done in v2.

>>
>> -    if (asprintf(&filename, CONFIG_TRACE_FILE, getpid())<  0) {
>> -        return false;
>> +/**
>> + * set_trace_file : To set the name of a trace file.
>> + * @file : pointer to the name to be set.
>> + *         If NULL, set to the default name-<pid>  set at config time.
>> + */
>> +bool st_set_trace_file(const char *file)
>> +{
>> +    if (trace_file_enabled) {
>> +        st_set_trace_file_enabled(false);
>>      }
>
> No need for an if statement.  If trace_file_enabled is already false,
> then st_set_trace_file_enabled() is a nop.

Agree this is unnecessary. Changed in v2.

>>
>> -    trace_fp = fopen(filename, "w");
>> -    free(filename);
>> -    return trace_fp != NULL;
>> +    if (trace_file_name) {
>> +        free(trace_file_name);
>> +    }
>
> No need for an if statement.  free(NULL) is a nop.

Changed in v2.

>> +
>> +    if (!file) {
>> +        if (asprintf(&trace_file_name, CONFIG_TRACE_FILE, getpid())<  0) {
>> +           return false;
>> +        }
>> +    } else {
>> +        if (asprintf(&trace_file_name, "%s", file)<  0) {
>> +            return false;
>> +        }
>> +    }
>
> When asprintf() fails, the value of the string pointer is undefined
> according to the man page.  That can result in double frees.  It would
> be safest to set trace_file_name = NULL on failure.
>

Done.

>>
>> ...
>>  ...
>>
>> @@ -2590,6 +2597,12 @@ int main(int argc, char **argv, char **envp)
>>                  }
>>                  xen_mode = XEN_ATTACH;
>>                  break;
>> +#ifdef CONFIG_SIMPLE_TRACE
>> +            case QEMU_OPTION_trace:
>> +                trace_file = (char *) qemu_malloc(strlen(optarg) + 1);
>> +                strcpy(trace_file, optarg);
>> +                break;
>> +#endif
>
> Malloc isn't necessary, just hold the optarg pointer like gdbstub_dev
> and other string options do.

It wouldnt be corect to use optarg directly here. If this optional 
argument is not specified, st_set_file_name() is called with a NULL 
argument, and the filename defaults to config-specified name.
(This is how gdbstub_dev works too. The optional argument is copied to 
gdbstub_dev if provided.)

>
>...
>

Thanks,
-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India

  reply	other threads:[~2010-08-04  9:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-03  5:37 [Qemu-devel] [Tracing][PATCH] Add options to specify trace file name at startup and runtime Prerna Saxena
2010-08-03 14:15 ` Stefan Hajnoczi
2010-08-04  9:33   ` Prerna Saxena [this message]
2010-08-04  9:53     ` Stefan Hajnoczi
2010-08-04  9:21 ` [Qemu-devel] [Tracing][PATCH v2] " Prerna Saxena
2010-08-04  9:30   ` malc
2010-08-04 10:53   ` [Qemu-devel] [Tracing][PATCH v3] " Prerna Saxena
2010-08-04 11:48     ` Stefan Hajnoczi
2010-08-05 12:08       ` [Qemu-devel] [Tracing][PATCH] Fix a build warning Prerna Saxena
2010-08-05 14:26         ` [Qemu-devel] " Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C5933FC.2090902@linux.vnet.ibm.com \
    --to=prerna@linux.vnet.ibm.com \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=stefanha@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).