display.c revision b47b5b34b42fa8056577c43496cdb99a4c99f8d7
/*
* Copyright 2009, Intel Corporation
* Copyright 2009, Sun Microsystems, Inc
*
* This file is part of PowerTOP
*
* 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
*
* Authors:
* Arjan van de Ven <arjan@linux.intel.com>
* Eric C Saxe <eric.saxe@sun.com>
* Aubrey Li <aubrey.li@intel.com>
*/
/*
* GPL Disclaimer
*
* For the avoidance of doubt, except that if any license choice other
* than GPL or LGPL is available it will apply instead, Sun elects to
* use only the General Public License version 2 (GPLv2) at this time
* for any software where a choice of GPL license versions is made
* available with the language indicating that GPLv2 or any later
* version may be used, or where a choice of which version of the GPL
* is applied is otherwise unspecified.
*/
#include <stdlib.h>
#include <string.h>
#include <curses.h>
#include "powertop.h"
static WINDOW *title_bar_window;
static WINDOW *cstate_window;
static WINDOW *wakeup_window;
static WINDOW *acpi_power_window;
static WINDOW *eventstat_window;
static WINDOW *suggestion_window;
static WINDOW *status_bar_window;
if (PTOP_ON_DUMP) \
else \
char g_suggestion_key;
static void
zap_windows(void)
{
if (title_bar_window) {
(void) delwin(title_bar_window);
}
if (cstate_window) {
(void) delwin(cstate_window);
}
if (wakeup_window) {
(void) delwin(wakeup_window);
}
if (acpi_power_window) {
(void) delwin(acpi_power_window);
}
if (eventstat_window) {
(void) delwin(eventstat_window);
}
if (suggestion_window) {
(void) delwin(suggestion_window);
}
if (status_bar_window) {
(void) delwin(status_bar_window);
}
}
void
cleanup_curses(void)
{
(void) endwin();
}
/*
* This part was re-written to be human readable and easy to modify. Please
* try to keep it that way and help us save some time.
*
* Friendly reminder:
* subwin(WINDOW *orig, int nlines, int ncols, int begin_y, int begin_x)
*/
void
setup_windows(void)
{
/*
* These variables are used to properly set the initial y position and
* number of lines in each subwindow, as the number of supported CPU
* states affects their placement.
*/
zap_windows();
pos_y = 0;
(void) wrefresh(status_bar_window);
}
void
initialize_curses(void)
{
(void) initscr();
(void) start_color();
/*
* Enable keyboard mapping
*/
/*
*/
(void) nonl();
/*
* Take input chars one at a time, no wait for \n
*/
(void) cbreak();
/*
* Dont echo input
*/
(void) noecho();
/*
* Turn off cursor
*/
(void) curs_set(0);
(void) atexit(cleanup_curses);
}
void
show_title_bar(void)
{
int i, x = 0, y = 0;
char title_pad[10];
(void) werase(title_bar_window);
/* LINTED: E_SEC_PRINTF_VAR_FMT */
(void) wrefresh(title_bar_window);
(void) werase(status_bar_window);
for (i = 0; i < PTOP_BAR_NSLOTS; i++) {
if (strlen(g_status_bar_slots[i]) == 0)
continue;
}
(void) wnoutrefresh(status_bar_window);
}
void
show_cstates(void)
{
char c[100];
int i;
if (!PTOP_ON_DUMP) {
(void) werase(cstate_window);
}
for (i = 1; i <= g_max_cstate; i++) {
/*
* In situations where the load is too intensive, the system
* might not transition at all.
*/
if (g_cstate_info[i].events > 0)
else
avg = 0;
* 100;
(float)res);
}
if (g_npstates < 2) {
(void) sprintf(c, "%4lu Mhz\t%.1f%%",
} else {
for (i = 0; i < g_npstates; i++) {
g_ncpus_observed/1000000);
}
/*
* display ACPI_PSTATE from P(n) to P(1)
*/
for (i = 0; i < g_npstates - 1; i++) {
(void) sprintf(c, "%4lu Mhz\t%.1f%%",
(long)g_pstate_info[i].speed,
1000000/total_pstates));
}
/*
* Display ACPI_PSTATE P0 according to if turbo
* mode is supported
*/
if (g_turbo_supported) {
/*
* If g_turbo_ratio <= 1.0, it will be ignored.
* we display P(0) as P(1) + 1.
*/
if (g_turbo_ratio <= 1.0) {
} else {
/*
* If g_turbo_ratio > 1.0, that means turbo
* mode works. So, P(0) = ratio * P(1);
*/
}
/*
* Reset the ratio for the next round
*/
g_turbo_ratio = 0.0;
/*
* Setup the string for the display
*/
(void) sprintf(c, "%4lu Mhz(turbo)\t%.1f%%",
(long)p0_speed,
} else {
(void) sprintf(c, "%4lu Mhz\t%.1f%%",
(long)g_pstate_info[i].speed,
}
}
if (!PTOP_ON_DUMP)
(void) wnoutrefresh(cstate_window);
}
void
{
char buffer[1024];
if (!PTOP_ON_DUMP)
(void) werase(acpi_power_window);
if (flag) {
char *c;
rate);
switch (state) {
case 0:
(void) sprintf(c, "(running on AC power, fully "
"charged)");
break;
case 1:
(void) sprintf(c, "(discharging: %3.1f hours)",
break;
case 2:
(void) sprintf(c, "(charging: %3.1f hours)",
break;
case 4:
(void) sprintf(c, "(##critically low battery power##)");
break;
}
}
if (!PTOP_ON_DUMP)
(void) wnoutrefresh(acpi_power_window);
}
void
show_wakeups(double interval)
{
char c[100];
int i, event_sum = 0;
if (!PTOP_ON_DUMP) {
(void) werase(wakeup_window);
}
/*
* calculate the actual total event number
*/
for (i = 0; i < g_tog_p_events; i++, g_p_event++)
/*
* g_total_events is the sum of the number of Cx->C0 transition,
* So when the system is very busy, the idle thread will have no
* chance or very seldom to be scheduled, this could cause >100%
* event report. Re-assign g_total_events to the actual event
* number is a way to avoid this issue.
*/
if (event_sum > g_total_events)
(void) sprintf(c, "Wakeups-from-idle per second: %4.1f\tinterval: "
if (!PTOP_ON_DUMP)
(void) wnoutrefresh(wakeup_window);
}
void
show_eventstats(double interval)
{
char c[100];
int i;
double events;
if (!PTOP_ON_DUMP) {
(void) werase(eventstat_window);
}
/*
* Sort the event report list
*/
if (g_tog_p_events > EVENT_NUM_MAX)
if (PTOP_ON_CPU)
(void) sprintf(c, "Top causes for wakeups on CPU %d:\n",
else
(void) sprintf(c, "Top causes for wakeups:\n");
for (i = 0; i < g_tog_p_events; i++, g_p_event++) {
(double)g_total_events;
else
continue;
}
if (!PTOP_ON_DUMP)
(void) wnoutrefresh(eventstat_window);
}
void
show_suggestion(char *sug)
{
(void) werase(suggestion_window);
(void) wnoutrefresh(suggestion_window);
}
void
update_windows(void)
{
(void) doupdate();
}