2 * debugfs file to track time spent in suspend
4 * Copyright (c) 2011, Google, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 #include <linux/debugfs.h>
18 #include <linux/err.h>
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/seq_file.h>
22 #include <linux/time.h>
24 static unsigned int sleep_time_bin
[32] = {0};
26 static int tk_debug_show_sleep_time(struct seq_file
*s
, void *data
)
29 seq_puts(s
, " time (secs) count\n");
30 seq_puts(s
, "------------------------------\n");
31 for (bin
= 0; bin
< 32; bin
++) {
32 if (sleep_time_bin
[bin
] == 0)
34 seq_printf(s
, "%10u - %-10u %4u\n",
35 bin
? 1 << (bin
- 1) : 0, 1 << bin
,
41 static int tk_debug_sleep_time_open(struct inode
*inode
, struct file
*file
)
43 return single_open(file
, tk_debug_show_sleep_time
, NULL
);
46 static const struct file_operations tk_debug_sleep_time_fops
= {
47 .open
= tk_debug_sleep_time_open
,
50 .release
= single_release
,
53 static int __init
tk_debug_sleep_time_init(void)
57 d
= debugfs_create_file("sleep_time", 0444, NULL
, NULL
,
58 &tk_debug_sleep_time_fops
);
60 pr_err("Failed to create sleep_time debug file\n");
66 late_initcall(tk_debug_sleep_time_init
);
68 void tk_debug_account_sleep_time(struct timespec
*t
)
70 sleep_time_bin
[fls(t
->tv_sec
)]++;