diff options
Diffstat (limited to 'src/report')
-rw-r--r-- | src/report/report-data-html.cpp | 128 | ||||
-rw-r--r-- | src/report/report-data-html.h | 76 | ||||
-rw-r--r-- | src/report/report-formatter-base.cpp | 114 | ||||
-rw-r--r-- | src/report/report-formatter-base.h | 52 | ||||
-rw-r--r-- | src/report/report-formatter-csv.cpp | 163 | ||||
-rw-r--r-- | src/report/report-formatter-csv.h | 73 | ||||
-rw-r--r-- | src/report/report-formatter-html.cpp | 376 | ||||
-rw-r--r-- | src/report/report-formatter-html.h | 73 | ||||
-rw-r--r-- | src/report/report-formatter.h | 57 | ||||
-rw-r--r-- | src/report/report-maker.cpp | 187 | ||||
-rw-r--r-- | src/report/report-maker.h | 139 | ||||
-rw-r--r-- | src/report/report.cpp | 217 | ||||
-rw-r--r-- | src/report/report.h | 47 |
13 files changed, 1702 insertions, 0 deletions
diff --git a/src/report/report-data-html.cpp b/src/report/report-data-html.cpp new file mode 100644 index 0000000..d9b713e --- /dev/null +++ b/src/report/report-data-html.cpp @@ -0,0 +1,128 @@ +#include "report-data-html.h" + +void init_div(struct tag_attr *div_attr, const char *css_class, const char *css_id) +{ + div_attr->css_class=css_class; + div_attr->css_id=css_id; +} + +void +init_top_table_attr(struct table_attributes *table_css, int rows, int cols){ + table_css->pos_table_title=L; + table_css->table_class="emphasis1"; + table_css->th_class="table_sysinfo"; + table_css->td_class=""; + table_css->tr_class=""; + table_css->title_mod=0; + table_css->rows=rows; + table_css->cols=cols; +} + +void init_title_attr(struct tag_attr *title_attr) +{ + title_attr->css_class="content_title"; + title_attr->css_id=""; +} + +void init_std_table_attr(struct table_attributes *table_css, int rows, int cols){ + table_css->table_class="emphasis2"; + table_css->tr_class="emph1"; + table_css->th_class="emph_title"; + table_css->td_class=""; + table_css->pos_table_title=T; + table_css->title_mod=0; + table_css->rows=rows; + table_css->cols=cols; +} +void init_std_side_table_attr(struct table_attributes *table_css, int rows, int cols){ + table_css->table_class="emphasis2 side_by_side_left"; + table_css->tr_class="emph1"; + table_css->th_class="emph_title"; + table_css->td_class=""; + table_css->pos_table_title=T; + table_css->title_mod=0; + table_css->rows=rows; + table_css->cols=cols; +} + + +void init_pkg_table_attr(struct table_attributes *table_css, int rows, int cols){ + table_css->table_class="emphasis2 side_by_side_left"; + table_css->tr_class=""; + table_css->th_class="title"; + table_css->td_class="package"; + table_css->pos_table_title=T; + table_css->title_mod=0; + table_css->rows=rows; + table_css->cols=cols; +} + +void init_core_table_attr(struct table_attributes *table_css, int title_mod, + int rows, int cols){ + table_css->table_class="emphasis2 side_by_side_left"; + table_css->tr_class=""; + table_css->th_class="title"; + table_css->td_class="core"; + table_css->pos_table_title=TC; + table_css->title_mod=title_mod; + table_css->rows=rows; + table_css->cols=cols; +} + +void init_cpu_table_attr(struct table_attributes *table_css, int title_mod, + int rows, int cols){ + table_css->table_class="emphasis2 side_by_side_left"; + table_css->tr_class=""; + table_css->th_class="title"; + table_css->td_class="cpu"; + table_css->pos_table_title=TLC; + table_css->title_mod=title_mod; + table_css->rows=rows; + table_css->cols=cols; +} + + +void init_nowarp_table_attr(struct table_attributes *table_css, int rows, int cols){ + table_css->table_class="emphasis2"; + table_css->tr_class="emph1"; + table_css->th_class="emph_title"; + table_css->td_class="no_wrap"; + table_css->pos_table_title=T; + table_css->title_mod=0; + table_css->rows=rows; + table_css->cols=cols; +} + +void init_tune_table_attr(struct table_attributes *table_css, int rows, int cols){ + table_css->table_class="emphasis2"; + table_css->tr_class="tune"; + table_css->th_class="emph_title"; + table_css->td_class=""; + table_css->pos_table_title=T; + table_css->rows=rows; + table_css->cols=cols; +} + +void init_wakeup_table_attr(struct table_attributes *table_css, int rows, int cols){ + table_css->table_class="emphasis2"; + table_css->tr_class="tune"; + table_css->th_class="emph_title"; + table_css->td_class=""; + table_css->pos_table_title=T; + table_css->rows=rows; + table_css->cols=cols; +} + +/* Other Helper Functions */ +string +double_to_string(double dval) +{ + ostringstream dtmp; + string str; + dtmp << dval; + str= dtmp.str(); + str = str.substr(0, str.find(".")+2); + return str; +} + + diff --git a/src/report/report-data-html.h b/src/report/report-data-html.h new file mode 100644 index 0000000..e506f5a --- /dev/null +++ b/src/report/report-data-html.h @@ -0,0 +1,76 @@ +#ifndef PowerTop_REPORT_DATA_HTML_H_C58C116411234A34AC2EFB8D23A69713 +#define PowerTop_REPORT_DATA_HTML_H_C58C116411234A34AC2EFB8D23A69713 + +#include <string> +#include <sstream> + +using namespace std; + +struct tag_attr { + const char *css_class; + const char *css_id; +}; +/* T:Top, L:Left, TL:Top-Left, TLC: Top-Left-Center */ +enum position { T, L, TL, TC, TLC }; + +struct table_attributes { + const char *table_class; + const char *td_class; + const char *tr_class; + const char *th_class; + position pos_table_title; + int title_mod; + int rows; + int cols; +}; + +struct table_size { + int rows; + int cols; +}; + + +/* Definition of css attributes for the cases that apply to powertop + * html report + * */ + +void +init_div(struct tag_attr *div_attr, const char *css_class, const char *css_id); + +void +init_top_table_attr(struct table_attributes *table_css, int rows, int cols); + +void +init_title_attr(struct tag_attr *title_attr); + +void +init_std_table_attr(struct table_attributes *table_css, int rows, int cols); + +void +init_std_side_table_attr(struct table_attributes *table_css, int rows, + int cols); + +void +init_pkg_table_attr(struct table_attributes *table_css, int rows, int cols); + +void +init_core_table_attr(struct table_attributes *table_css, int title_mod, + int rows, int cols); + +void +init_cpu_table_attr(struct table_attributes *table_css, int title_mod, + int rows, int cols); +void +init_nowarp_table_attr(struct table_attributes *table_css, int rows, int cols); + +void +init_tune_table_attr(struct table_attributes *table_css, int rows, int cols); + +void +init_wakeup_table_attr(struct table_attributes *table_css, int rows, int cols); + +/* Other helper functions */ +string +double_to_string(double dval); + +#endif diff --git a/src/report/report-formatter-base.cpp b/src/report/report-formatter-base.cpp new file mode 100644 index 0000000..4e10603 --- /dev/null +++ b/src/report/report-formatter-base.cpp @@ -0,0 +1,114 @@ +/* Copyright (c) 2012 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * 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. + * + * Common part of report_formatter_csv and report_formatter_html. + * Written by Igor Zhbanov <i.zhbanov@samsung.com> + * 2012.10 */ + +/* Uncomment to disable asserts */ +/*#define NDEBUG*/ + +#include <stdio.h> +#include <assert.h> +#include <stdarg.h> + +#include "report-formatter-base.h" + +/* ************************************************************************ */ + +const char * +report_formatter_string_base::get_result() +{ + return result.c_str(); +} + +/* ************************************************************************ */ + +void +report_formatter_string_base::clear_result() +{ + result.clear(); +} + +/* ************************************************************************ */ + +void +report_formatter_string_base::add(const char *str) +{ + assert(str); + + result += escape_string(str); +} + +/* ************************************************************************ */ + +void +report_formatter_string_base::add_exact(const char *str) +{ + assert(str); + + result += std::string(str); +} + +/* ************************************************************************ */ + +#define LINE_SIZE 8192 + +void +report_formatter_string_base::addv(const char *fmt, va_list ap) +{ + char str[LINE_SIZE]; + + assert(fmt); + + vsnprintf(str, sizeof(str), fmt, ap); + add(str); +} + +/* ************************************************************************ */ + +void +report_formatter_string_base::addf(const char *fmt, ...) +{ + va_list ap; + + assert(fmt); + + va_start(ap, fmt); + addv(fmt, ap); + va_end(ap); +} + +/* ************************************************************************ */ + +void +report_formatter_string_base::addf_exact(const char *fmt, ...) +{ + char str[LINE_SIZE]; + va_list ap; + + assert(fmt); + + va_start(ap, fmt); + vsnprintf(str, sizeof(str), fmt, ap); + add_exact(str); + va_end(ap); +} diff --git a/src/report/report-formatter-base.h b/src/report/report-formatter-base.h new file mode 100644 index 0000000..e35a2ff --- /dev/null +++ b/src/report/report-formatter-base.h @@ -0,0 +1,52 @@ +/* Copyright (c) 2012 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * 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. + * + * Common part of report_formatter_csv and report_formatter_html. + * Written by Igor Zhbanov <i.zhbanov@samsung.com> + * 2012.10 */ + +#ifndef _REPORT_FORMATTER_BASE_H_ +#define _REPORT_FORMATTER_BASE_H_ + +#include "report-formatter.h" + +class report_formatter_string_base: public report_formatter +{ +public: + virtual const char *get_result(); + virtual void clear_result(); + + virtual void add(const char *str); + virtual void addv(const char *fmt, va_list ap); + +protected: + void add_exact(const char *str); + void addf(const char *fmt, ...) + __attribute__ ((format (printf, 2, 3))); + void addf_exact(const char *fmt, ...) + __attribute__ ((format (printf, 2, 3))); + + virtual std::string escape_string(const char *str) = 0; + + std::string result; +}; + +#endif /* _REPORT_FORMATTER_BASE_H_ */ diff --git a/src/report/report-formatter-csv.cpp b/src/report/report-formatter-csv.cpp new file mode 100644 index 0000000..0360fd8 --- /dev/null +++ b/src/report/report-formatter-csv.cpp @@ -0,0 +1,163 @@ +/* Copyright (c) 2012 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * 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. + * + * CSV report generator. + * Written by Igor Zhbanov <i.zhbanov@samsung.com> + * 2012.10 */ + +/* Uncomment to disable asserts */ +/*#define NDEBUG*/ + +#include <stdio.h> +#include <assert.h> +#include <stdarg.h> + +#include "report-formatter-csv.h" +#include "report-data-html.h" + + +/* ************************************************************************ */ +report_formatter_csv::report_formatter_csv() +{ + /* Do nothing special */ +} + +/* ************************************************************************ */ +void +report_formatter_csv::finish_report() +{ + /* Do nothing special */ +} + + +string +report_formatter_csv::escape_string(const char *str) +{ + string res; + + assert(str); + + for (const char *i = str; *i; i++) { + switch (*i) { + case '"': + res += '"'; +#ifdef REPORT_CSV_SPACE_NEED_QUOTES + case ' ': +#endif /* REPORT_CSV_SPACE_NEED_QUOTES */ + case '\n': + case REPORT_CSV_DELIMITER: + csv_need_quotes = true; + break; + } + + res += *i; + } + + return res; +} + + + + +/* Report Style */ +void +report_formatter_csv::add_header() +{ + add_exact("____________________________________________________________________\n"); +} + +void +report_formatter_csv::end_header() +{ + /* Do nothing */ +} + +void +report_formatter_csv::add_logo() +{ + add_exact("\t\t\tP o w e r T O P\n"); +} + + +void +report_formatter_csv::add_div(struct tag_attr * div_attr) +{ + add_exact("\n"); +} + +void +report_formatter_csv::end_div() +{ + /*Do nothing*/ +} + +void +report_formatter_csv::add_title(struct tag_attr *title_att, const char *title) +{ + add_exact("____________________________________________________________________\n"); + addf_exact(" * * * %s * * *\n", title); +} + +void +report_formatter_csv::add_navigation() +{ + /* No nav in csv - thinking on table of contents */ +} + +void +report_formatter_csv::add_summary_list(string *list, int size) +{ + int i; + add_exact("\n"); + for (i=0; i < size; i+=2){ + addf_exact("%s %s", list[i].c_str(), list[i+1].c_str()); + if(i < (size - 1)) + add_exact(";"); + } + add_exact("\n"); +} + +void +report_formatter_csv::add_table(string *system_data, struct table_attributes* tb_attr) +{ + int i, j; + int offset=0; + string tmp_str=""; + int empty_row=0; + add_exact("\n"); + for (i=0; i < tb_attr->rows; i++){ + for (j=0; j < tb_attr->cols; j++){ + offset = i * (tb_attr->cols) + j; + tmp_str=system_data[offset]; + + if(tmp_str == " ") + empty_row+=1; + else{ + addf_exact("%s", system_data[offset].c_str()); + if(j < (tb_attr->cols - 1)) + add_exact(";"); + } + } + if(empty_row < tb_attr->cols) + add_exact("\n"); + empty_row=0; + } +} diff --git a/src/report/report-formatter-csv.h b/src/report/report-formatter-csv.h new file mode 100644 index 0000000..7edfc01 --- /dev/null +++ b/src/report/report-formatter-csv.h @@ -0,0 +1,73 @@ +/* Copyright (c) 2012 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * 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. + * + * CSV report generator. + * Written by Igor Zhbanov <i.zhbanov@samsung.com> + * 2012.10 */ + +#ifndef _REPORT_FORMATTER_CSV_H_ +#define _REPORT_FORMATTER_CSV_H_ + +#include <string> + +#include "report-formatter-base.h" + +/* Offices like semicolon separated values instead of comma */ +#define REPORT_CSV_DELIMITER ',' + +/* "a,b,c" vs "a, b, c" */ +/*#define REPORT_CSV_ADD_SPACE*/ + +/* Whether to escape with quotes empty cell values */ +/*#define REPORT_CSV_ESCAPE_EMPTY*/ + +/* Whether to escape with quotes empty cell values with spaces */ +/*#define REPORT_CSV_SPACE_NEED_QUOTES*/ + +using namespace std; + +/* ************************************************************************ */ + +class report_formatter_csv: public report_formatter_string_base +{ +public: + report_formatter_csv(); + void finish_report(); + + /* Report Style */ + void add_logo(); + void add_header(); + void end_header(); + void add_div(struct tag_attr *div_attr); + void end_div(); + void add_title(struct tag_attr *title_att, const char *title); + void add_navigation(); + void add_summary_list(string *list, int size); + void add_table(string *system_data, struct table_attributes *tb_attr); + +private: + void add_quotes(); + string escape_string(const char *str); + bool csv_need_quotes; + size_t text_start; +}; + +#endif /* _REPORT_FORMATTER_CSV_H_ */ diff --git a/src/report/report-formatter-html.cpp b/src/report/report-formatter-html.cpp new file mode 100644 index 0000000..387bd76 --- /dev/null +++ b/src/report/report-formatter-html.cpp @@ -0,0 +1,376 @@ +/* Copyright (c) 2012 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * 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. + * + * HTML report generator. + * Written by Igor Zhbanov <i.zhbanov@samsung.com> + * 2012.10 */ + +/* Uncomment to disable asserts */ +/*#define NDEBUG*/ + +#include <stdio.h> +#include <assert.h> +#include <stdarg.h> + +#include "report-formatter-html.h" +#include "css.h" /* For HTML-report header */ + +/* ************************************************************************ */ + +#ifdef EXTERNAL_CSS_FILE /* Where is it defined? */ +static const char report_html_alternative_head[] = + "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " + "\"http://www.w3.org/TR/html4/loose.dtd\">\n" + "<html>\n" + "<head>\n" + "<title>PowerTOP report</title>\n" + "<link rel=\"stylesheet\" href=\"powertop.css\">\n" + "</head>\n" + "<body>\n"; +#endif /* EXTERNAL_CSS_FILE */ + +/* ************************************************************************ */ + +static const char report_html_footer[] = + "</body>\n" + "</html>\n"; + +/* ************************************************************************ */ + +void +report_formatter_html::init_markup() +{ + /*here all html code*/ +} + +/* ************************************************************************ */ + +report_formatter_html::report_formatter_html() +{ + init_markup(); + add_doc_header(); +} + +/* ************************************************************************ */ + +void +report_formatter_html::finish_report() +{ + add_doc_footer(); +} + +/* ************************************************************************ */ + +void +report_formatter_html::add_doc_header() +{ +#ifdef EXTERNAL_CSS_FILE /* Where is it defined? */ + add_exact(report_html_alternative_head); +#else /* !EXTERNAL_CSS_FILE */ + add_exact(css); +#endif /* !EXTERNAL_CSS_FILE */ +} + +/* ************************************************************************ */ + +void +report_formatter_html::add_doc_footer() +{ + add_exact(report_html_footer); +} + +/* ************************************************************************ */ +string +report_formatter_html::escape_string(const char *str) +{ + string res; + + assert(str); + + for (const char *i = str; *i; i++) { + switch (*i) { + case '<': + res += "<"; + continue; + case '>': + res += ">"; + continue; + case '&': + res += "&"; + continue; +#ifdef REPORT_HTML_ESCAPE_QUOTES + case '"': + res += """; + continue; + case '\'': + res += "'"; + continue; +#endif /* REPORT_HTML_ESCAPE_QUOTES */ + } + + res += *i; + } + + return res; +} + + +/* Report Style */ +void +report_formatter_html::add_logo() +{ + add_exact("<img alt=\"PowerTop\" class=\"pwtop_logo\" src=\"data:image/png;base64," + "iVBORw0KGgoAAAANSUhEUgAAAbQAAABDCAYAAAD01PBTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA" + "GXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAGsxJREFUeNrsXQt4FNXZ/nLhmutq" + "VdAKMXJHTMhiLGAuLUEfSg2xSFSUgIkkRPQ3QiHxqcRwswQrRq2EBKjhapvU3yCgtaQ+CRGUSyAB" + "vNDfRhArqEA2FwjksvnPN0xokpnZPWd2dnd297w851kyt3OZ+c4773e+c8aro6MDODg4ODg4XB3e" + "vAk4ODg4ODihcXBwcHB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VgjKTwzlCbBs2bBDSgAEDAJUdjsN1" + "ui2HDRsGH354RfgEDCqwS01mOP+9GU6R/3+psFq+HB5JTISUlJSGgICA2aR8pfaoN7r/SGdD+9FC" + "LYnFWUTqMtD5x0tRiRxmeG5wPC2R1Mkj7p/o6ssV54uh6zXVjioeQ7XLPDHwwxK8UFl4Oj7dvz+Y" + "/OScPXv2ubzXX4fKykqHlwFJ8sUXX4SIsWNryJ8J4ydMOMUfTw4O1wchuK7uV3wZoHXH9pxHVkUI" + "jK+WwwmNDvv37YslP0VHjx4dvHHjRjhaXW33PP38/SAlOQWVWT2S6oSJE/P4neDg4ODghKYJ9n2y" + "bw6SCxJbcXExVH6ivWJDRZacnAzRUdHg7+//OuY38b6JJt76HBwcHJzQNMcnlZVIbBnnzp0L21tZ" + "Kbgiq21QbbcMuBmi74uGKVOm4NjbaVSDJOXdFxXFiYyDg4ODE5r9Ubl3bwj5QXLD9a7C0BVZffQo" + "NDY1wddffy0c0yT+f8Att8AAcRFkorxg6JAhMIQkDB4hqgxJrJyk0qjo6FLeshwcHByc0JyGvRUV" + "GEASTlIsSSFiQuD2MJJwLKxTxpnE/wspOibmFG9BDg4ODk5oHBwcHBwcivDmTcDBwcHB4Q74fwEG" + "APNNNssrHc8WAAAAAElFTkSuQmCC\">"); +} + +void +report_formatter_html::add_header() +{ + add_exact("<header id=\"main_header\">\n"); +} + +void +report_formatter_html::end_header() +{ + add_exact("</header>\n\n"); +} + +void +report_formatter_html::add_div(struct tag_attr * div_attr) +{ + string empty=""; + string tmp_str; + + if (div_attr->css_class == empty && div_attr->css_id == empty) + add_exact("<div>\n"); + + else if (div_attr->css_class == empty && div_attr->css_id != empty) + addf_exact("<div id=\"%s\">\n", div_attr->css_id); + + else if (div_attr->css_class != empty && div_attr->css_id == empty) + addf_exact("<div class=\"%s\">\n", div_attr->css_class); + + else if (div_attr->css_class != empty && div_attr->css_id != empty) + addf_exact("<div class=\"%s\" id=\"%s\">\n", + div_attr->css_class, div_attr->css_id); +} + +void +report_formatter_html::end_div() +{ + add_exact("</div>\n"); +} + +void +report_formatter_html::add_title(struct tag_attr *title_att, const char *title) +{ + addf_exact("<h2 class=\"%s\"> %s </h2>\n", title_att->css_class, title); +} + +void +report_formatter_html::add_navigation() +{ + add_exact("<br/><div id=\"main_menu\"> </div>\n"); +} + +void +report_formatter_html::add_summary_list(string *list, int size) +{ + int i; + add_exact("<div><br/> <ul>\n"); + for (i=0; i < size; i+=2){ + addf_exact("<li class=\"summary_list\"> <b> %s </b> %s </li>", + list[i].c_str(), list[i+1].c_str()); + } + add_exact("</ul> </div> <br />\n"); +} + + +void +report_formatter_html::add_table(string *system_data, struct table_attributes* tb_attr) +{ + int i, j; + int offset=0; + string empty=""; + + if (tb_attr->table_class == empty) + add_exact("<table>\n"); + else + addf_exact("<table class=\"%s\">\n", tb_attr->table_class); + + for (i=0; i < tb_attr->rows; i++){ + if (tb_attr->tr_class == empty) + add_exact("<tr> "); + else + addf_exact("<tr class=\"%s\"> ", tb_attr->tr_class); + + for (j=0; j < tb_attr->cols; j++){ + offset = i * (tb_attr->cols) + j; + + if (tb_attr->pos_table_title == T && i==0) + addf_exact("<th class=\"%s\"> %s </th> ", + tb_attr->th_class,system_data[offset].c_str()); + else if (tb_attr->pos_table_title == L && j==0) + addf_exact("<th class=\"%s\"> %s </th> ", + tb_attr->th_class, system_data[offset].c_str()); + else if (tb_attr->pos_table_title == TL && ( i==0 || j==0 )) + addf_exact("<th class=\"%s\"> %s </th> ", + tb_attr->th_class, system_data[offset].c_str()); + else if (tb_attr->pos_table_title == TC && ((i % tb_attr->title_mod ) == 0)) + addf_exact("<th class=\"%s\"> %s </th> ", tb_attr->th_class, + system_data[offset].c_str()); + else if (tb_attr->pos_table_title == TLC && ((i % tb_attr->title_mod) == 0 || j==0)) + addf_exact("<th class=\"%s\"> %s </th> ", tb_attr->th_class, + system_data[offset].c_str()); + else + if ( tb_attr->td_class == empty) + addf_exact("<td > %s </td> ", system_data[offset].c_str()); + else + addf_exact("<td class=\"%s\"> %s </td> ", tb_attr->td_class, + system_data[offset].c_str()); + } + add_exact("</tr>\n"); + } + add_exact("</table>\n"); +} + diff --git a/src/report/report-formatter-html.h b/src/report/report-formatter-html.h new file mode 100644 index 0000000..c003fd9 --- /dev/null +++ b/src/report/report-formatter-html.h @@ -0,0 +1,73 @@ +/* Copyright (c) 2012 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * 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. + * + * HTML report generator. + * Written by Igor Zhbanov <i.zhbanov@samsung.com> + * 2012.10 */ + +#ifndef _REPORT_FORMATTER_HTML_H_ +#define _REPORT_FORMATTER_HTML_H_ + +#include <string> + +#include "report-formatter-base.h" +#include "report-data-html.h" + +using namespace std; + +/* Whether to replace " and ' in HTML by " and ' respectively */ +/*#define REPORT_HTML_ESCAPE_QUOTES*/ + +/* ************************************************************************ */ + +struct html_section { + const char *id; +}; + +/* ************************************************************************ */ + +class report_formatter_html: public report_formatter_string_base +{ +public: + report_formatter_html(); + void finish_report(); + + /* Report Style */ + void add_logo(); + void add_header(); + void end_header(); + void add_div(struct tag_attr *div_attr); + void end_div(); + void add_title(struct tag_attr *title_att, const char *title); + void add_navigation(); + void add_summary_list(string *list, int size); + void add_table(string *system_data, struct table_attributes *tb_attr); + +private: + /* Document structure related functions */ + void init_markup(); + void add_doc_header(); + void add_doc_footer(); + string escape_string(const char *str); + +}; + +#endif /* _REPORT_FORMATTER_HTML_H_ */ diff --git a/src/report/report-formatter.h b/src/report/report-formatter.h new file mode 100644 index 0000000..940b5cf --- /dev/null +++ b/src/report/report-formatter.h @@ -0,0 +1,57 @@ +/* Copyright (c) 2012 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * 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. + * + * report_formatter interface. + * Written by Igor Zhbanov <i.zhbanov@samsung.com> + * 2012.10 */ + +#ifndef _REPORT_FORMATTER_H_ +#define _REPORT_FORMATTER_H_ + +#include "report-maker.h" +using namespace std; + +class report_formatter +{ +public: + virtual ~report_formatter() {} + + virtual void finish_report() {} + virtual const char *get_result() {return "Basic report_formatter::get_result() call\n";} + virtual void clear_result() {} + + virtual void add(const char *str) {} + virtual void addv(const char *fmt, va_list ap) {} + + /* *** Report Style *** */ + virtual void add_logo() {} + virtual void add_header() {} + virtual void end_header() {} + virtual void add_div(struct tag_attr *div_attr) {} + virtual void end_div() {} + virtual void add_title(struct tag_attr *att_title, const char *title) {} + virtual void add_navigation() {} + virtual void add_summary_list(string *list, int size) {} + virtual void add_table(string *system_data, + struct table_attributes *tb_attr) {} +}; + +#endif /* _REPORT_FORMATTER_H_ */ diff --git a/src/report/report-maker.cpp b/src/report/report-maker.cpp new file mode 100644 index 0000000..4049a54 --- /dev/null +++ b/src/report/report-maker.cpp @@ -0,0 +1,187 @@ +/* Copyright (c) 2012 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * 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. + * + * Generic report generator. + * Written by Igor Zhbanov <i.zhbanov@samsung.com> + * 2012.10 */ + +/* Uncomment to disable asserts */ +/*#define NDEBUG*/ + +#include <assert.h> +#include <stdarg.h> + +#include "report-maker.h" +#include "report-formatter-csv.h" +#include "report-formatter-html.h" + +/* ************************************************************************ */ + +report_maker::report_maker(report_type t) +{ + type = t; + formatter = NULL; + setup_report_formatter(); + clear_result(); /* To reset state and add document header */ +} + +/* ************************************************************************ */ + +report_maker::~report_maker() +{ + delete formatter; +} + +/* ************************************************************************ */ + +void +report_maker::finish_report() +{ + formatter->finish_report(); +} + +/* ************************************************************************ */ + +const char * +report_maker::get_result() +{ + return formatter->get_result(); +} + +/* ************************************************************************ */ + +void +report_maker::clear_result() +{ + formatter->clear_result(); +} + +/* ************************************************************************ */ + +report_type +report_maker::get_type() +{ + return type; +} + +/* ************************************************************************ */ + +void +report_maker::set_type(report_type t) +{ + clear_result(); + type = t; + setup_report_formatter(); +} + +/* ************************************************************************ */ + +void +report_maker::setup_report_formatter() +{ + delete formatter; + + if (type == REPORT_HTML) + formatter = new report_formatter_html(); + else if (type == REPORT_CSV) + formatter = new report_formatter_csv(); + else if (type == REPORT_OFF) + formatter = new report_formatter(); + else + assert(false); +} + +/* ************************************************************************ */ + +void +report_maker::add(const char *str) +{ + assert(str); + formatter->add(str); +} + +/* ************************************************************************ */ + +void +report_maker::addf(const char *fmt, ...) +{ + va_list ap; + assert(fmt); + va_start(ap, fmt); + formatter->addv(fmt, ap); + va_end(ap); +} + +/* *** Report Style *** */ +void +report_maker::add_logo() +{ + formatter->add_logo(); +} + +void +report_maker::add_header() +{ + formatter->add_header(); +} + +void +report_maker::end_header() +{ + formatter->end_header(); +} + +void +report_maker::add_title(struct tag_attr *att_title, const char *title) +{ + formatter->add_title(att_title, title); +} + +void +report_maker::add_div(struct tag_attr * div_attr) +{ + formatter->add_div(div_attr); +} + +void +report_maker::end_div() +{ + formatter->end_div(); +} + +void +report_maker::add_navigation() +{ + formatter->add_navigation(); +} + +void +report_maker::add_summary_list(string *list, int size) +{ + formatter->add_summary_list(list, size); +} + +void +report_maker::add_table(string *system_data, struct table_attributes *tb_attr) +{ + formatter->add_table(system_data, tb_attr); +} + diff --git a/src/report/report-maker.h b/src/report/report-maker.h new file mode 100644 index 0000000..bda4cef --- /dev/null +++ b/src/report/report-maker.h @@ -0,0 +1,139 @@ +/* Copyright (c) 2012 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * 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. + * + * Generic report generator. + * Written by Igor Zhbanov <i.zhbanov@samsung.com> + * 2012.10 */ + +#ifndef _REPORT_MAKER_H_ +#define _REPORT_MAKER_H_ + +/* This report generator implements the following document structure: + * body + * \---> section + * |---> Title + * |---> paragraph + * |---> table + * |---> list + * + * The report body consists of a number of sections (a.k.a. <div>s, + * a.k.a. tabs). + * Each section can contain titles (<h2>), paragraphs (<p>) + * and tables (<table>). + * + * A header is a single line of text. + * + * Paragraphs can contain only text. + * + * + * Each section, table, row or cell could have its own formatting. + * + * Example of usage: + * report_maker report(REPORT_OFF); + * + * report.set_type(REPORT_HTML); + * report.add_div + * report.add_title + * report.add_list + * report.add_table + * report.finish_report(); + * const char *result = report.get_result(); + */ + +#include <stdarg.h> + +#include <string> +using namespace std; +/* Conditional gettext. We need original strings for CSV. */ +#ifdef ENABLE_NLS +#define __(STRING) \ + ((report.get_type() == REPORT_CSV) ? (STRING) : gettext(STRING)) +#else +#define __(STRING) (STRING) +#endif + +#ifndef UNUSED +#define UNUSED __attribute__((unused)) +#endif /* UNUSED */ + +/* ************************************************************************ */ + +enum report_type { + REPORT_OFF, + REPORT_HTML, + REPORT_CSV +}; + +/* ************************************************************************ */ + +enum section_type { + SECTION_DEFAULT, + SECTION_SYSINFO, + SECTION_CPUIDLE, + SECTION_CPUFREQ, + SECTION_DEVFREQ, + SECTION_DEVPOWER, + SECTION_SOFTWARE, + SECTION_SUMMARY, + SECTION_TUNING, + SECTION_MAX /* Must be last in this enum */ +}; + + +/* ************************************************************************ */ + +class report_formatter; + +class report_maker +{ +public: + report_maker(report_type t); + ~report_maker(); + + report_type get_type(); + void set_type(report_type t); + + void addf(const char *fmt, ...) + __attribute__ ((format (printf, 2, 3))); + + void finish_report(); + const char *get_result(); + void clear_result(); + + void add(const char *str); + + /* *** Report Style *** */ + void add_header(); + void end_header(); + void add_logo(); + void add_div(struct tag_attr *div_attr); + void end_div(); + void add_title(struct tag_attr *att_title, const char *title); + void add_navigation(); + void add_summary_list(string *list, int size); + void add_table(string *system_data, struct table_attributes *tb_attr); + +private: + void setup_report_formatter(); + report_type type; + report_formatter *formatter; +}; +#endif /* _REPORT_MAKER_H_ */ diff --git a/src/report/report.cpp b/src/report/report.cpp new file mode 100644 index 0000000..2efe835 --- /dev/null +++ b/src/report/report.cpp @@ -0,0 +1,217 @@ +/* + * Copyright 2011, 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> + * Chris Ferron <chris.e.ferron@linux.intel.com> + */ + +#include "lib.h" +#include "report.h" +#include "report-maker.h" +#include <errno.h> +#include <string.h> +#include <utility> +#include <iostream> +#include <fstream> +#include <string.h> +#include <malloc.h> +#include <unistd.h> +#include <limits.h> +#include "report-data-html.h" + +using namespace std; + +struct reportstream reportout; +report_type reporttype = REPORT_OFF; +report_maker report(REPORT_OFF); + +string cpu_model(void) +{ + ifstream file; + + file.open("/proc/cpuinfo", ios::in); + + if (!file) + return ""; + + while (file) { + char line[4096]; + file.getline(line, 4096); + if (strstr(line, "model name")) { + char *c; + c = strchr(line, ':'); + if (c) { + file.close(); + c++; + return c; + } + } + } + file.close(); + return ""; +} + +static string read_os_release(const string &filename) +{ + ifstream file; + char content[4096]; + char *c; + const char *pname = "PRETTY_NAME="; + string os(""); + + file.open(filename.c_str(), ios::in); + if (!file) + return ""; + while (file.getline(content, 4096)) { + if (strncasecmp(pname, content, strlen(pname)) == 0) { + c = strchr(content, '='); + if (!c) + break; + c += 1; + if (*c == '"' || *c == '\'') + c += 1; + *strchrnul(c, '"') = 0; + *strchrnul(c, '\'') = 0; + os = c; + break; + } + } + file.close(); + return os; +} + +static void system_info(void) +{ + string str; + char version_date[64]; + time_t now = time(NULL); + + /* div attr css_class and css_id */ + tag_attr div_attr; + init_div(&div_attr, "sys_info", ""); + + /* Set Table attributes, rows, and cols */ + table_attributes sys_table; + init_top_table_attr(&sys_table, 5, 2); + + /* Set Title attributes */ + tag_attr title_attr; + init_title_attr(&title_attr); + + /* Set array of data in row Major order */ + string *system_data = new string[sys_table.rows * sys_table.cols]; + system_data[0]=__("PowerTOP Version"); + snprintf(version_date, sizeof(version_date), "%s ran at %s", PACKAGE_VERSION, ctime(&now)); + system_data[1]=version_date; + + str = read_sysfs_string("/proc/version"); + size_t found = str.find(" "); + found = str.find(" ", found+1); + found = str.find(" ", found+1); + str = str.substr(0,found); + system_data[2]=__("Kernel Version"); + system_data[3]=str.c_str(); + + str = read_sysfs_string("/sys/devices/virtual/dmi/id/board_vendor"); + system_data[4]=__("System Name"); + system_data[5]= str.c_str(); + str = read_sysfs_string("/sys/devices/virtual/dmi/id/board_name"); + system_data[5].append(str.c_str()); + str = read_sysfs_string("/sys/devices/virtual/dmi/id/product_version"); + system_data[5].append(str.c_str()); + str = cpu_model(); + system_data[6]=__("CPU Information"); + stringstream n_proc; + n_proc << sysconf(_SC_NPROCESSORS_ONLN); + system_data[7]= n_proc.str(); + system_data[7].append(str.c_str()); + + str = read_sysfs_string("/etc/system-release"); + if (str.length() < 1) + str = read_sysfs_string("/etc/redhat-release"); + if (str.length() < 1) + str = read_os_release("/etc/os-release"); + + system_data[8]=__("OS Information"); + system_data[9]=str; + + /* Report Output */ + report.add_header(); + report.add_logo(); + report.add_div(&div_attr); + report.add_title(&title_attr, __("System Information")); + report.add_table(system_data, &sys_table); + report.end_header(); + report.end_div(); + report.add_navigation(); + delete [] system_data; +} + +void init_report_output(char *filename_str, int iterations) +{ + size_t period; + string filename; + time_t stamp; + char datestr[200]; + + if (iterations == 1) + snprintf(reportout.filename, sizeof(reportout.filename), "%s", filename_str); + else + { + filename = string(filename_str); + period = filename.find_last_of("."); + if (period > filename.length()) + period = filename.length(); + memset(&datestr, 0, 200); + memset(&stamp, 0, sizeof(time_t)); + stamp = time(NULL); + strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M%S", localtime(&stamp)); + snprintf(reportout.filename, sizeof(reportout.filename), "%s-%s%s", + filename.substr(0, period).c_str(), datestr, + filename.substr(period).c_str()); + } + + reportout.report_file = fopen(reportout.filename, "wm"); + if (!reportout.report_file) { + fprintf(stderr, _("Cannot open output file %s (%s)\n"), + reportout.filename, strerror(errno)); + } + + report.set_type(reporttype); + system_info(); +} + +void finish_report_output(void) +{ + if (reporttype == REPORT_OFF) + return; + + report.finish_report(); + if (reportout.report_file) + { + fprintf(stderr, _("PowerTOP outputting using base filename %s\n"), reportout.filename); + fputs(report.get_result(), reportout.report_file); + fdatasync(fileno(reportout.report_file)); + fclose(reportout.report_file); + } + report.clear_result(); +} diff --git a/src/report/report.h b/src/report/report.h new file mode 100644 index 0000000..c1aee1b --- /dev/null +++ b/src/report/report.h @@ -0,0 +1,47 @@ +/* + * 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_REPORT_H_ +#define __INCLUDE_GUARD_REPORT_H_ + +#include <string> +#include <stdio.h> +#include <limits.h> + +#include "report-maker.h" + +using namespace std; + +struct reportstream { + FILE *report_file; + char filename[PATH_MAX]; +}; + +extern report_type reporttype; +extern report_maker report; +extern struct reportstream reportout; +extern void init_report_output(char *filename_str, int iterations); +extern void finish_report_output(void); + +#endif |