Skip to content

Commit

Permalink
[dbus] Add method for querying uptime and suspend time. Fixes JB#31310
Browse files Browse the repository at this point in the history
Usually test automation scripts can get suspend statistics from proc fs.
But as some devices do not have the necessary kernel interfaces, we need
to have a common way to get suspend vs uptime statistics.

Add a dbus-method for querying uptime and time spent in suspend. Provide
mcetool option "--get-suspend-stats" for getting it in a form that easy
to use from scripts.
  • Loading branch information
spiiroin committed Sep 22, 2015
1 parent a3e3626 commit efae71e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .depend
Expand Up @@ -139,6 +139,7 @@ mce-dbus.o:\
builtin-gconf.h\
datapipe.h\
mce-dbus.h\
mce-lib.h\
mce-log.h\
mce.h\

Expand All @@ -147,6 +148,7 @@ mce-dbus.pic.o:\
builtin-gconf.h\
datapipe.h\
mce-dbus.h\
mce-lib.h\
mce-log.h\
mce.h\

Expand Down
47 changes: 47 additions & 0 deletions mce-dbus.c
Expand Up @@ -25,6 +25,7 @@

#include "mce.h"
#include "mce-log.h"
#include "mce-lib.h"

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -688,6 +689,43 @@ static gboolean version_get_dbus_cb(DBusMessage *const msg)
return status;
}

/** D-Bus callback for the get suspend time statistics method call
*
* @param req The D-Bus message to reply to
*
* @return TRUE
*/
static gboolean suspend_stats_get_dbus_cb(DBusMessage *const req)
{
DBusMessage *rsp = 0;

mce_log(LL_DEVEL, "suspend info request from %s",
mce_dbus_get_message_sender_ident(req));

/* get stats */
dbus_int64_t uptime_ms = mce_lib_get_boot_tick();
dbus_int64_t suspend_ms = uptime_ms - mce_lib_get_mono_tick();

/* create and send reply message */
rsp = dbus_new_method_reply(req);

if( !dbus_message_append_args(rsp,
DBUS_TYPE_INT64, &uptime_ms,
DBUS_TYPE_INT64, &suspend_ms,
DBUS_TYPE_INVALID) ) {
mce_log(LL_ERR, "Failed to append arguments");
goto EXIT;
}

dbus_send_message(rsp), rsp = 0;

EXIT:
if( rsp )
dbus_message_unref(rsp);

return TRUE;
}

/** Helper for appending gconf string list to dbus message
*
* @param conf GConfValue of string list type
Expand Down Expand Up @@ -3613,6 +3651,15 @@ static mce_dbus_handler_t mce_dbus_handlers[] =
" <arg direction=\"in\" name=\"key_part\" type=\"s\"/>\n"
" <arg direction=\"out\" name=\"count\" type=\"i\"/>\n"
},
{
.interface = MCE_REQUEST_IF,
.name = "get_suspend_stats",
.type = DBUS_MESSAGE_TYPE_METHOD_CALL,
.callback = suspend_stats_get_dbus_cb,
.args =
" <arg direction=\"out\" name=\"uptime_ms\" type=\"x\"/>\n"
" <arg direction=\"out\" name=\"suspend_ms\" type=\"x\"/>\n"
},
{
.interface = DBUS_INTERFACE_INTROSPECTABLE,
.name = "Introspect",
Expand Down
41 changes: 41 additions & 0 deletions tools/mcetool.c
Expand Up @@ -4521,6 +4521,41 @@ static void xmce_get_suspend_policy(void)
printf("%-"PAD1"s %s \n", "Autosuspend policy:", txt ?: "unknown");
}

/** Get current uptime and suspend time
*/
static bool xmce_get_suspend_stats(const char *args)
{
(void)args;

DBusMessage *rsp = NULL;
DBusError err = DBUS_ERROR_INIT;

if( !xmce_ipc_message_reply("get_suspend_stats", &rsp, DBUS_TYPE_INVALID) )
goto EXIT;

dbus_int64_t uptime_ms = 0;
dbus_int64_t suspend_ms = 0;

if( !dbus_message_get_args(rsp, &err,
DBUS_TYPE_INT64, &uptime_ms,
DBUS_TYPE_INT64, &suspend_ms,
DBUS_TYPE_INVALID) )
goto EXIT;

printf("uptime: %.3f \n", uptime_ms * 1e-3);
printf("suspend_time: %.3f \n", suspend_ms * 1e-3);
EXIT:

if( dbus_error_is_set(&err) ) {
errorf("%s: %s: %s\n", "get_suspend_stats", err.name, err.message);
dbus_error_free(&err);
}

if( rsp ) dbus_message_unref(rsp);

return true;
}

/* ------------------------------------------------------------------------- *
* use mouse clicks to emulate touchscreen doubletap policy
* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -5450,6 +5485,12 @@ static const mce_opt_t options[] =
"set the autosuspend mode; valid modes are:\n"
"'enabled', 'disabled' and 'early'\n"
},
{
.name = "get-suspend-stats",
.without_arg = xmce_get_suspend_stats,
.usage =
"get device uptime and time spent in suspend\n"
},
{
.name = "set-cpu-scaling-governor",
.flag = 'S',
Expand Down

0 comments on commit efae71e

Please sign in to comment.