2 * webprobe/webprobe_debugfs.c
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) Samsung Electronics, 2015
19 * 2015 Anastasia Lyupa <a.lyupa@samsung.com>
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/debugfs.h>
26 #include <linux/uaccess.h>
28 #include <master/swap_debugfs.h>
29 #include <master/swap_initializer.h>
31 #include "webprobe_debugfs.h"
34 static const char ENABLED_FILE[] = "enabled";
35 static const char APP_INFO_FILE[] = "app_info";
36 static const char INSPSERVER_START_FILE[] = "inspector_server_start";
37 static const char TICK_PROBE_FILE[] = "tick_probe";
39 enum { max_count = 256 };
40 static char app_info[max_count];
42 /* ============================================================================
43 * === DEBUGFS FOR WEBPROBE INSTRUMENTATION ===
44 * ============================================================================
47 static ssize_t read_enabled(struct file *file, char __user *user_buf,
48 size_t count, loff_t *ppos)
52 buf[0] = web_prof_enabled() ? '1' : '0';
55 return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
58 static ssize_t write_enabled(struct file *file, const char __user *user_buf,
59 size_t count, loff_t *ppos)
65 buf_size = min(count, (sizeof(buf) - 1));
66 if (copy_from_user(buf, user_buf, buf_size))
72 ret = web_prof_enable();
75 ret = web_prof_disable();
87 static const struct file_operations fops_enabled = {
88 .write = write_enabled,
90 .open = swap_init_simple_open,
91 .release = swap_init_simple_release,
94 static ssize_t write_app_info(struct file *file, const char __user *user_buf,
95 size_t count, loff_t *ppos)
98 char *buf, *path, *id;
101 if (count > max_count)
104 buf = kmalloc(count + 1, GFP_KERNEL);
108 if (copy_from_user(buf, user_buf, count)) {
115 path = kmalloc(count, GFP_KERNEL);
121 id = kmalloc(count, GFP_KERNEL);
127 n = sscanf(buf, "%s %s", path, id);
134 web_prof_data_set(path, id);
135 snprintf(app_info, sizeof(app_info), "%s\n", buf);
144 return ret ? ret : count;
147 static ssize_t read_app_info(struct file *file, char __user *userbuf,
148 size_t count, loff_t *ppos)
150 return simple_read_from_buffer(userbuf, count, ppos, app_info,
151 sizeof(app_info) - 1);
154 static const struct file_operations fops_app_info = {
155 .write = write_app_info,
156 .read = read_app_info,
157 .open = swap_init_simple_open,
158 .release = swap_init_simple_release,
161 /* ============================================================================
163 * ============================================================================
166 static struct dentry *webprobe_dir;
168 void webprobe_debugfs_exit(void)
170 debugfs_remove_recursive(webprobe_dir);
174 int webprobe_debugfs_init(void)
176 struct dentry *dentry;
178 dentry = swap_debugfs_getdir();
182 webprobe_dir = debugfs_create_dir("webprobe", dentry);
186 dentry = debugfs_create_file(ENABLED_FILE, 0600, webprobe_dir, NULL,
189 dentry = debugfs_create_file(APP_INFO_FILE, 0600, webprobe_dir,
190 NULL, &fops_app_info);
194 dentry = debugfs_create_x64(INSPSERVER_START_FILE, 0600, webprobe_dir,
195 web_prof_addr_ptr(INSPSERVER_START));
199 dentry = debugfs_create_x64(TICK_PROBE_FILE, 0600, webprobe_dir,
200 web_prof_addr_ptr(TICK_PROBE));
207 webprobe_debugfs_exit();