All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: "Jin, Yao" <yao.jin@linux.intel.com>
Cc: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org,
	mingo@redhat.com, alexander.shishkin@linux.intel.com,
	Linux-kernel@vger.kernel.org, ak@linux.intel.com,
	kan.liang@intel.com, yao.jin@intel.com
Subject: Re: [PATCH v1 4/5] perf mem: Support record for hybrid platform
Date: Wed, 26 May 2021 13:44:56 +0200	[thread overview]
Message-ID: <YK40uLOZC+4qGMl3@krava> (raw)
In-Reply-To: <6d6f1040-6c96-7d1d-c766-5fb0057e1cc4@linux.intel.com>

On Wed, May 26, 2021 at 09:51:34AM +0800, Jin, Yao wrote:
> Hi Jiri,
> 
> On 5/25/2021 3:39 PM, Jin, Yao wrote:
> > Hi Jiri,
> > 
> > > > >       rec_argv = calloc(rec_argc + 1, sizeof(char *));
> > > > >       if (!rec_argv)
> > > > >           return -1;
> > > > > +    /*
> > > > > +     * Save the allocated event name strings.
> > > > > +     */
> > > > > +    rec_tmp = calloc(rec_argc + 1, sizeof(char *));
> > > > > +    if (!rec_tmp) {
> > > > > +        free(rec_argv);
> > > > > +        return -1;
> > > > > +    }
> > > > 
> > > > why not do strdup on all of them and always call free instead?
> > > > that would get rid of the rec_tmp and tmp_nr
> > > > 
> > > 
> > > That is also one method. Let me try it.
> > > 
> > 
> > If we do strdup on all of them, such as,
> > 
> >      if (e->record)
> >          rec_argv[i++] = strdup("-W");
> > 
> >      rec_argv[i++] = strdup("-d");
> > 
> >      if (mem->phys_addr)
> >          rec_argv[i++] = strdup("--phys-data");
> >      ....
> > 
> > That looks too much strdup used here. So I choose to use a rec_tmp[] to
> > record the allocated string and free them before exit the function.
> > 
> > Or we record the start index and end index in rec_argv[] for the
> > allocated event string, use strdup on them and call free before exit the
> > function.
> > 
> 
> This method looks also not OK.
> 
> The rec_argv[] is changed in cmd_record() for some complex command lines.
> 
> For example,
> 
> ./perf mem record -- ./memtest -R0d -b2000 -d64 -n100
> 
> Before cmd_record(), rec_argv[3] = "-e".
> After cmd_record(), rec_argv[3] = "-d64"
> 
> Even we do strdup on all of rec_argv[], but the entries are probably changed
> in cmd_record(), so we can't free the entries at the end of __cmd_record().
> 
> Maybe we have to use the original way which just records the allocated event
> string to a temporary array and free the whole array at the end of
> __cmd_record().
> 
> What do you think?

ok, it was worth to try ;-)

thanks,
jirka


  reply	other threads:[~2021-05-26 11:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-20  7:00 [PATCH v1 0/5] perf: Support perf-mem/perf-c2c for AlderLake Jin Yao
2021-05-20  7:00 ` [PATCH v1 1/5] perf util: Check mem-loads auxiliary event Jin Yao
2021-05-20  7:00 ` [PATCH v1 2/5] perf tools: Support pmu name in perf_mem_events__name Jin Yao
2021-05-24 17:20   ` Jiri Olsa
2021-05-25  5:39     ` Jin, Yao
2021-05-20  7:00 ` [PATCH v1 3/5] perf tools: Check if mem_events is supported for hybrid Jin Yao
2021-05-24 17:19   ` Jiri Olsa
2021-05-25  6:14     ` Jin, Yao
2021-05-20  7:00 ` [PATCH v1 4/5] perf mem: Support record for hybrid platform Jin Yao
2021-05-24 17:19   ` Jiri Olsa
2021-05-25  7:00     ` Jin, Yao
2021-05-25  7:39       ` Jin, Yao
2021-05-26  1:51         ` Jin, Yao
2021-05-26 11:44           ` Jiri Olsa [this message]
2021-05-20  7:00 ` [PATCH v1 5/5] perf c2c: " Jin Yao

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=YK40uLOZC+4qGMl3@krava \
    --to=jolsa@redhat.com \
    --cc=Linux-kernel@vger.kernel.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@intel.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=yao.jin@intel.com \
    --cc=yao.jin@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.