Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame^] | 1 | /******************************************************************************* |
| 2 | * Copyright (C) 2010, Linaro |
| 3 | * Copyright (C) 2010, IBM Corporation |
| 4 | * |
| 5 | * This file is part of PowerDebug. |
| 6 | * |
| 7 | * All rights reserved. This program and the accompanying materials |
| 8 | * are made available under the terms of the Eclipse Public License v1.0 |
| 9 | * which accompanies this distribution, and is available at |
| 10 | * http://www.eclipse.org/legal/epl-v10.html |
| 11 | * |
| 12 | * Contributors: |
| 13 | * Amit Arora <amit.arora@linaro.org> (IBM Corporation) |
| 14 | * - initial API and implementation |
| 15 | *******************************************************************************/ |
| 16 | |
| 17 | #include "powerdebug.h" |
| 18 | #include<error.h> |
| 19 | #include<errno.h> |
| 20 | |
| 21 | int get_int_from(char *file) |
| 22 | { |
| 23 | FILE *filep; |
| 24 | char result[NAME_MAX]; |
| 25 | int ret; |
| 26 | |
| 27 | filep = fopen(file, "r"); |
| 28 | |
| 29 | if (!filep) |
| 30 | return -1; //TBD : What should we return on failure, here ? |
| 31 | |
| 32 | ret = fscanf(filep, "%s", result); |
| 33 | fclose(filep); |
| 34 | |
| 35 | return atoi(result); |
| 36 | } |
| 37 | |
| 38 | int read_and_print_clock_info(int verbose, int hrow) |
| 39 | { |
| 40 | int line = 0, usecount = 0, flags = 0, rate = 0; |
| 41 | DIR *dir, *subdir; |
| 42 | char filename[PATH_MAX], devpath[PATH_MAX], clockname[NAME_MAX]; |
| 43 | struct dirent *item, *subitem; |
| 44 | |
| 45 | (void)verbose; |
| 46 | |
| 47 | print_clock_header(1); |
| 48 | |
| 49 | sprintf(filename, "%s", "/debug/clock"); |
| 50 | |
| 51 | dir = opendir(filename); |
| 52 | if (!dir) |
| 53 | return 0; |
| 54 | |
| 55 | while ((item = readdir(dir))) { |
| 56 | if (item->d_name[0] == '.') /* skip the hidden files */ |
| 57 | continue; |
| 58 | |
| 59 | sprintf(devpath, "/debug/clock/%s", item->d_name); |
| 60 | strcpy(clockname, item->d_name); |
| 61 | |
| 62 | subdir = opendir(devpath); |
| 63 | |
| 64 | if (!subdir) |
| 65 | continue; |
| 66 | |
| 67 | while ((subitem = readdir(subdir))) { |
| 68 | if (subitem->d_name[0] == '.') /* skip hidden files */ |
| 69 | continue; |
| 70 | |
| 71 | sprintf(filename, "%s/%s", devpath, subitem->d_name); |
| 72 | |
| 73 | if (!strcmp(subitem->d_name, "flags")) |
| 74 | flags = get_int_from(filename); |
| 75 | |
| 76 | if (!strcmp(subitem->d_name, "rate")) |
| 77 | rate = get_int_from(filename); |
| 78 | |
| 79 | if (!strcmp(subitem->d_name, "usecount")) |
| 80 | usecount = get_int_from(filename); |
| 81 | } |
| 82 | |
| 83 | print_clock_info_line(line, clockname, flags, rate, |
| 84 | usecount, (hrow == line) ? 1 : 0); |
| 85 | line++; |
| 86 | closedir(subdir); |
| 87 | } |
| 88 | |
| 89 | closedir(dir); |
| 90 | |
| 91 | if (hrow >= (line - 1)) |
| 92 | hrow = -1; |
| 93 | return hrow; |
| 94 | } |