aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mathew <johnx.mathew@intel.com>2011-06-30 09:58:25 +0300
committerAmit Daniel Kachhap <amit.kachhap@linaro.org>2011-07-13 16:30:21 +0530
commit54dbc493115680f940ad0102dfd97657cb8848a1 (patch)
treebde60e85ffa3a2f3b61ee15cd32c4bee8c9d255e
parent0f7e6dd0ab7b1b02ef7e55749d6a34d6801c3973 (diff)
downloadpowertop-54dbc493115680f940ad0102dfd97657cb8848a1.tar.gz
main: mount debugfs if not mounted already in Android
Powertop2 uses debugfs. Currently it uses /bin/mount to mount the debugfs. In Android mount command is present in system/bin. This patch mounts the debugfs in android natively. This patch also enables powertop to use the /data directory instead of /var to store powertop paramaters and results in case of Android OS
-rw-r--r--main.cpp12
-rw-r--r--parameters/persistent.cpp33
2 files changed, 35 insertions, 10 deletions
diff --git a/main.cpp b/main.cpp
index 7861c37..74304c1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -262,11 +262,19 @@ int main(int argc, char **argv)
}
system("/sbin/modprobe cpufreq_stats > /dev/null 2>&1");
system("/sbin/modprobe msr > /dev/null 2>&1");
- system("/bin/mount -t debugfs debugfs /sys/kernel/debug > /dev/null 2>&1");
+
+ if (access("/bin/mount", X_OK) == 0) {
+ system("/bin/mount -t debugfs debugfs /sys/kernel/debug > /dev/null 2>&1");
+ } else {
+ system("mount -t debugfs debugfs /sys/kernel/debug > /dev/null 2>&1");
+ }
srand(time(NULL));
- mkdir("/var/cache/powertop", 0600);
+ if (access("/var/cache/", W_OK) == 0)
+ mkdir("/var/cache/powertop", 0600);
+ else
+ mkdir("/data/local/powertop", 0600);
load_results("/var/cache/powertop/saved_results.powertop");
load_parameters("/var/cache/powertop/saved_parameters.powertop");
diff --git a/parameters/persistent.cpp b/parameters/persistent.cpp
index 069095d..9297755 100644
--- a/parameters/persistent.cpp
+++ b/parameters/persistent.cpp
@@ -26,6 +26,7 @@
#include <fstream>
#include <iomanip>
#include <stdlib.h>
+#include <unistd.h>
#include "parameters.h"
#include "../measurement/measurement.h"
@@ -37,10 +38,14 @@ void save_all_results(const char *filename)
ofstream file;
unsigned int i;
struct result_bundle *bundle;
+ char* tempfilename = const_cast<char*>(filename);
- file.open(filename, ios::out);
+ if (access("/var/", W_OK ) != 0)
+ sprintf(tempfilename, "/data/local/powertop/saved_results.powertop");
+
+ file.open(tempfilename, ios::out);
if (!file) {
- cout << _("Cannot save to file ") << filename << "\n";
+ cout << _("Cannot save to file ") << tempfilename << "\n";
return;
}
for (i = 0; i < past_results.size(); i++) {
@@ -66,10 +71,14 @@ void load_results(const char *filename)
struct result_bundle *bundle;
int first = 1;
unsigned int count = 0;
+ char* tempfilename = const_cast<char*>(filename);
+
+ if (access("/var/", W_OK ) != 0)
+ sprintf(tempfilename, "/data/local/powertop/saved_results.powertop");
- file.open(filename, ios::in);
+ file.open(tempfilename, ios::in);
if (!file) {
- cout << _("Cannot load from file ") << filename << "\n";
+ cout << _("Cannot load from file ") << tempfilename << "\n";
return;
}
@@ -119,15 +128,19 @@ void load_results(const char *filename)
void save_parameters(const char *filename)
{
ofstream file;
+ char* tempfilename = const_cast<char*>(filename);
// printf("result size is %i, #parameters is %i \n", (int)past_results.size(), (int)all_parameters.parameters.size());
if (!global_power_valid())
return;
- file.open(filename, ios::out);
+ if (access("/var/", R_OK ) != 0)
+ sprintf(tempfilename, "/data/local/powertop/saved_parameters.powertop");
+
+ file.open(tempfilename, ios::out);
if (!file) {
- cout << _("Cannot save to file ") << filename << "\n";
+ cout << _("Cannot save to file ") << tempfilename << "\n";
return;
}
@@ -146,10 +159,14 @@ void load_parameters(const char *filename)
ifstream file;
char line[4096];
char *c1;
+ char* tempfilename = const_cast<char*>(filename);
+
+ if (access("/var/", R_OK ) != 0)
+ sprintf(tempfilename, "/data/local/powertop/saved_parameters.powertop");
- file.open(filename, ios::in);
+ file.open(tempfilename, ios::in);
if (!file) {
- cout << _("Cannot load from file ") << filename << "\n";
+ cout << _("Cannot load from file ") << tempfilename << "\n";
return;
}