linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH 4/7] kernel-shark-qt: Add an example showing how to load trace data
Date: Mon, 25 Jun 2018 14:34:59 -0400	[thread overview]
Message-ID: <20180625143459.3e29de1e@gandalf.local.home> (raw)
In-Reply-To: <20180625150121.14291-5-y.karadz@gmail.com>

On Mon, 25 Jun 2018 18:01:18 +0300
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:


> --- /dev/null
> +++ b/kernel-shark-qt/examples/dataload.c
> @@ -0,0 +1,80 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +/*
> + * Copyright (C) 2018 VMware Inc, Yordan Karadzhov <y.karadz@gmail.com>
> + */
> +
> +// C
> +#include <stdio.h>
> +#include <stdlib.h>
> +
> +// KernelShark
> +#include "libkshark.h"
> +
> +const char *default_file = "trace.dat";
> +
> +int main(int argc, char **argv)
> +{
> +	// Create a new kshark session.

Again, for C files, please use the /* */ comment format.

> +	struct kshark_context *kshark_ctx = NULL;
> +	kshark_instance(&kshark_ctx);


Shouldn't you check the return value here?


> +
> +	// Open a trace data file produced by trace-cmd.
> +	bool status;

Even though this is an example, please put declarations at the top.

Other than that, this looks fine.

-- Steve

> +	if (argc > 1)
> +		status = kshark_open(kshark_ctx, argv[1]);
> +	else
> +		status = kshark_open(kshark_ctx, default_file);
> +
> +	if (!status) {
> +		kshark_free(kshark_ctx);
> +		return 1;
> +	}
> +
> +	// Load the content of the file into an array of entries.
> +	struct kshark_entry **data = NULL;
> +	size_t r, n_rows;
> +	n_rows = kshark_load_data_entries(kshark_ctx, &data);
> +
> +	// Print to the screen the list of all tasks.
> +	struct kshark_task_list* task = kshark_ctx->tasks;
> +	while (task) {
> +		const char *task_str = pevent_data_comm_from_pid(kshark_ctx->pevt,
> +								 task->pid);
> +		printf("task: %s-%i\n", task_str, task->pid);
> +		task = task->next;
> +	}
> +
> +	puts("\n\n");
> +
> +	// Print to the screen the first 10 entries.
> +	char *entry_str;
> +	for (r = 0; r < 10; ++r) {
> +		entry_str = kshark_dump_entry(data[r]);
> +		puts(entry_str);
> +		free(entry_str);
> +	}
> +
> +	puts("\n...\n");
> +
> +	// Print the last 10 entries.
> +	for (r = n_rows - 10; r < n_rows; ++r) {
> +		entry_str = kshark_dump_entry(data[r]);
> +		puts(entry_str);
> +		free(entry_str);
> +	}
> +
> +	// Free the memory.
> +	for (r = 0; r < n_rows; ++r)
> +		free(data[r]);
> +
> +	free(data);
> +
> +	// Close the file.
> +	kshark_close(kshark_ctx);
> +
> +	// Close the session.
> +	kshark_free(kshark_ctx);
> +
> +	return 0;
> +}

  reply	other threads:[~2018-06-25 18:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-25 15:01 [PATCH 0/7] Introduce the very basic part of the C API of KS-1.0 Yordan Karadzhov (VMware)
2018-06-25 15:01 ` [PATCH 1/7] kernel-shark-qt: Add Cmake build system for the Qt based KernelShark Yordan Karadzhov (VMware)
2018-06-25 16:06   ` Steven Rostedt
2018-06-26 14:23     ` Yordan Karadzhov (VMware)
2018-06-25 15:01 ` [PATCH 3/7] kernel-shark-qt: Add API for loading trace.dat files Yordan Karadzhov (VMware)
2018-06-25 18:30   ` Steven Rostedt
2018-06-26 14:47     ` Yordan Karadzhov (VMware)
2018-06-26 15:16       ` Steven Rostedt
2018-06-26 15:26         ` Yordan Karadzhov (VMware)
2018-06-25 15:01 ` [PATCH 4/7] kernel-shark-qt: Add an example showing how to load trace data Yordan Karadzhov (VMware)
2018-06-25 18:34   ` Steven Rostedt [this message]
2018-06-25 15:01 ` [PATCH 5/7] kernel-shark-qt: Add a README file to trace-cmd/kernel-shark-qt Yordan Karadzhov (VMware)
2018-06-25 18:38   ` Steven Rostedt
2018-06-26 14:51     ` Yordan Karadzhov (VMware)
2018-06-26 15:18       ` Steven Rostedt
2018-06-25 15:01 ` [PATCH 6/7] kernel-shark-qt: Add filtering to the C API of KernelShark Yordan Karadzhov (VMware)
2018-06-25 19:07   ` Steven Rostedt
2018-06-25 15:01 ` [PATCH 7/7] kernel-shark-qt: Add an example showing how to filter trace data Yordan Karadzhov (VMware)
     [not found] ` <20180625150121.14291-3-y.karadz@gmail.com>
2018-06-25 16:09   ` [PATCH 2/7] kernel-shark-qt: Automatic generation of doxygen documentation Steven Rostedt
2018-06-26 14:29     ` Yordan Karadzhov (VMware)
2018-06-26 15:00       ` Steven Rostedt

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=20180625143459.3e29de1e@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=y.karadz@gmail.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).