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.
8 #include <linux/kernel.h>
9 #include <linux/debugfs.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
,
25 if (!relay_buf_full(buf
))
29 printk("relay_buf_full!\n");
34 static struct dentry
*ctracer__create_buf_file_callback(const char *filename
,
35 struct dentry
*parent
,
37 struct rchan_buf
*buf
,
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
);
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
,
60 const unsigned long long function_id
,
61 const void *object
, const int state_len
)
64 void *t
= relay_reserve(ctracer__rchan
,
65 sizeof(struct trace_entry
) + state_len
);
68 struct trace_entry
*entry
= t
;
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");
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");