Blame view

samples/tracepoints/tracepoint-sample.c 1.18 KB
4a0897526   Mathieu Desnoyers   tracing: tracepoi...
1
2
  /* tracepoint-sample.c
   *
0a5d64901   Jody McIntyre   tracing: Document...
3
   * Executes a tracepoint when /proc/tracepoint-sample is opened.
4a0897526   Mathieu Desnoyers   tracing: tracepoi...
4
5
6
7
8
9
10
11
12
13
14
   *
   * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
   *
   * This file is released under the GPLv2.
   * See the file COPYING for more details.
   */
  
  #include <linux/module.h>
  #include <linux/sched.h>
  #include <linux/proc_fs.h>
  #include "tp-samples-trace.h"
7e066fb87   Mathieu Desnoyers   tracepoints: add ...
15
16
  DEFINE_TRACE(subsys_event);
  DEFINE_TRACE(subsys_eventb);
0a5d64901   Jody McIntyre   tracing: Document...
17
  struct proc_dir_entry *pentry_sample;
4a0897526   Mathieu Desnoyers   tracing: tracepoi...
18
19
20
21
22
23
24
25
26
27
  
  static int my_open(struct inode *inode, struct file *file)
  {
  	int i;
  
  	trace_subsys_event(inode, file);
  	for (i = 0; i < 10; i++)
  		trace_subsys_eventb();
  	return -EPERM;
  }
828c09509   Alexey Dobriyan   const: constify r...
28
  static const struct file_operations mark_ops = {
4a0897526   Mathieu Desnoyers   tracing: tracepoi...
29
  	.open = my_open,
6038f373a   Arnd Bergmann   llseek: automatic...
30
  	.llseek = noop_llseek,
4a0897526   Mathieu Desnoyers   tracing: tracepoi...
31
  };
0a5d64901   Jody McIntyre   tracing: Document...
32
  static int __init sample_init(void)
4a0897526   Mathieu Desnoyers   tracing: tracepoi...
33
  {
0a5d64901   Jody McIntyre   tracing: Document...
34
35
36
  	printk(KERN_ALERT "sample init
  ");
  	pentry_sample = proc_create("tracepoint-sample", 0444, NULL,
4a0897526   Mathieu Desnoyers   tracing: tracepoi...
37
  		&mark_ops);
0a5d64901   Jody McIntyre   tracing: Document...
38
  	if (!pentry_sample)
4a0897526   Mathieu Desnoyers   tracing: tracepoi...
39
40
41
  		return -EPERM;
  	return 0;
  }
0a5d64901   Jody McIntyre   tracing: Document...
42
  static void __exit sample_exit(void)
4a0897526   Mathieu Desnoyers   tracing: tracepoi...
43
  {
0a5d64901   Jody McIntyre   tracing: Document...
44
45
46
  	printk(KERN_ALERT "sample exit
  ");
  	remove_proc_entry("tracepoint-sample", NULL);
4a0897526   Mathieu Desnoyers   tracing: tracepoi...
47
  }
0a5d64901   Jody McIntyre   tracing: Document...
48
49
  module_init(sample_init)
  module_exit(sample_exit)
4a0897526   Mathieu Desnoyers   tracing: tracepoi...
50
51
52
  
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("Mathieu Desnoyers");
0a5d64901   Jody McIntyre   tracing: Document...
53
  MODULE_DESCRIPTION("Tracepoint sample");