aboutsummaryrefslogtreecommitdiff
path: root/drivers/media/video/uvc/uvc_debugfs.c
diff options
context:
space:
mode:
authorAlexey Fisher <bug-track@fisher-privat.net>2011-11-03 11:40:08 -0300
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-12-11 11:22:08 -0200
commit7bc5edb00bbd02449576289a50d2900f58e7187a (patch)
treefe0dc70fcceed75d72e10fc9869ecd90f7b8c057 /drivers/media/video/uvc/uvc_debugfs.c
parentedbaa39842793fc4ac6603b277f2ad76f2057a45 (diff)
[media] uvcvideo: Extract video stream statistics
Export the statistics through debugfs. Signed-off-by: Alexey Fisher <bug-track@fisher-privat.net> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/uvc/uvc_debugfs.c')
-rw-r--r--drivers/media/video/uvc/uvc_debugfs.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/drivers/media/video/uvc/uvc_debugfs.c b/drivers/media/video/uvc/uvc_debugfs.c
index 39fd43b3e1d..14561a5abb7 100644
--- a/drivers/media/video/uvc/uvc_debugfs.c
+++ b/drivers/media/video/uvc/uvc_debugfs.c
@@ -19,6 +19,57 @@
#include "uvcvideo.h"
/* -----------------------------------------------------------------------------
+ * Statistics
+ */
+
+#define UVC_DEBUGFS_BUF_SIZE 1024
+
+struct uvc_debugfs_buffer {
+ size_t count;
+ char data[UVC_DEBUGFS_BUF_SIZE];
+};
+
+static int uvc_debugfs_stats_open(struct inode *inode, struct file *file)
+{
+ struct uvc_streaming *stream = inode->i_private;
+ struct uvc_debugfs_buffer *buf;
+
+ buf = kmalloc(sizeof(*buf), GFP_KERNEL);
+ if (buf == NULL)
+ return -ENOMEM;
+
+ buf->count = uvc_video_stats_dump(stream, buf->data, sizeof(buf->data));
+
+ file->private_data = buf;
+ return 0;
+}
+
+static ssize_t uvc_debugfs_stats_read(struct file *file, char __user *user_buf,
+ size_t nbytes, loff_t *ppos)
+{
+ struct uvc_debugfs_buffer *buf = file->private_data;
+
+ return simple_read_from_buffer(user_buf, nbytes, ppos, buf->data,
+ buf->count);
+}
+
+static int uvc_debugfs_stats_release(struct inode *inode, struct file *file)
+{
+ kfree(file->private_data);
+ file->private_data = NULL;
+
+ return 0;
+}
+
+static const struct file_operations uvc_debugfs_stats_fops = {
+ .owner = THIS_MODULE,
+ .open = uvc_debugfs_stats_open,
+ .llseek = no_llseek,
+ .read = uvc_debugfs_stats_read,
+ .release = uvc_debugfs_stats_release,
+};
+
+/* -----------------------------------------------------------------------------
* Global and stream initialization/cleanup
*/
@@ -37,13 +88,21 @@ int uvc_debugfs_init_stream(struct uvc_streaming *stream)
dent = debugfs_create_dir(dir_name, uvc_debugfs_root_dir);
if (IS_ERR_OR_NULL(dent)) {
- uvc_printk(KERN_INFO, "Unable to create debugfs %s directory.\n",
- dir_name);
+ uvc_printk(KERN_INFO, "Unable to create debugfs %s "
+ "directory.\n", dir_name);
return -ENODEV;
}
stream->debugfs_dir = dent;
+ dent = debugfs_create_file("stats", 0444, stream->debugfs_dir,
+ stream, &uvc_debugfs_stats_fops);
+ if (IS_ERR_OR_NULL(dent)) {
+ uvc_printk(KERN_INFO, "Unable to create debugfs stats file.\n");
+ uvc_debugfs_cleanup_stream(stream);
+ return -ENODEV;
+ }
+
return 0;
}