aboutsummaryrefslogtreecommitdiff
path: root/clocks.c
diff options
context:
space:
mode:
authorAmit Arora <amit.arora@linaro.org>2010-09-14 12:06:09 +0530
committerAmit Arora <amit.arora@linaro.org>2010-09-14 12:06:09 +0530
commit728e0c96c34812361649ef095f14700c53647ef3 (patch)
treee1fed71f97c0672e7f4fddb515704dec4284673f /clocks.c
parent39f2954961126dbe0eb1b63cef6cd1840f5c0dce (diff)
downloadpowerdebug-728e0c96c34812361649ef095f14700c53647ef3.tar.gz
Version 0.2 (add clock info)
Diffstat (limited to 'clocks.c')
-rw-r--r--clocks.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/clocks.c b/clocks.c
new file mode 100644
index 0000000..9a49d9e
--- /dev/null
+++ b/clocks.c
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Linaro
+ * Copyright (C) 2010, IBM Corporation
+ *
+ * This file is part of PowerDebug.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Amit Arora <amit.arora@linaro.org> (IBM Corporation)
+ * - initial API and implementation
+ *******************************************************************************/
+
+#include "powerdebug.h"
+#include<error.h>
+#include<errno.h>
+
+int get_int_from(char *file)
+{
+ FILE *filep;
+ char result[NAME_MAX];
+ int ret;
+
+ filep = fopen(file, "r");
+
+ if (!filep)
+ return -1; //TBD : What should we return on failure, here ?
+
+ ret = fscanf(filep, "%s", result);
+ fclose(filep);
+
+ return atoi(result);
+}
+
+int read_and_print_clock_info(int verbose, int hrow)
+{
+ int line = 0, usecount = 0, flags = 0, rate = 0;
+ DIR *dir, *subdir;
+ char filename[PATH_MAX], devpath[PATH_MAX], clockname[NAME_MAX];
+ struct dirent *item, *subitem;
+
+ (void)verbose;
+
+ print_clock_header(1);
+
+ sprintf(filename, "%s", "/debug/clock");
+
+ dir = opendir(filename);
+ if (!dir)
+ return 0;
+
+ while ((item = readdir(dir))) {
+ if (item->d_name[0] == '.') /* skip the hidden files */
+ continue;
+
+ sprintf(devpath, "/debug/clock/%s", item->d_name);
+ strcpy(clockname, item->d_name);
+
+ subdir = opendir(devpath);
+
+ if (!subdir)
+ continue;
+
+ while ((subitem = readdir(subdir))) {
+ if (subitem->d_name[0] == '.') /* skip hidden files */
+ continue;
+
+ sprintf(filename, "%s/%s", devpath, subitem->d_name);
+
+ if (!strcmp(subitem->d_name, "flags"))
+ flags = get_int_from(filename);
+
+ if (!strcmp(subitem->d_name, "rate"))
+ rate = get_int_from(filename);
+
+ if (!strcmp(subitem->d_name, "usecount"))
+ usecount = get_int_from(filename);
+ }
+
+ print_clock_info_line(line, clockname, flags, rate,
+ usecount, (hrow == line) ? 1 : 0);
+ line++;
+ closedir(subdir);
+ }
+
+ closedir(dir);
+
+ if (hrow >= (line - 1))
+ hrow = -1;
+ return hrow;
+}