Merge lp:~sforshee/powerd/log-stats-on-low-battery into lp:powerd

Proposed by Seth Forshee
Status: Merged
Approved by: Michael Frey
Approved revision: 91
Merged at revision: 90
Proposed branch: lp:~sforshee/powerd/log-stats-on-low-battery
Merge into: lp:powerd
Prerequisite: lp:~sforshee/powerd/thermal-shutdown
Diff against target: 208 lines (+136/-1)
3 files modified
src/power-source.c (+25/-1)
src/powerd-internal.h (+1/-0)
src/stats.c (+110/-0)
To merge this branch: bzr merge lp:~sforshee/powerd/log-stats-on-low-battery
Reviewer Review Type Date Requested Status
Michael Frey (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+183669@code.launchpad.net

Commit message

Dump statistics to syslog on low battery

Description of the change

Dump statistics to syslog on low battery

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Frey (mfrey) wrote :

good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/power-source.c'
2--- src/power-source.c 2013-09-03 14:13:37 +0000
3+++ src/power-source.c 2013-09-03 14:13:37 +0000
4@@ -25,7 +25,9 @@
5 #include "log.h"
6
7 static UpClient *up_client;
8-double shutdown_temp = 68.0f;
9+static double shutdown_temp = 68.0f;
10+static double battery_log_level = 4.0f;
11+static gboolean stats_logged;
12
13 static void up_device_changed_cb(UpClient *client, UpDevice *device,
14 gpointer unused)
15@@ -33,6 +35,7 @@
16 gboolean on_battery;
17 GPtrArray *devices;
18 int i;
19+ gboolean log_stats = TRUE;
20 gboolean low_batt_shutdown = TRUE;
21 gboolean thermal_shutdown = FALSE;
22
23@@ -56,6 +59,17 @@
24 "percentage", &percentage,
25 "temperature", &temp,
26 NULL);
27+
28+ /*
29+ * Log battery stats a little before emergency
30+ * shutdown is triggered to avoid any delays
31+ * when we actually need to shut down.
32+ */
33+ if (percentage > battery_log_level) {
34+ log_stats = FALSE;
35+ stats_logged = FALSE;
36+ }
37+
38 /*
39 * Android shuts down when percentage reaches 0. We
40 * use 1% to leave a little more headroom.
41@@ -69,6 +83,10 @@
42 }
43 }
44 }
45+ if (log_stats && !stats_logged) {
46+ powerd_log_stats();
47+ stats_logged = TRUE;
48+ }
49 if (low_batt_shutdown || thermal_shutdown) {
50 powerd_warn("Initiating emergency shutdown");
51 powerd_shutdown();
52@@ -90,6 +108,12 @@
53 g_value_unset(&v);
54 }
55
56+ if (!device_config_get("criticalBatteryWarningLevel", &v) &&
57+ G_VALUE_HOLDS_UINT(&v)) {
58+ battery_log_level = (double)g_value_get_uint(&v);
59+ g_value_unset(&v);
60+ }
61+
62 up_client = up_client_new();
63 if (!up_client) {
64 powerd_warn("Could not allocate upower client");
65
66=== modified file 'src/powerd-internal.h'
67--- src/powerd-internal.h 2013-08-26 19:34:31 +0000
68+++ src/powerd-internal.h 2013-09-03 14:13:37 +0000
69@@ -179,6 +179,7 @@
70 const char *name,
71 const struct powerd_display_request *req);
72 void powerd_account_clear_display_req(const char *dbus_name, const char *name);
73+void powerd_log_stats(void);
74 int powerd_stats_init(void);
75 void powerd_stats_deinit(void);
76 gboolean handle_get_sys_request_stats(PowerdSource *obj,
77
78=== modified file 'src/stats.c'
79--- src/stats.c 2013-08-12 14:22:18 +0000
80+++ src/stats.c 2013-09-03 14:13:37 +0000
81@@ -16,10 +16,13 @@
82 * along with this program. If not, see <http://www.gnu.org/licenses/>.
83 */
84
85+#include <stdio.h>
86 #include <stdlib.h>
87+#include <stdarg.h>
88 #include <errno.h>
89 #include <string.h>
90 #include <time.h>
91+#include <sys/sysinfo.h>
92
93 #include <glib.h>
94 #include <gio/gio.h>
95@@ -323,6 +326,113 @@
96 stats->last_req = req;
97 }
98
99+static void log_sys_req_stats(struct client_stats *client)
100+{
101+ const char *dbus_name = client->dbus_name;
102+ GSList *cur;
103+ guint64 us;
104+
105+ us = get_usecs();
106+ for (cur = client->sys_stats; cur; cur = g_slist_next(cur)) {
107+ struct sys_request_stats *stats = cur->data;
108+ guint64 active_time, max_active_time;
109+
110+ /*
111+ * Aggregate currently held requests into active_time, and
112+ * consider whether this is greater than the current
113+ * max_active_time.
114+ */
115+ active_time = stats->active_time;
116+ max_active_time = stats->max_active_time;
117+ if (stats->active_since != 0) {
118+ guint64 duration = us - stats->active_since;
119+ active_time += duration;
120+ if (duration > max_active_time)
121+ max_active_time = duration;
122+ }
123+ powerd_info(" Name: %s", stats->name);
124+ powerd_info(" Owner: %s", dbus_name);
125+ powerd_info(" Active Count: %u", stats->active_count);
126+ powerd_info(" Active Time: %f", (double)active_time / 1000000.0f);
127+ powerd_info(" Max Active Time: %f",
128+ (double)max_active_time / 1000000.0f);
129+ powerd_info(" Active Since: %f",
130+ (double)stats->active_since / 1000000.0f);
131+ }
132+}
133+
134+static void log_disp_req_stats(struct client_stats *client)
135+{
136+ const char *dbus_name = client->dbus_name;
137+ GSList *cur;
138+ guint64 us;
139+
140+ us = get_usecs();
141+ for (cur = client->disp_stats; cur; cur = g_slist_next(cur)) {
142+ struct disp_request_stats *stats = cur->data;
143+ guint64 active_time, max_active_time;
144+ guint64 disp_on_time;
145+ int i;
146+
147+ active_time = stats->active_time;
148+ max_active_time = stats->max_active_time;
149+ if (stats->active_since != 0) {
150+ guint64 duration = us - stats->active_since;
151+ active_time += duration;
152+ if (duration > max_active_time)
153+ max_active_time = duration;
154+ }
155+
156+ disp_on_time = stats->disp_on_time;
157+ if (stats->disp_on_since != 0)
158+ disp_on_time += us - stats->disp_on_since;
159+
160+ powerd_info(" Name: %s", stats->name);
161+ powerd_info(" Owner: %s", dbus_name);
162+ powerd_info(" Active Count: %u", stats->active_count);
163+ powerd_info(" Active Time: %f", (double)active_time / 1000000.0f);
164+ powerd_info(" Max Active Time: %f",
165+ (double)max_active_time / 1000000.0f);
166+ powerd_info(" Active Since: %f",
167+ (double)stats->active_since / 1000000.0f);
168+ powerd_info(" Display On Time: %f",
169+ (double)disp_on_time / 1000000.0f);
170+ powerd_info(" Display On Since: %f",
171+ (double)stats->disp_on_since / 1000000.0f);
172+ for (i = 0; i < POWERD_NUM_DISPLAY_FLAGS; i++) {
173+ guint64 on_time = stats->flag_on_time[i];
174+ if (stats->flag_on_since[i] != 0)
175+ on_time += us - stats->flag_on_since[i];
176+ powerd_info(" Flag %d On Time: %f", i,
177+ (double)on_time / 1000000.0f);
178+ powerd_info(" Flag %d On Since: %f", i,
179+ (double)stats->flag_on_since[i] / 1000000.0f);
180+ }
181+ }
182+}
183+
184+void powerd_log_stats(void)
185+{
186+ struct sysinfo si;
187+ GHashTableIter iter;
188+ gpointer key, value;
189+
190+ if (!sysinfo(&si))
191+ powerd_info("Uptime: %ld", si.uptime);
192+
193+ if (stats_hash) {
194+ powerd_info("System Request Statistics:");
195+ g_hash_table_iter_init(&iter, stats_hash);
196+ while (g_hash_table_iter_next(&iter, &key, &value))
197+ log_sys_req_stats(value);
198+
199+ powerd_info("Display Request Statistics:");
200+ g_hash_table_iter_init(&iter, stats_hash);
201+ while (g_hash_table_iter_next(&iter, &key, &value))
202+ log_disp_req_stats(value);
203+ }
204+}
205+
206 static void sys_stats_list_destroy(gpointer data)
207 {
208 struct sys_request_stats *stats = data;

Subscribers

People subscribed via source and target branches