aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjan van de Ven <arjan@linux.intel.com>2010-12-19 12:18:02 -0800
committerArjan van de Ven <arjan@linux.intel.com>2010-12-19 12:18:02 -0800
commit56f1884be1568e15bdad197ed73c5c0a8bc7f683 (patch)
treed70f6e550cca6ebd814b08a30cb801eb7d01fb9c
parente27fd5325868a20a8755dfdf1dbe332de0f0fe73 (diff)
downloadpowertop-56f1884be1568e15bdad197ed73c5c0a8bc7f683.tar.gz
start adding html output support
-rw-r--r--Makefile4
-rw-r--r--TODO2
-rw-r--r--cpu/cpu.cpp95
-rw-r--r--cpu/cpu.h7
-rw-r--r--html.cpp71
-rw-r--r--html.h40
-rw-r--r--main.cpp19
7 files changed, 191 insertions, 47 deletions
diff --git a/Makefile b/Makefile
index e60f6fa..c895735 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ all: powertop
CFLAGS += -Wall -O2 -g -fno-omit-frame-pointer
CPPFLAGS += -Wall -O2 -g -fno-omit-frame-pointer
CXXFLAGS += -Wall -O2 -g -fno-omit-frame-pointer
-OBJS := lib.o main.o display.o
+OBJS := lib.o main.o display.o html.o
OBJS += cpu/cpu.o cpu/abstract_cpu.o cpu/cpu_linux.o cpu/cpu_core.o cpu/cpu_package.o cpu/intel_cpus.o cpu/cpudevice.cpp
OBJS += perf/perf.o perf/perf_bundle.o
OBJS += process/process.o process/do_process.o process/interrupt.o process/timer.o process/work.o process/powerconsumer.o process/device.o
@@ -35,5 +35,5 @@ powertop: $(OBJS) $(HEADERS)
%.o: %.cpp lib.h Makefile
@echo " CC $<"
- @[ -x /usr/bin/cppcheck ] && /usr/bin/cppcheck -q $<
+ @[ -x /usr/bin/cppcheck ] && /usr/bin/cppcheck -q $< || :
@$(CC) $(CFLAGS) -c -o $@ $<
diff --git a/TODO b/TODO
index 8d81b83..314b429 100644
--- a/TODO
+++ b/TODO
@@ -5,7 +5,6 @@
* inode dirty trace point
* health report (reporting mode, not interactive) needs to include devices that don't support runtime PM
-* status bar at the bottom
* have a "show me my process" page
* fix memory leaks
* find out why CPU %age and C state C0 %age don't mesh sometimes
@@ -59,3 +58,4 @@ done
* pretty print various kernel pieces
* deal with debugfs not being in /sys/kernel/debug
* if you plug in the AC during a run, the battery code is not detecting that
+* status bar at the bottom
diff --git a/cpu/cpu.cpp b/cpu/cpu.cpp
index 7ff7b33..9716b38 100644
--- a/cpu/cpu.cpp
+++ b/cpu/cpu.cpp
@@ -36,6 +36,7 @@
#include "../perf/perf_bundle.h"
#include "../lib.h"
#include "../display.h"
+#include "../html.h"
static class abstract_cpu system_level;
@@ -443,18 +444,20 @@ void w_display_cpu_cstates(void)
}
-void display_cpu_pstates(const char *start, const char *end, const char *linestart,
- const char *separator, const char *lineend)
+void html_display_cpu_pstates(void)
{
- char buffer[128];
+ char buffer[512], buffer2[512];
char linebuf[1024];
unsigned int package, core, cpu;
int line;
class abstract_cpu *_package, * _core, * _cpu;
- int ctr = 0;
+ if (!htmlout)
+ return;
+
+
+ fprintf(htmlout, "<h2>Processor frequency report</h2>\n");
- printf("%s", start);
for (package = 0; package < system_level.children.size(); package++) {
int first_pkg = 0;
@@ -462,6 +465,7 @@ void display_cpu_pstates(const char *start, const char *end, const char *linesta
if (!_package)
continue;
+ fprintf(htmlout, "<table width=100%%>\n");
for (core = 0; core < _package->children.size(); core++) {
_core = _package->children[core];
@@ -470,69 +474,82 @@ void display_cpu_pstates(const char *start, const char *end, const char *linesta
for (line = LEVEL_HEADER; line < 10; line++) {
int first = 1;
- ctr = 0;
linebuf[0] = 0;
if (!_package->has_pstate_level(line))
continue;
- printf("%s", linestart);
- ctr += strlen(linestart);
-
+ if (line == LEVEL_HEADER)
+ fprintf(htmlout, "<th>");
+ else
+ fprintf(htmlout, "<tr>");
+
+
buffer[0] = 0;
+ buffer2[0] = 0;
if (first_pkg == 0) {
- strcat(linebuf, _package->fill_pstate_name(line, buffer));
- expand_string(linebuf, ctr + 10);
- strcat(linebuf, _package->fill_pstate_line(line, buffer));
+ if (line == LEVEL_HEADER)
+ fprintf(htmlout, "<td colspan=2>%s%s</td>",
+ _package->fill_pstate_name(line, buffer),
+ _package->fill_pstate_line(line, buffer2));
+ else
+ fprintf(htmlout, "<td>%s</td><td>%s</td>",
+ _package->fill_pstate_name(line, buffer),
+ _package->fill_pstate_line(line, buffer2));
+ } else {
+ fprintf(htmlout, "<td colspan=2>&nbsp;</td>");
}
- ctr += 20;
- expand_string(linebuf, ctr);
-
- strcat(linebuf, separator);
- ctr += strlen(separator);
if (!_core->can_collapse()) {
buffer[0] = 0;
- strcat(linebuf, _core->fill_pstate_name(line, buffer));
- expand_string(linebuf, ctr + 10);
- strcat(linebuf, _core->fill_pstate_line(line, buffer));
- ctr += 20;
- expand_string(linebuf, ctr);
-
- strcat(linebuf, separator);
- ctr += strlen(separator);
+ buffer2[0] = 0;
+ if (line == LEVEL_HEADER)
+ fprintf(htmlout, "<td colspan=2>%s%s</td>",
+ _core->fill_pstate_name(line, buffer),
+ _core->fill_pstate_line(line, buffer2));
+ else
+ fprintf(htmlout, "<td>%s</td><td>%s</td>",
+ _core->fill_pstate_name(line, buffer),
+ _core->fill_pstate_line(line, buffer2));
}
for (cpu = 0; cpu < _core->children.size(); cpu++) {
+ buffer[0] = 0;
_cpu = _core->children[cpu];
if (!_cpu)
continue;
- if (first == 1) {
- strcat(linebuf, _cpu->fill_pstate_name(line, buffer));
- expand_string(linebuf, ctr + 10);
- first = 0;
- ctr += 12;
+ if (line == LEVEL_HEADER) {
+ fprintf(htmlout, "<td colspan=2>%s</td>", _cpu->fill_pstate_line(line, buffer));
+ } else {
+ if (first == 1) {
+ fprintf(htmlout, "<td>%s</td>", _cpu->fill_pstate_name(line, buffer));
+ first = 0;
+ buffer[0] = 0;
+ fprintf(htmlout, "<td>%s</td>",
+ _cpu->fill_pstate_line(line, buffer));
+ } else {
+ buffer[0] = 0;
+ fprintf(htmlout, "<td colspan=2>%s</td>",
+ _cpu->fill_pstate_line(line, buffer));
+ }
}
- buffer[0] = 0;
- strcat(linebuf, _cpu->fill_pstate_line(line, buffer));
- ctr += 10;
- expand_string(linebuf, ctr);
-
}
- strcat(linebuf, lineend);
- printf("%s", linebuf);
+ if (line == LEVEL_HEADER)
+ fprintf(htmlout, "</th>\n");
+ else
+ fprintf(htmlout, "</tr>\n");
+
}
- printf("\n");
first_pkg++;
}
}
- printf("%s", end);
+ fprintf(htmlout, "</table>");
}
void w_display_cpu_pstates(void)
diff --git a/cpu/cpu.h b/cpu/cpu.h
index fbd25d8..b4a8385 100644
--- a/cpu/cpu.h
+++ b/cpu/cpu.h
@@ -200,11 +200,8 @@ public:
extern void enumerate_cpus(void);
-extern void display_cpu_pstates(const char *start= "",
- const char *end = "",
- const char *linestart = "",
- const char *separator = "| ",
- const char *lineend = "\n");
+extern void html_display_cpu_pstates(void);
+
extern void display_cpu_cstates(const char *start= "",
const char *end = "",
diff --git a/html.cpp b/html.cpp
new file mode 100644
index 0000000..7631ac8
--- /dev/null
+++ b/html.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2010, Intel Corporation
+ *
+ * This file is part of PowerTOP
+ *
+ * This program file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program in a file named COPYING; if not, write to the
+ * Free Software Foundation, Inc,
+ * 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ * or just google for it.
+ *
+ * Authors:
+ * Arjan van de Ven <arjan@linux.intel.com>
+ */
+
+#include "html.h"
+#include <errno.h>
+#include <string.h>
+
+using namespace std;
+
+
+FILE *htmlout;
+
+static void css_header(void)
+{
+ if (!htmlout)
+ return;
+
+ fprintf(htmlout, "<style type=\"text/css\">\n");
+
+
+ fprintf(htmlout, "</style>\n");
+}
+
+void init_html_output(const char *filename)
+{
+ htmlout = fopen(filename, "wm");
+
+ if (!htmlout) {
+ fprintf(stderr, "Cannot open output file %s (%s)\n", filename, strerror(errno));
+ }
+
+ fprintf(htmlout, "<!DOCTYPE html PUBLIC \"-//W3C/DTD HTML 4.01//EN\">\n");
+ fprintf(htmlout, "<html>\n\n");
+ fprintf(htmlout, "<head>\n");
+
+ css_header();
+
+ fprintf(htmlout, "</head>\n\n");
+ fprintf(htmlout, "<body>\n");
+}
+
+void finish_html_output(void)
+{
+ if (!htmlout)
+ return;
+
+ fprintf(htmlout, "</body>\n\n");
+ fprintf(htmlout, "</html>\n");
+}
diff --git a/html.h b/html.h
new file mode 100644
index 0000000..dddf80f
--- /dev/null
+++ b/html.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2010, Intel Corporation
+ *
+ * This file is part of PowerTOP
+ *
+ * This program file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program in a file named COPYING; if not, write to the
+ * Free Software Foundation, Inc,
+ * 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ * or just google for it.
+ *
+ * Authors:
+ * Arjan van de Ven <arjan@linux.intel.com>
+ */
+#ifndef __INCLUDE_GUARD_HTML_H_
+#define __INCLUDE_GUARD_HTML_H_
+
+#include <string>
+#include <stdio.h>
+
+using namespace std;
+
+
+extern FILE *htmlout;
+
+extern void init_html_output(const char *filename);
+extern void finish_html_output(void);
+
+
+#endif \ No newline at end of file
diff --git a/main.cpp b/main.cpp
index 3205b78..da07142 100644
--- a/main.cpp
+++ b/main.cpp
@@ -32,6 +32,7 @@
#include "perf/perf.h"
#include "perf/perf_bundle.h"
#include "lib.h"
+#include "html.h"
#include "devices/device.h"
#include "devices/usb.h"
@@ -118,6 +119,7 @@ void one_measurement(int seconds)
process_update_display();
w_display_cpu_cstates();
w_display_cpu_pstates();
+ html_display_cpu_pstates();
tuning_update_display();
end_process_data();
@@ -168,6 +170,23 @@ int main(int argc, char **argv)
debug_learning = 1;
}
+ if (argc > 1) {
+ if (strcmp(argv[1], "--html") == 0) {
+ init_html_output("powertop.html");
+ fprintf(stderr, "Measuring for 20 seconds\n");
+ one_measurement(1);
+ initialize_tuning();
+
+ finish_html_output();
+
+ /* and wrap up */
+ learn_parameters(50, 0);
+ save_all_results("saved_results.powertop");
+ save_parameters("saved_parameters.powertop");
+ exit(0);
+ }
+ }
+
if (debug_learning)
printf("Learning debugging enabled\n");