From: Márton Németh <nm...@freemail.hu>

Gracefully free the vector of tunables and untunables on exit
from interactive mode and also when the report is generated.

This will also remove multiple entries of the same content
from the Chapter "Software Settings in need of Tuning" of the report
when iteration >= 2, for example when powertop is called as
# ./powertop --iteration=3 --html

The patch was verified with Valgrind:

valgrind --leak-check=full --log-file=powertop.log ./powertop

and

valgrind --leak-check=full --log-file=powertop.log ./powertop --iteration=3 
--html

The patch removes the bigest chunk of leaked memory at exit from the Valgrind 
log:

==2925== 419,500 bytes in 25 blocks are definitely lost in loss record 125 of 
130
==2925==    at 0x4025D54: operator new(unsigned int) (in 
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2925==    by 0x808D68D: add_runtime_tunables(char const*) (runtime.cpp:156)
==2925==    by 0x808889A: initialize_tuning() (tuning.cpp:71)
==2925==    by 0x805039E: main (main.cpp:391)

Note the size of one "tunable" which is 16780 bytes.

Signed-off-by: Márton Németh <nm...@freemail.hu>
---
diff --git a/main.cpp b/main.cpp
index 0e57ee1..67db2eb 100644
--- a/main.cpp
+++ b/main.cpp
@@ -240,6 +240,7 @@ void report(int time, int iterations, char *file)
                one_measurement(time);
                report_show_tunables();
                finish_report_output();
+               clear_tuning();
        }
        /* and wrap up */
        learn_parameters(50, 0);
@@ -415,6 +416,7 @@ int main(int argc, char **argv)
        learn_parameters(500, 0);
        save_parameters("saved_parameters.powertop");
        end_pci_access();
+       clear_tuning();
        reset_display();

        clear_all_devices();
diff --git a/tuning/tuning.cpp b/tuning/tuning.cpp
index a0c3ffa..6a359ae 100644
--- a/tuning/tuning.cpp
+++ b/tuning/tuning.cpp
@@ -312,3 +312,15 @@ void report_show_tunables(void)
                        fprintf(reportout.csv_report,"\n");
        }
 }
+
+void clear_tuning()
+{
+       while (!all_tunables.empty()) {
+               delete all_tunables.back();
+               all_tunables.pop_back();
+       }
+       while (!all_untunables.empty()) {
+               delete all_untunables.back();
+               all_untunables.pop_back();
+       }
+}
diff --git a/tuning/tuning.h b/tuning/tuning.h
index e5c962b..7c4921f 100644
--- a/tuning/tuning.h
+++ b/tuning/tuning.h
@@ -28,6 +28,7 @@
 extern void initialize_tuning(void);
 extern void tuning_update_display(void);
 extern void report_show_tunables(void);
+extern void clear_tuning(void);





_______________________________________________
Power mailing list
Power@bughost.org
https://bughost.org/mailman/listinfo/power

Reply via email to