linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH v17 04/18] trace-cmd: Add new library APIs for ftrace instances.
Date: Thu, 5 Dec 2019 16:40:41 +0200	[thread overview]
Message-ID: <CAPpZLN55PuXtN5-9SzPnDaitHVmEUjRyGndbab21LX9DrbeRFQ@mail.gmail.com> (raw)
In-Reply-To: <20191204111731.7409abdc@gandalf.local.home>

On Wed, Dec 4, 2019 at 6:17 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
[ ... ]
> > +     do {
> > +             r = read(fd, buffer, BUFSIZ);
> > +             if (r <= 0)
> > +                     continue;
> > +             if (size)
> > +                     buf = realloc(buf, size+r+1);
> > +             else
> > +                     buf = malloc(r+1);
>
> I know this is only cut and pasted from what the original was, but we
> should probably (either in this patch, or perhaps a separate one) fix
> the above. As realloc(NULL, x) is equivalent to malloc(x), we can just
> have:
>
>                 buf = realloc(buf, size+r+1);
>
>
> > +             if (!buf)
> > +                     die("Failed to allocate instance file buffer");
>
> As this is becoming a library function, we should remove "die()", as
> that is only allowed in the application. Not library calls.
>
> That would also mean we need to clean up anything we allocated on
> failure, and that the realloc would need to be:
>
>                 new_buf = realloc(buf, size + r + 1);
>
>                 if (!new_buf) {
>                         free(buf);
>                         return NULL;
>
> All the functions that are being moved into the library needs to have
> their die() calls removed. This is OK to do in a separate patch.
>
> Preferably right after this patch (so reviewers know it's happening).
>
I fixed most of the comments, except those die() call. There are a lot
of things that
should be fixed in the existing libtracecmd code, in order to become a
real library.
Also, I started to work on a new library providing APIs for
interaction with files
from tracefs, libtraceftrace (this is only a work name, we should
think about more suitable one).
I would suggest changes from this patch set to be considered only as
part of the time stamp sync
feature. There will be at least two library patch sets - for cleaning
up the existing libtracecmd code and
for the new ftrace library.

>
> > +             memcpy(buf+size, buffer, r);
> > +             size += r;
> > +     } while (r);
> > +
> > +     buf[size] = '\0';
> > +     if (psize)
> > +             *psize = size;
> > +     return buf;
> > +}
> > +
> > +/**
> > + * tracecmd_set_clock - Set the clock of ftrace event's timestamps, per instance.
> > + * @instance: Pointer to ftrace instance, containing the desired clock.
> > + * @old_clock: Optional, return the newly allocated string with the old clock.
>
> This looks to be just a copy of the old code and forced into a library
> function. As a library function, it should return an "int" and be
> passed the clock name directly. Not via the instance->clock.

The idea of this API is to apply the clock, already set to the
instance. This follows
the existing logic of configuring the instance clock, that's why I put
the "char *clock"
in the new "struct tracecmd_instance". We can remove the clock from
the structure
and pass it as an argument to tracecmd_set_clock(), so the  "struct
tracecmd_instance"
will hold only the instance name ?

>
> -- Steve
>
> > + *
> > + */
> > +void tracecmd_set_clock(struct tracecmd_instance *instance, char **old_clock)
> > +{
> > +     char *content;
> > +     char *str;
> > +
> > +     if (!instance->clock)
> > +             return;
> > +
> > +     /* The current clock is in brackets, reset it when we are done */
> > +     content = tracecmd_read_instance_file(instance, "trace_clock", NULL);
> > +
> > +     /* check if first clock is set */
> > +     if (*content == '[')
> > +             str = strtok(content+1, "]");
> > +     else {
> > +             str = strtok(content, "[");
> > +             if (!str)
> > +                     die("Can not find clock in trace_clock");
> > +             str = strtok(NULL, "]");
> > +     }
> > +     if (old_clock)
> > +             *old_clock = strdup(str);
> > +
> > +     free(content);
> > +     tracecmd_write_instance_file(instance,
> > +                                  "trace_clock", instance->clock, "clock");
> > +}
> >

Thanks !

-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

  reply	other threads:[~2019-12-05 14:40 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-03 10:35 [PATCH v17 00/18]Timestamp synchronization of host - guest tracing session Tzvetomir Stoyanov (VMware)
2019-12-03 10:35 ` [PATCH v17 01/18] trace-cmd: Implement new lib API: tracecmd_local_events_system() Tzvetomir Stoyanov (VMware)
2019-12-03 10:35 ` [PATCH v17 02/18] trace-cmd: Add support for negative time offsets in trace.dat file Tzvetomir Stoyanov (VMware)
2019-12-03 10:35 ` [PATCH v17 03/18] trace-cmd: Add implementations of htonll() and ntohll() Tzvetomir Stoyanov (VMware)
2019-12-20 13:50   ` Steven Rostedt
2020-01-06 14:30     ` Tzvetomir Stoyanov
2019-12-03 10:35 ` [PATCH v17 04/18] trace-cmd: Add new library APIs for ftrace instances Tzvetomir Stoyanov (VMware)
2019-12-04 16:17   ` Steven Rostedt
2019-12-05 14:40     ` Tzvetomir Stoyanov [this message]
2019-12-03 10:35 ` [PATCH v17 05/18] trace-cmd: Add new library API for local CPU count Tzvetomir Stoyanov (VMware)
2019-12-04 20:09   ` Steven Rostedt
2019-12-03 10:35 ` [PATCH v17 06/18] trace-cmd: Add new library API for reading ftrace buffers Tzvetomir Stoyanov (VMware)
2019-12-04 21:10   ` Steven Rostedt
2019-12-03 10:35 ` [PATCH v17 07/18] trace-cmd: Find and store pids of tasks, which run virtual CPUs of given VM Tzvetomir Stoyanov (VMware)
2019-12-04 21:35   ` Steven Rostedt
2019-12-03 10:35 ` [PATCH v17 08/18] trace-cmd: Implement new API tracecmd_add_option_v() Tzvetomir Stoyanov (VMware)
2019-12-04 21:47   ` Steven Rostedt
2019-12-03 10:35 ` [PATCH v17 09/18] trace-cmd: Add new API to generate a unique ID of the tracing session Tzvetomir Stoyanov (VMware)
2019-12-03 10:35 ` [PATCH v17 10/18] trace-cmd: Store the session tracing ID in the trace.dat file Tzvetomir Stoyanov (VMware)
2019-12-03 10:35 ` [PATCH v17 11/18] trace-cmd: Exchange tracing IDs between host and guest Tzvetomir Stoyanov (VMware)
2019-12-04 22:03   ` Steven Rostedt
2019-12-03 10:35 ` [PATCH v17 12/18] trace-cmd: Implement new option in trace.dat file: TRACECMD_OPTION_TIME_SHIFT Tzvetomir Stoyanov (VMware)
2019-12-05  0:46   ` Steven Rostedt
2019-12-05 15:09     ` Tzvetomir Stoyanov
2019-12-03 10:35 ` [PATCH v17 13/18] trace-cmd: Add guest information in host's trace.dat file Tzvetomir Stoyanov (VMware)
2019-12-05  0:59   ` Steven Rostedt
2019-12-03 10:35 ` [PATCH v17 14/18] trace-cmd: Add host trace clock as guest trace argument Tzvetomir Stoyanov (VMware)
2019-12-09 19:31   ` Steven Rostedt
2019-12-10  8:49     ` Tzvetomir Stoyanov
2019-12-10 15:48       ` Steven Rostedt
2019-12-11  8:21         ` Tzvetomir Stoyanov
2019-12-11 15:01           ` Steven Rostedt
2019-12-03 10:35 ` [PATCH v17 15/18] trace-cmd: Refactor few trace-cmd internal functions Tzvetomir Stoyanov (VMware)
2019-12-09 19:32   ` Steven Rostedt
2019-12-03 10:35 ` [PATCH v17 16/18] trace-cmd: Basic infrastructure for host - guest timestamp synchronization Tzvetomir Stoyanov (VMware)
2019-12-10 17:04   ` Steven Rostedt
2019-12-10 18:39   ` Steven Rostedt
2019-12-12 12:34     ` Tzvetomir Stoyanov
2019-12-12 14:54       ` Steven Rostedt
2019-12-12 14:00     ` Tzvetomir Stoyanov
2019-12-03 10:35 ` [PATCH v17 17/18] trace-cmd: [POC] PTP-like algorithm " Tzvetomir Stoyanov (VMware)
2019-12-03 10:35 ` [PATCH v17 18/18] trace-cmd: Debug scripts for " Tzvetomir Stoyanov (VMware)

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=CAPpZLN55PuXtN5-9SzPnDaitHVmEUjRyGndbab21LX9DrbeRFQ@mail.gmail.com \
    --to=tz.stoyanov@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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).