Duy Truong | bc5c35e | 2013-01-09 17:37:23 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2009, The Linux Foundation. All rights reserved. |
Anurag Singh | c5781f8 | 2011-10-10 10:44:44 -0700 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are met: |
| 5 | * * Redistributions of source code must retain the above copyright |
| 6 | * notice, this list of conditions and the following disclaimer. |
| 7 | * * Redistributions in binary form must reproduce the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer in the |
| 9 | * documentation and/or other materials provided with the distribution. |
Duy Truong | bc5c35e | 2013-01-09 17:37:23 -0800 | [diff] [blame] | 10 | * * Neither the name of The Linux Foundation nor |
Anurag Singh | c5781f8 | 2011-10-10 10:44:44 -0700 | [diff] [blame] | 11 | * the names of its contributors may be used to endorse or promote |
| 12 | * products derived from this software without specific prior written |
| 13 | * permission. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 19 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <string.h> |
| 32 | |
| 33 | #include "powertop.h" |
| 34 | |
| 35 | char msm_pm_stat_lines[12][200]; |
| 36 | |
| 37 | void msm_pm_stats(void) |
| 38 | { |
| 39 | FILE* fp = NULL; |
| 40 | char buf[256], temp[256]; |
| 41 | char *p; |
| 42 | int count, time_s, time_ns; |
| 43 | int i, n = 0; |
| 44 | static char sleep_types[10][50] = { |
| 45 | "idle-request", |
| 46 | "idle-spin", |
| 47 | "idle-wfi", |
| 48 | "idle-sleep", |
| 49 | "idle-failed-sleep", |
| 50 | "idle-power-collapse", |
| 51 | "idle-failed-power-collapse", |
| 52 | "suspend", |
| 53 | "failed-suspend", |
| 54 | "not-idle" |
| 55 | }; |
| 56 | |
| 57 | fp = fopen("/proc/msm_pm_stats", "r"); |
| 58 | if (!fp) { |
| 59 | printf("No msm_pm_stats available in procfs. \ |
| 60 | Enable CONFIG_MSM_IDLE_STATS in the kernel.\n"); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | sprintf(msm_pm_stat_lines[n], "MSM PM idle stats:\n"); |
| 65 | |
| 66 | while (!feof(fp)) { |
| 67 | fgets(buf, 256, fp); |
| 68 | for (i = n; i < 10; i++) { |
| 69 | p = buf; |
| 70 | if (strstr(p, sleep_types[i])) { |
| 71 | fgets(buf, 256, fp); |
| 72 | sscanf(buf, "%s%d", temp, &count); |
| 73 | fgets(buf, 256, fp); |
| 74 | sscanf(buf, "%s%d.%d", temp, |
| 75 | &time_s, |
| 76 | &time_ns); |
| 77 | sprintf(msm_pm_stat_lines[++n], |
| 78 | "%s (count = %d) : %d.%ds\n", |
| 79 | sleep_types[i], |
| 80 | count, |
| 81 | time_s, |
| 82 | time_ns); |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | fclose(fp); |
| 89 | } |