Current powertop release doesnt give user a help
option and version information .Also there is no
option to specify a time period to collect wakeup
stats while creating a report.

This patch enables the use of -t -h and -v parameters.
Following is a powertop -h output that has been
implemented with this patch.

  -c, --calibrate       make estimation more accurate by running a calibration
  -t, --time=DOUBLE     default time to gather data in seconds
  -d, --debug           debug learning
  -h, --help            Show this help message
  -r, --html            create a powertop.html report
  -v, --version         Show version information and exit
---
 main.cpp |   64 ++++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/main.cpp b/main.cpp
index c5b8a60..de0558e 100644
--- a/main.cpp
+++ b/main.cpp
@@ -156,9 +156,28 @@ void out_of_memory()
        abort();
 }
 
+void usage()
+{
+       printf(_("Usage: powertop [OPTION...]\n"));
+       printf(_("  -c, --calibrate       Make estimation more accurate by 
running a calibration\n"));
+       printf(_("  -t, --time=DOUBLE     Specify the time to gather data in 
seconds to be used along with -r\n"));
+       printf(_("  -d, --debug           Debug learning\n"));
+       printf(_("  -h, --help            Show this help message\n"));
+       printf(_("  -r, --html            Create a powertop.html report using 
20 seconds of data\n"));
+       printf(_("  -v, --version         Show version information and 
exit\n"));
+       exit(0);
+}
+
+void version()
+{
+       printf(_("powertop version %s\n"), POWERTOP_VERSION);
+       exit(0);
+}
+
 int main(int argc, char **argv)
 {
        int uid;
+       double ticktime = 20.0;
 
        set_new_handler(out_of_memory);
 
@@ -179,11 +198,14 @@ int main(int argc, char **argv)
 
        srand(time(NULL));
 
-       mkdir("/var/cache/powertop", 0600);
+       mkdir("/data/powertop", 0600);
 
-       load_results("/var/cache/powertop/saved_results.powertop");
-       load_parameters("/var/cache/powertop/saved_parameters.powertop");
+       load_results("/data/powertop/saved_results.powertop");
+       load_parameters("/data/powertop/saved_parameters.powertop");
 
+       putenv("TERM=vt100");
+       system("echo $TERM");
+       
        enumerate_cpus();
        create_all_devices();
        detect_power_meters();
@@ -196,12 +218,22 @@ int main(int argc, char **argv)
        register_parameter("disk-operations", 0.0);
 
        if (argc > 1) {
-               if (strcmp(argv[1], "--calibrate") == 0)
+               if (strcmp(argv[1], "--calibrate") == 0 || strcmp(argv[1], 
"-c") == 0)
                        calibrate();
        }
 
        if (argc > 1) {
-               if (strcmp(argv[1], "--debug") == 0)
+               if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 
0)
+                       usage();
+       }
+
+       if (argc > 1) {
+               if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") 
== 0)
+                       version();
+       }
+
+       if (argc > 1) {
+               if (strcmp(argv[1], "--debug") == 0 || strcmp(argv[1], "-d") == 
0)
                        debug_learning = 1;
        }
 
@@ -211,23 +243,27 @@ int main(int argc, char **argv)
        }
 
        if (argc > 1) {
-               if (strcmp(argv[1], "--html") == 0) {
-                       fprintf(stderr, _("Measuring for 20 seconds\n"));
+               if (strcmp(argv[1], "--html") == 0 || strcmp(argv[1], "-r") == 
0){
+                       if (argc > 2) {
+                               ticktime = strtod(argv[2], NULL);
+                       }
+
+                       fprintf(stderr, _("Measuring for %i seconds\n"), 
(int)ticktime);
                        /* one to warm up everything */
                        utf_ok = 0;
                        one_measurement(1);
                        init_html_output("powertop.html");
                        initialize_tuning();
                        /* and then the real measurement */
-                       one_measurement(20);
+                       one_measurement(ticktime);
                        html_show_tunables();
 
                        finish_html_output();
 
                        /* and wrap up */
                        learn_parameters(50, 0);
-                       
save_all_results("/var/cache/powertop/saved_results.powertop");
-                       
save_parameters("/var/cache/powertop/saved_parameters.powertop");
+                       
save_all_results("/data/powertop/saved_results.powertop");
+                       
save_parameters("/data/powertop/saved_parameters.powertop");
                        end_pci_access();
                        exit(0);
                }
@@ -239,7 +275,7 @@ int main(int argc, char **argv)
 
 
         learn_parameters(250, 0);
-       save_parameters("/var/cache/powertop/saved_parameters.powertop");
+       save_parameters("/data/powertop/saved_parameters.powertop");
 
 
        if (debug_learning) {
@@ -272,10 +308,10 @@ int main(int argc, char **argv)
        end_process_data();
        end_cpu_data();
 
-       save_all_results("/var/cache/powertop/saved_results.powertop");
-       save_parameters("/var/cache/powertop/saved_parameters.powertop");
+       save_all_results("/data/powertop/saved_results.powertop");
+       save_parameters("/data/powertop/saved_parameters.powertop");
        learn_parameters(500, 0);
-       save_parameters("/var/cache/powertop/saved_parameters.powertop");
+       save_parameters("/data/powertop/saved_parameters.powertop");
        end_pci_access();
        reset_display();
 
-- 
1.7.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

_______________________________________________
Power mailing list
[email protected]
http://www.bughost.org/mailman/listinfo/power

Reply via email to