aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Čerman2019-06-19 00:06:34 +0200
committerOndrej Čerman2019-06-19 00:06:34 +0200
commitb1dd2f531524d64357775b6dbcfde9474eb740c4 (patch)
treef8d621fca67221ef40bc061dd39417e51ea05633
parentd585178609b19406fd78ae11ddb4209a9a66f365 (diff)
Added min/max columns
-rw-r--r--src/gui.c76
-rw-r--r--src/include/zenmonitor.h2
-rw-r--r--src/ss/msr.c26
-rw-r--r--src/ss/zenpower.c27
4 files changed, 98 insertions, 33 deletions
diff --git a/src/gui.c b/src/gui.c
index 6d289a8..0b16281 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -12,6 +12,8 @@ static SensorSource *sensor_sources;
enum {
COLUMN_NAME,
COLUMN_VALUE,
+ COLUMN_MIN,
+ COLUMN_MAX,
NUM_COLUMNS
};
@@ -36,8 +38,10 @@ static void init_sensors() {
data = (SensorInit*)sensor->data;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
- COLUMN_NAME, data->label,
+ COLUMN_NAME, data->label,
COLUMN_VALUE, " --- ",
+ COLUMN_MIN, " --- ",
+ COLUMN_MAX, " --- ",
-1);
sensor = sensor->next;
i++;
@@ -49,15 +53,24 @@ static void init_sensors() {
static GtkTreeModel* create_model (void) {
GtkListStore *store;
- store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
+ store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
return GTK_TREE_MODEL (store);
}
+static void set_list_column_value(float num, const gchar *printf_format, GtkTreeIter *iter, gint column){
+ gchar *value;
+ if (num != ERROR_VALUE)
+ value = g_strdup_printf(printf_format, num);
+ else
+ value = g_strdup(" ? ? ?");
+ gtk_list_store_set(GTK_LIST_STORE (model), iter, column, value, -1);
+ g_free(value);
+}
+
static gboolean update_data (gpointer data) {
GtkTreeIter iter;
guint number;
GSList *node;
- gchar *value;
SensorSource *source;
const SensorInit *sensorData;
@@ -77,12 +90,10 @@ static gboolean update_data (gpointer data) {
while(node) {
sensorData = (SensorInit*)node->data;
- if (*(sensorData->value) != ERROR_VALUE)
- value = g_strdup_printf(sensorData->printf_format, *(sensorData->value));
- else
- value = g_strdup(" ? ? ?");
-
- gtk_list_store_set(GTK_LIST_STORE (model), &iter, COLUMN_VALUE, value, -1);
+ set_list_column_value(*(sensorData->value), sensorData->printf_format, &iter, COLUMN_VALUE);
+ set_list_column_value(*(sensorData->min), sensorData->printf_format, &iter, COLUMN_MIN);
+ set_list_column_value(*(sensorData->max), sensorData->printf_format, &iter, COLUMN_MAX);
+
node = node->next;
if (!gtk_tree_model_iter_next(model, &iter))
break;
@@ -93,26 +104,41 @@ static gboolean update_data (gpointer data) {
}
static void add_columns (GtkTreeView *treeview) {
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
- GtkTreeModel *model = gtk_tree_view_get_model (treeview);
-
- // NAME
- renderer = gtk_cell_renderer_text_new ();
-
- column = gtk_tree_view_column_new_with_attributes ("Sensor", renderer,
+ GtkCellRenderer *renderer;
+ GtkTreeViewColumn *column;
+ GtkTreeModel *model = gtk_tree_view_get_model (treeview);
+
+ // NAME
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("Sensor", renderer,
"text", COLUMN_NAME,
NULL);
- g_object_set(renderer, "family", "monotype", NULL);
- gtk_tree_view_append_column (treeview, column);
+ g_object_set(renderer, "family", "monotype", NULL);
+ gtk_tree_view_append_column (treeview, column);
- //VALUE
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("Value", renderer,
+ //VALUE
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("Value", renderer,
"text", COLUMN_VALUE,
NULL);
- g_object_set(renderer, "family", "monotype", NULL);
- gtk_tree_view_append_column (treeview, column);
+ g_object_set(renderer, "family", "monotype", NULL);
+ gtk_tree_view_append_column (treeview, column);
+
+ //MIN
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("Min", renderer,
+ "text", COLUMN_MIN,
+ NULL);
+ g_object_set(renderer, "family", "monotype", NULL);
+ gtk_tree_view_append_column (treeview, column);
+
+ //MAX
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("Max", renderer,
+ "text", COLUMN_MAX,
+ NULL);
+ g_object_set(renderer, "family", "monotype", NULL);
+ gtk_tree_view_append_column (treeview, column);
}
static void about_btn_clicked(GtkButton *button, gpointer user_data) {
@@ -144,7 +170,7 @@ int start_gui (SensorSource *ss) {
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
- gtk_window_set_default_size(GTK_WINDOW(window), 400, 350);
+ gtk_window_set_default_size(GTK_WINDOW(window), 480, 350);
header = gtk_header_bar_new();
gtk_header_bar_set_show_close_button(GTK_HEADER_BAR (header), TRUE);
diff --git a/src/include/zenmonitor.h b/src/include/zenmonitor.h
index a1caa8d..9f320eb 100644
--- a/src/include/zenmonitor.h
+++ b/src/include/zenmonitor.h
@@ -4,6 +4,8 @@ typedef struct
{
gchar *label;
float *value;
+ float *min;
+ float *max;
const gchar *printf_format;
}
SensorInit;
diff --git a/src/ss/msr.c b/src/ss/msr.c
index 0085363..e3c9198 100644
--- a/src/ss/msr.c
+++ b/src/ss/msr.c
@@ -25,7 +25,11 @@ gulong *core_eng_b = NULL;
gulong *core_eng_a = NULL;
gfloat package_power;
+gfloat package_power_min;
+gfloat package_power_max;
gfloat *core_power;
+gfloat *core_power_min;
+gfloat *core_power_max;
static guint get_core_count() {
guint eax = 0, ebx = 0, ecx = 0, edx = 0;
@@ -87,6 +91,7 @@ gulong get_core_energy(gint core) {
gboolean msr_init() {
int i;
+ size_t sz;
if (!check_zen())
return FALSE;
@@ -107,6 +112,14 @@ gboolean msr_init() {
core_eng_b = malloc(cores * sizeof (gulong));
core_eng_a = malloc(cores * sizeof (gulong));
core_power = malloc(cores * sizeof (gfloat));
+ core_power_min = malloc(cores * sizeof (gfloat));
+ core_power_max = malloc(cores * sizeof (gfloat));
+
+ msr_update();
+ memcpy(core_power_min, core_power, cores * sizeof (gfloat));
+ memcpy(core_power_max, core_power, cores * sizeof (gfloat));
+ package_power_min = package_power;
+ package_power_max = package_power;
return TRUE;
}
@@ -128,8 +141,17 @@ void msr_update() {
}
package_power = (package_eng_a - package_eng_b) * energy_unit / MESUREMENT_TIME;
+ if (package_power < package_power_min)
+ package_power_min = package_power;
+ if (package_power > package_power_max)
+ package_power_max = package_power;
+
for (i = 0; i < cores; i++) {
core_power[i] = (core_eng_a[i] - core_eng_b[i]) * energy_unit / MESUREMENT_TIME;
+ if (core_power[i] < core_power_min[i])
+ core_power_min[i] = core_power[i];
+ if (core_power[i] > core_power_max[i])
+ core_power_max[i] = core_power[i];
}
}
@@ -141,6 +163,8 @@ GSList* msr_get_sensors() {
data = sensor_init_new();
data->label = g_strdup("Package Power");
data->value = &package_power;
+ data->min = &package_power_min;
+ data->max = &package_power_max;
data->printf_format = MSR_PWR_PRINTF_FORMAT;
list = g_slist_append(list, data);
@@ -148,6 +172,8 @@ GSList* msr_get_sensors() {
data = sensor_init_new();
data->label = g_strdup_printf("Core %d Power", i);
data->value = &(core_power[i]);
+ data->min = &(core_power_min[i]);
+ data->max = &(core_power_max[i]);
data->printf_format = MSR_PWR_PRINTF_FORMAT;
list = g_slist_append(list, data);
}
diff --git a/src/ss/zenpower.c b/src/ss/zenpower.c
index 7d24bba..e449a3c 100644
--- a/src/ss/zenpower.c
+++ b/src/ss/zenpower.c
@@ -11,17 +11,19 @@ typedef struct
const gchar *printf_format;
const double adjust_ratio;
float current_value;
+ float min;
+ float max;
} HwmonSensor;
HwmonSensor hwmon_sensors[] = {
- {"CPU Temperature (tCtrl)", "temp1_input", " %6.2f°C", 1000.0, 0.0},
- {"CPU Temperature (tDie)", "temp2_input", " %6.2f°C", 1000.0, 0.0},
- {"CPU Core Voltage (SVI2)", "in1_input", " %8.3f V", 1000.0, 0.0},
- {"SOC Voltage (SVI2)", "in2_input", " %8.3f V", 1000.0, 0.0},
- {"CPU Core Current (SVI2)", "curr1_input", " %8.3f A", 1000.0, 0.0},
- {"SOC Current (SVI2)", "curr2_input", " %8.3f A", 1000.0, 0.0},
- {"CPU Core Power (SVI2)", "power1_input", " %8.3f W", 1000000.0, 0.0},
- {"SOC Power (SVI2)", "power2_input", " %8.3f W", 1000000.0, 0.0},
+ {"CPU Temperature (tCtrl)", "temp1_input", " %6.2f°C", 1000.0, 0.0, 999.0, 0.0},
+ {"CPU Temperature (tDie)", "temp2_input", " %6.2f°C", 1000.0, 0.0, 999.0, 0.0},
+ {"CPU Core Voltage (SVI2)", "in1_input", " %8.3f V", 1000.0, 0.0, 999.0, 0.0},
+ {"SOC Voltage (SVI2)", "in2_input", " %8.3f V", 1000.0, 0.0, 999.0, 0.0},
+ {"CPU Core Current (SVI2)", "curr1_input", " %8.3f A", 1000.0, 0.0, 999.0, 0.0},
+ {"SOC Current (SVI2)", "curr2_input", " %8.3f A", 1000.0, 0.0, 999.0, 0.0},
+ {"CPU Core Power (SVI2)", "power1_input", " %8.3f W", 1000000.0, 0.0, 999.0, 0.0},
+ {"SOC Power (SVI2)", "power2_input", " %8.3f W", 1000000.0, 0.0, 999.0, 0.0},
{0, NULL}
};
@@ -66,6 +68,13 @@ void zenpower_update() {
for (sensor = hwmon_sensors; sensor->label; sensor++) {
if (read_raw_hwmon_value(zenpowerDir, sensor->file, &tmp)){
sensor->current_value = atof(tmp) / sensor->adjust_ratio;
+
+ if (sensor->current_value < sensor->min)
+ sensor->min = sensor->current_value;
+
+ if (sensor->current_value > sensor->max)
+ sensor->max = sensor->current_value;
+
g_free(tmp);
}
else{
@@ -83,6 +92,8 @@ GSList* zenpower_get_sensors() {
data = sensor_init_new();
data->label = g_strdup(sensor->label);
data->value = &sensor->current_value;
+ data->min = &sensor->min;
+ data->max = &sensor->max;
data->printf_format = sensor->printf_format;
list = g_slist_append(list, data);
}