summaryrefslogtreecommitdiffstats
path: root/runtime/docs/examples
diff options
context:
space:
mode:
authorhunt <hunt>2005-06-18 08:05:34 +0000
committerhunt <hunt>2005-06-18 08:05:34 +0000
commit2d7f5dfb3ea63f301341a1b63c3dfa293a3abfce (patch)
treeddacea9ee824af0d4598b73a86f1b2ce22d7bbc4 /runtime/docs/examples
parente5d2abb56ca57a613e4ef9398a6499190b2265be (diff)
downloadsystemtap-steved-2d7f5dfb3ea63f301341a1b63c3dfa293a3abfce.tar.gz
systemtap-steved-2d7f5dfb3ea63f301341a1b63c3dfa293a3abfce.tar.xz
systemtap-steved-2d7f5dfb3ea63f301341a1b63c3dfa293a3abfce.zip
*** empty log message ***
Diffstat (limited to 'runtime/docs/examples')
-rw-r--r--runtime/docs/examples/template.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/runtime/docs/examples/template.c b/runtime/docs/examples/template.c
new file mode 100644
index 00000000..fc8da3c1
--- /dev/null
+++ b/runtime/docs/examples/template.c
@@ -0,0 +1,147 @@
+/* Framework for new probes using the runtime */
+/* this example shows both kprobes and jprobes although you */
+/* likely will only want one. */
+
+/* define this if you don't want to use relayfs. Normally */
+/* you want relayfs, although it is broken at the moment. */
+
+#define STP_NETLINK_ONLY
+
+/* How many strings to allocate. see strings.c. Default is 0. */
+#define STP_NUM_STRINGS 1
+
+/* maximum size for a string. default is 2048 */
+#define STP_STRING_SIZE 2048
+
+/* size of strings saved in maps */
+#define MAP_STRING_LENGTH 256
+
+/* width of histograms. Default 50 */
+#define HIST_WIDTH 50
+
+/* always include this. Put all non-map defines above it. */
+#include "runtime.h"
+
+/* These are the possible values a map can have. */
+/* Comment out unused ones. Comment out all if you don't need maps. */
+#define NEED_INT64_VALS
+#define NEED_STRING_VALS
+#define NEED_STAT_VALS
+
+/* now for each set of keys, define the key type and include map-keys.c */
+/* This define a single key of int64, for example map1[2048] */
+#define KEY1_TYPE INT64
+#include "map-keys.c"
+
+/* This generates code to handle keys of int64,string, for example */
+/* map2[1000,"Cobalt"] */
+#define KEY1_TYPE INT64
+#define KEY2_TYPE STRING
+#include "map-keys.c"
+
+/* After defining all your key combinations, include map.c */
+#include "map.c"
+
+/* include if you use lists */
+#include "list.c"
+
+/* include if you use copy_from_user functions */
+#include "copy.c"
+
+/* include if you use the _stp_register_probe functions */
+#include "probes.c"
+
+MODULE_DESCRIPTION("SystemTap probe: myname");
+MODULE_AUTHOR("Me <myname@nowhere.com>");
+
+/* here is an example jprobe instrumentation function. */
+/* jprobes require a prototype matching the probed function. */
+
+static int inst_meminfo_read_proc(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ _stp_print("Now in meminfo\n");
+ _stp_stack_printj();
+ _stp_ustack_print();
+ jprobe_return();
+ return 0;
+}
+
+/* here is an example kprobe. kprobes always take the same arguments */
+static int inst_uptime_read_proc(struct kprobe *p, struct pt_regs *regs)
+{
+ _stp_stack_print(regs);
+ _stp_ustack_print();
+ return 0;
+}
+
+/* put jprobes here */
+static struct jprobe jp[] = {
+ {
+ .kp.addr = (kprobe_opcode_t *)"meminfo_read_proc",
+ .entry = (kprobe_opcode_t *) inst_meminfo_read_proc
+ },
+};
+
+/* put kprobes here */
+static struct kprobe kp[] = {
+ {
+ .addr = "uptime_read_proc",
+ .pre_handler = inst_uptime_read_proc,
+ }
+};
+
+#define NUM_JPROBES (sizeof(jp)/sizeof(struct jprobe))
+#define NUM_KPROBES (sizeof(kp)/sizeof(struct kprobe))
+
+/* these are currently required. May be eliminated later */
+static int pid;
+module_param(pid, int, 0);
+MODULE_PARM_DESC(pid, "daemon pid");
+
+/* called when the module loads. */
+int init_module(void)
+{
+ int ret;
+
+ /* currently required */
+ if (!pid) {
+ printk("init_module: Can't start without daemon pid\n");
+ return -1;
+ }
+
+ /* open the transport to stpd */
+ if (_stp_transport_open(n_subbufs, subbuf_size, pid) < 0) {
+ printk("init_module: Couldn't open transport\n");
+ return -1;
+ }
+
+ /* register any jprobes */
+ ret = _stp_register_jprobes (jp, NUM_JPROBES);
+
+ /* register any kprobes */
+ if (ret >= 0)
+ ret = _stp_register_kprobes (kp, NUM_KPROBES);
+
+ return ret;
+}
+
+
+static void probe_exit (void)
+{
+ /* unregister the probes */
+ _stp_unregister_jprobes (jp, NUM_JPROBES);
+ _stp_unregister_kprobes (kp, NUM_KPROBES);
+
+ /* print out any colledted data, etc */
+ _stp_printf ("whatever I want to say\n");
+ _stp_print_flush();
+}
+
+/* required */
+void cleanup_module(void)
+{
+ _stp_transport_close();
+}
+
+MODULE_LICENSE("GPL");