NEWS: Add missing list of changes for v1.25
[dwarves.git] / lib / ctracer_relay.c
blobf753fc125189dd50f0326980af572a02ba6ea185
1 /*
2 Copyright (C) 2007 Arnaldo Carvalho de Melo <acme@redhat.com>
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of version 2 of the GNU General Public License as
6 published by the Free Software Foundation.
7 */
8 #include <linux/kernel.h>
9 #include <linux/debugfs.h>
10 #include <linux/fs.h>
11 #include <linux/percpu.h>
12 #include <linux/relay.h>
13 #include <linux/sched.h>
14 #include <linux/string.h>
15 #include <linux/module.h>
16 #include "ctracer_relay.h"
18 static struct rchan *ctracer__rchan;
20 static int ctracer__subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
21 void *prev_subbuf,
22 size_t prev_padding)
24 static int warned;
25 if (!relay_buf_full(buf))
26 return 1;
27 if (!warned) {
28 warned = 1;
29 printk("relay_buf_full!\n");
31 return 0;
34 static struct dentry *ctracer__create_buf_file_callback(const char *filename,
35 struct dentry *parent,
36 int mode,
37 struct rchan_buf *buf,
38 int *is_global)
40 return debugfs_create_file(filename, mode, parent, buf,
41 &relay_file_operations);
44 static int ctracer__remove_buf_file_callback(struct dentry *dentry)
46 debugfs_remove(dentry);
47 return 0;
50 static struct rchan_callbacks ctracer__relay_callbacks = {
51 .subbuf_start = ctracer__subbuf_start_callback,
52 .create_buf_file = ctracer__create_buf_file_callback,
53 .remove_buf_file = ctracer__remove_buf_file_callback,
56 extern void ctracer__class_state(const void *from, void *to);
58 void ctracer__method_hook(const unsigned long long now,
59 const int probe_type,
60 const unsigned long long function_id,
61 const void *object, const int state_len)
63 if (object != NULL) {
64 void *t = relay_reserve(ctracer__rchan,
65 sizeof(struct trace_entry) + state_len);
67 if (t != NULL) {
68 struct trace_entry *entry = t;
70 entry->nsec = now;
71 entry->probe_type = probe_type;
72 entry->object = object;
73 entry->function_id = function_id;
74 ctracer__class_state(object, t + sizeof(*entry));
79 EXPORT_SYMBOL_GPL(ctracer__method_hook);
81 static int __init ctracer__relay_init(void)
83 ctracer__rchan = relay_open("ctracer", NULL, 512 * 1024, 64,
84 &ctracer__relay_callbacks, NULL);
85 if (ctracer__rchan == NULL) {
86 pr_info("ctracer: couldn't create the relay\n");
87 return -1;
89 return 0;
92 module_init(ctracer__relay_init);
94 static void __exit ctracer__relay_exit(void)
96 relay_close(ctracer__rchan);
99 module_exit(ctracer__relay_exit);
101 MODULE_LICENSE("GPL");