diff --git a/Makefile b/Makefile index 993bda07..3064a1f1 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,18 @@ trace-malloc: ## Trace the malloc() calls memory-leak: ## Profile memory leaks ./venv/bin/python -m glances -C ./conf/glances.conf --memory-leak +memory-profiling: ## Profile memory usage + @echo "It's a very long test (~4 hours)..." + rm -f mprofile_*.dat + @echo "1/2 - Start memory profiling with the history option enable" + ./venv/bin/mprof run -T 1 -C run.py -C ./conf/glances.conf --stop-after 2400 --quiet + ./venv/bin/mprof plot --output ./docs/_static/glances-memory-profiling-with-history.png + rm -f mprofile_*.dat + @echo "2/2 - Start memory profiling with the history option disable" + ./venv/bin/mprof run -T 1 -C run.py -C ./conf/glances.conf --disable-history --stop-after 2400 --quiet + ./venv/bin/mprof plot --output ./docs/_static/glances-memory-profiling-without-history.png + rm -f mprofile_*.dat + # =================================================================== # Docs # =================================================================== diff --git a/conf/glances.conf b/conf/glances.conf index 85326e33..d40a9715 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -10,8 +10,8 @@ refresh=2 # Does Glances should check if a newer version is available on PyPI ? check_update=true # History size (maximum number of values) -# Default is 3600 seconds (1 hour) -history_size=3600 +# Default is 1200 values (~1h with the default refresh rate) +history_size=1200 ############################################################################## # User interface diff --git a/dev-requirements.txt b/dev-requirements.txt index 30fbb37a..9034dd47 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -6,3 +6,5 @@ flake8 autopep8 autoflake codespell +memory-profiler +matplotlib \ No newline at end of file diff --git a/docs/_static/glances-memory-profiling-with-history.png b/docs/_static/glances-memory-profiling-with-history.png new file mode 100644 index 00000000..0046790a Binary files /dev/null and b/docs/_static/glances-memory-profiling-with-history.png differ diff --git a/docs/_static/glances-memory-profiling-without-history.png b/docs/_static/glances-memory-profiling-without-history.png new file mode 100644 index 00000000..e27f4ea2 Binary files /dev/null and b/docs/_static/glances-memory-profiling-without-history.png differ diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 6c056570..8259ba5f 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -178,13 +178,13 @@ class GlancesPlugin(object): def update_stats_history(self): """Update stats history.""" - # If the plugin data is a dict, the dict's key should be used - if self.get_key() is None: - item_name = '' - else: - item_name = self.get_key() # Build the history if self.get_export() and self.history_enable(): + # If the plugin data is a dict, the dict's key should be used + if self.get_key() is None: + item_name = '' + else: + item_name = self.get_key() for i in self.get_items_history_list(): if isinstance(self.get_export(), list): # Stats is a list of data