linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org,
	"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [RFC PATCH v2 4/5] kernel-shark: Add hello_kernel plugin
Date: Wed,  3 Jul 2019 15:10:22 +0300	[thread overview]
Message-ID: <20190703121023.16655-5-y.karadz@gmail.com> (raw)
In-Reply-To: <20190703121023.16655-1-y.karadz@gmail.com>

This plugin is meant to be used for demonstration purposes only,
or as part of a tutorial describing how to write a new plugin.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 kernel-shark/examples/CMakeLists.txt |  4 ++
 kernel-shark/examples/hello_kernel.c | 67 ++++++++++++++++++++++++++++
 kernel-shark/src/libkshark-plugin.h  |  3 ++
 3 files changed, 74 insertions(+)
 create mode 100644 kernel-shark/examples/hello_kernel.c

diff --git a/kernel-shark/examples/CMakeLists.txt b/kernel-shark/examples/CMakeLists.txt
index e16216e..824b21c 100644
--- a/kernel-shark/examples/CMakeLists.txt
+++ b/kernel-shark/examples/CMakeLists.txt
@@ -23,3 +23,7 @@ target_link_libraries(dplot   kshark-plot)
 message(STATUS "widgetdemo")
 add_executable(widgetdemo          widgetdemo.cpp)
 target_link_libraries(widgetdemo   kshark-gui)
+
+add_library(hello             SHARED  hello_kernel.c)
+set_target_properties(hello   PROPERTIES PREFIX "plugin-")
+target_link_libraries(hello   kshark-plot)
diff --git a/kernel-shark/examples/hello_kernel.c b/kernel-shark/examples/hello_kernel.c
new file mode 100644
index 0000000..6c78411
--- /dev/null
+++ b/kernel-shark/examples/hello_kernel.c
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: LGPL-2.1
+
+/*
+ * Copyright (C) 2019 VMware Inc, Yordan Karadzhov <ykaradzhov@vmware.com>
+ */
+
+/**
+ *  @file    hello_kernel.c
+ *  @brief   Example plugin.
+ */
+
+// C
+#ifndef _GNU_SOURCE
+/** Use GNU C Library. */
+#define _GNU_SOURCE
+#endif
+#include <stdio.h>
+
+// KernelShark
+#include "libkshark.h"
+#include "libkshark-plot.h"
+#include "libkshark-plugin.h"
+
+char *font_file;
+struct ksplot_font mono_oblique_16;
+
+static void nop_action(struct kshark_context *kshark_ctx,
+		       struct tep_record *record,
+		       struct kshark_entry *entry)
+{}
+
+static void draw_hello(struct kshark_cpp_argv *argv_c,
+		       int val, int draw_action)
+{
+	if (!ksplot_font_is_loaded(&mono_oblique_16))
+		ksplot_init_font(&mono_oblique_16, 16, font_file);
+
+	ksplot_print_text(&mono_oblique_16, NULL, 100, 30, "hello kernel!");
+}
+
+/** Load this plugin. */
+int KSHARK_PLUGIN_INITIALIZER(struct kshark_context *kshark_ctx)
+{
+	font_file = ksplot_find_font_file("FreeMono", "FreeMonoOblique");
+	if (!font_file)
+		return 0;
+
+	kshark_register_event_handler(&kshark_ctx->event_handlers,
+				      KS_PLUGIN_NO_EVENT,
+				      nop_action,
+				      draw_hello);
+
+	return 1;
+}
+
+/** Unload this plugin. */
+int KSHARK_PLUGIN_DEINITIALIZER(struct kshark_context *kshark_ctx)
+{
+	kshark_unregister_event_handler(&kshark_ctx->event_handlers,
+					KS_PLUGIN_NO_EVENT,
+					nop_action,
+					draw_hello);
+
+	free(font_file);
+
+	return 1;
+}
diff --git a/kernel-shark/src/libkshark-plugin.h b/kernel-shark/src/libkshark-plugin.h
index b3cf1c6..b182d79 100644
--- a/kernel-shark/src/libkshark-plugin.h
+++ b/kernel-shark/src/libkshark-plugin.h
@@ -103,6 +103,9 @@ enum kshark_plugin_actions {
 	KSHARK_PLUGIN_CPU_DRAW,
 };
 
+/** No event identifier associated with the plugin. */
+#define KS_PLUGIN_NO_EVENT (-ENODEV)
+
 /**
  * Plugin Event handler structure, defining the properties of the required
  * kshark_entry.
-- 
2.20.1


  parent reply	other threads:[~2019-07-03 12:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-03 12:10 [RFC PATCH v2 0/5] Add support for text rendering Yordan Karadzhov (VMware)
2019-07-03 12:10 ` [RFC PATCH v2 1/5] kernel-shark: Simplify the drawing of the Triangle Fan Yordan Karadzhov (VMware)
2019-07-03 12:10 ` [RFC PATCH v2 2/5] kernel-shark: Add support for drawing text Yordan Karadzhov (VMware)
2019-07-03 12:10 ` [RFC PATCH v2 3/5] kernel-shark: Add text rendering to the plotting example Yordan Karadzhov (VMware)
2019-07-03 12:10 ` Yordan Karadzhov (VMware) [this message]
2019-07-03 12:10 ` [RFC PATCH v2 5/5] kernel-shark: Drop Freeglut as a compulsory dependency Yordan Karadzhov (VMware)
2019-07-05  9:13   ` Slavomir Kaslev
2019-07-05 10:25 ` [RFC PATCH v2 0/5] Add support for text rendering Slavomir Kaslev

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=20190703121023.16655-5-y.karadz@gmail.com \
    --to=y.karadz@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).