From b60e879a10972c4563e1f4dd2b721faf049eb2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 17:02:43 +0100 Subject: [PATCH 01/36] Ref #8 Generate Flask application. Uploading file added. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 42 ++++++++++++++++++++++++++++++++++++++++ javacore_analyzer.py | 4 +--- requirements.txt | 1 + templates/index.html | 17 ++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 javacore_analyser_web.py create mode 100644 templates/index.html diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py new file mode 100644 index 0000000..6dc86d5 --- /dev/null +++ b/javacore_analyser_web.py @@ -0,0 +1,42 @@ +# +# Copyright IBM Corp. 2024 - 2024 +# SPDX-License-Identifier: Apache-2.0 +# +import os +import tempfile + +# Assisted by WCA@IBM +# Latest GenAI contribution: ibm/granite-20b-code-instruct-v2 +from flask import Flask, render_template, request + +import javacore_analyzer + +REPORTS_DIR = "reports" + +app = Flask(__name__) + +@app.route('/') +def index(): + return render_template('index.html') + +@app.route('/upload', methods=['POST']) +def upload_file(): + # Create a temporary directory to store uploaded files + javacores_temp_dir = tempfile.TemporaryDirectory() + javacores_temp_dir_name = javacores_temp_dir.name + + # Get the list of files from webpage + files = request.files.getlist("files") + + input_files = [] + # Iterate for each file in the files List, and Save them + for file in files: + file_name = os.path.join(javacores_temp_dir_name, file.filename) + file.save(file_name) + input_files.append(file_name) + + # Process the uploaded file + javacore_analyzer.process_javacores_and_generate_report_data(input_files, REPORTS_DIR) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/javacore_analyzer.py b/javacore_analyzer.py index 7bf8c88..a64f008 100644 --- a/javacore_analyzer.py +++ b/javacore_analyzer.py @@ -135,11 +135,9 @@ def generate_javecore_set_data(files): # Location when we store extracted archive or copied javacores files javacores_temp_dir = tempfile.TemporaryDirectory() - # It is strange but sometimes the temp directory contains the content from previous run - # javacores_temp_dir.cleanup() + javacores_temp_dir_name = javacores_temp_dir.name for file in files: - # file = file.strip() # Remove leading or trailing space in file path if os.path.isdir(file): shutil.copytree(file, javacores_temp_dir_name, dirs_exist_ok=True) else: diff --git a/requirements.txt b/requirements.txt index 2eb5b2e..b0eab6c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +flask dicttoxml py7zr lxml diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..43fdf9e --- /dev/null +++ b/templates/index.html @@ -0,0 +1,17 @@ + + + + + Upload Files + + +

Upload Files

+
+ + +
+ + From 5c87c649a068777f4347374774c16618c7a5dd34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 18:10:33 +0100 Subject: [PATCH 02/36] Ref #8 Upload and display uploaded dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index 6dc86d5..9aaf7a1 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -3,11 +3,11 @@ # SPDX-License-Identifier: Apache-2.0 # import os +import re import tempfile +from datetime import datetime -# Assisted by WCA@IBM -# Latest GenAI contribution: ibm/granite-20b-code-instruct-v2 -from flask import Flask, render_template, request +from flask import Flask, render_template, request, send_from_directory, redirect import javacore_analyzer @@ -15,10 +15,17 @@ app = Flask(__name__) + @app.route('/') def index(): return render_template('index.html') +@app.route('/reports/') +def dir_listing(path): + return send_from_directory(REPORTS_DIR, path) + +# Assisted by WCA@IBM +# Latest GenAI contribution: ibm/granite-20b-code-instruct-v2 @app.route('/upload', methods=['POST']) def upload_file(): # Create a temporary directory to store uploaded files @@ -35,8 +42,19 @@ def upload_file(): file.save(file_name) input_files.append(file_name) + if len(input_files) == 1: + report_name = input_files[0] + else: + report_name = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + report_name = re.sub(r'[^a-zA-Z0-9]', '_', report_name) + # Process the uploaded file - javacore_analyzer.process_javacores_and_generate_report_data(input_files, REPORTS_DIR) + report_output_dir = REPORTS_DIR + '/' + report_name + javacore_analyzer.process_javacores_and_generate_report_data(input_files, report_output_dir) + + return redirect(report_output_dir + "/index.html") + + if __name__ == '__main__': app.run(debug=True) From e9114c6a7bb3bca59d538e7c99e1bb42278e9a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 18:14:54 +0100 Subject: [PATCH 03/36] =?UTF-8?q?Added=20required=20line=20Signed-off-by:?= =?UTF-8?q?=20Krzysztof=20Ka=C5=BAmierczyk=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_set.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/javacore_set.py b/javacore_set.py index 2f40fb3..4d968ea 100644 --- a/javacore_set.py +++ b/javacore_set.py @@ -87,7 +87,6 @@ def process_javacores(input_path): jset.generate_tips() return jset - # Assisted by WCA@IBM # Latest GenAI contribution: ibm/granite-8b-code-instruct def generate_report_files(self, output_dir): @@ -288,7 +287,7 @@ def print_thread_states(self): for thread in self.threads: logging.debug("max running states:" + str(thread.get_continuous_running_states())) logging.debug(thread.name + "(id: " + str(thread.id) + "; hash: " + thread.get_hash() + ") " + \ - "states: " + thread.get_snapshot_states()) + "states: " + thread.get_snapshot_states()) # Assisted by WCA@IBM # Latest GenAI contribution: ibm/granite-8b-code-instruct From f4b10abc1a6de2930833f4adf5a83931695247f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 21:56:50 +0100 Subject: [PATCH 04/36] Ref #8 set a default report name to upload filename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index 9aaf7a1..dc5bbb4 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -6,6 +6,7 @@ import re import tempfile from datetime import datetime +from pathlib import Path from flask import Flask, render_template, request, send_from_directory, redirect @@ -43,7 +44,7 @@ def upload_file(): input_files.append(file_name) if len(input_files) == 1: - report_name = input_files[0] + report_name = Path(input_files[0]).name else: report_name = datetime.now().strftime("%Y-%m-%d %H:%M:%S") report_name = re.sub(r'[^a-zA-Z0-9]', '_', report_name) From 37b08ebe92f4eeab97196a97ea8d60ef73a6cc01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 22:15:31 +0100 Subject: [PATCH 05/36] Ref #8 Added logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- constants.py | 2 ++ javacore_analyser_web.py | 24 +++++++++++++++++++----- javacore_analyzer.py | 7 ++----- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/constants.py b/constants.py index 652637d..6af2dd6 100644 --- a/constants.py +++ b/constants.py @@ -33,3 +33,5 @@ MIN_JAVACORE_SIZE = 5 * 1024 # Minimal Javacore size in bytes DATE_FORMAT = "%Y-%m-%d %H:%M:%S" + +DEFAULT_REPORTS_DIR = "reports" diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index dc5bbb4..cf47810 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -2,8 +2,11 @@ # Copyright IBM Corp. 2024 - 2024 # SPDX-License-Identifier: Apache-2.0 # +import locale +import logging import os import re +import sys import tempfile from datetime import datetime from pathlib import Path @@ -11,19 +14,31 @@ from flask import Flask, render_template, request, send_from_directory, redirect import javacore_analyzer - -REPORTS_DIR = "reports" +from constants import DEFAULT_REPORTS_DIR app = Flask(__name__) +with app.app_context(): + logging.getLogger().setLevel(logging.NOTSET) + console_handler = logging.StreamHandler(sys.stdout) + console_handler.setLevel(logging.INFO) + console_handler.setFormatter(logging.Formatter(javacore_analyzer.LOGGING_FORMAT)) + logging.getLogger().addHandler(console_handler) + logging.info("Javacore analyser") + logging.info("Python version: " + sys.version) + logging.info("Preferred encoding: " + locale.getpreferredencoding()) + reports_dir = os.getenv("REPORTS_DIR", DEFAULT_REPORTS_DIR) + javacore_analyzer.create_file_logging(reports_dir) @app.route('/') def index(): return render_template('index.html') + @app.route('/reports/') def dir_listing(path): - return send_from_directory(REPORTS_DIR, path) + return send_from_directory(reports_dir, path) + # Assisted by WCA@IBM # Latest GenAI contribution: ibm/granite-20b-code-instruct-v2 @@ -50,12 +65,11 @@ def upload_file(): report_name = re.sub(r'[^a-zA-Z0-9]', '_', report_name) # Process the uploaded file - report_output_dir = REPORTS_DIR + '/' + report_name + report_output_dir = reports_dir + '/' + report_name javacore_analyzer.process_javacores_and_generate_report_data(input_files, report_output_dir) return redirect(report_output_dir + "/index.html") - if __name__ == '__main__': app.run(debug=True) diff --git a/javacore_analyzer.py b/javacore_analyzer.py index a64f008..11b259d 100644 --- a/javacore_analyzer.py +++ b/javacore_analyzer.py @@ -26,16 +26,15 @@ SUPPORTED_ARCHIVES_FORMATS = {"zip", "gz", "tgz", "bz2", "lzma", "7z"} - - def create_file_logging(logging_file_dir): logging_file = logging_file_dir + "/wait2-debug.log" - Path(logging_file_dir).mkdir(parents=True, exist_ok=True) # Sometimes the folder of logging might not exist + Path(logging_file_dir).mkdir(parents=True, exist_ok=True) # Sometimes the folder of logging might not exist file_handler = logging.FileHandler(logging_file, mode='w') file_handler.setLevel(logging.DEBUG) file_handler.setFormatter(logging.Formatter(LOGGING_FORMAT)) logging.getLogger().addHandler(file_handler) + def extract_archive(input_archive_filename, output_path): """ @@ -150,7 +149,6 @@ def generate_javecore_set_data(files): return JavacoreSet.process_javacores(javacores_temp_dir_name) - # Assisted by WCA@IBM # Latest GenAI contribution: ibm/granite-8b-code-instruct def process_javacores_and_generate_report_data(input_files, output_dir): @@ -168,6 +166,5 @@ def process_javacores_and_generate_report_data(input_files, output_dir): javacore_set.generate_report_files(output_dir) - if __name__ == "__main__": main() From 6ea17a18164bacdfff8e7da817fca1127bd29c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 22:22:13 +0100 Subject: [PATCH 06/36] Ref #8 Set starting port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- constants.py | 2 ++ javacore_analyser_web.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/constants.py b/constants.py index 6af2dd6..7c78c30 100644 --- a/constants.py +++ b/constants.py @@ -34,4 +34,6 @@ DATE_FORMAT = "%Y-%m-%d %H:%M:%S" +# Web application constants DEFAULT_REPORTS_DIR = "reports" +DEFAULT_PORT = 5000 diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index cf47810..088e7e4 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -14,7 +14,7 @@ from flask import Flask, render_template, request, send_from_directory, redirect import javacore_analyzer -from constants import DEFAULT_REPORTS_DIR +from constants import DEFAULT_REPORTS_DIR, DEFAULT_PORT app = Flask(__name__) with app.app_context(): @@ -72,4 +72,4 @@ def upload_file(): if __name__ == '__main__': - app.run(debug=True) + app.run(debug=True, port=os.getenv("PORT", DEFAULT_PORT)) From 6d933e12396e4eee866920e8636e457dd6042cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 22:35:22 +0100 Subject: [PATCH 07/36] Ref #8 Remove duplicate code for logging. Created logging_utils.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 12 +++++------- javacore_analyzer.py | 20 +++++--------------- logging_utils.py | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 logging_utils.py diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index 088e7e4..32229bc 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -4,6 +4,8 @@ # import locale import logging + +import logging_utils import os import re import sys @@ -18,16 +20,12 @@ app = Flask(__name__) with app.app_context(): - logging.getLogger().setLevel(logging.NOTSET) - console_handler = logging.StreamHandler(sys.stdout) - console_handler.setLevel(logging.INFO) - console_handler.setFormatter(logging.Formatter(javacore_analyzer.LOGGING_FORMAT)) - logging.getLogger().addHandler(console_handler) + logging_utils.create_console_logging() logging.info("Javacore analyser") logging.info("Python version: " + sys.version) logging.info("Preferred encoding: " + locale.getpreferredencoding()) reports_dir = os.getenv("REPORTS_DIR", DEFAULT_REPORTS_DIR) - javacore_analyzer.create_file_logging(reports_dir) + logging_utils.create_file_logging(reports_dir) @app.route('/') @@ -68,7 +66,7 @@ def upload_file(): report_output_dir = reports_dir + '/' + report_name javacore_analyzer.process_javacores_and_generate_report_data(input_files, report_output_dir) - return redirect(report_output_dir + "/index.html") + return redirect("/reports/" + report_name + "/index.html") if __name__ == '__main__': diff --git a/javacore_analyzer.py b/javacore_analyzer.py index 11b259d..ed34b8c 100644 --- a/javacore_analyzer.py +++ b/javacore_analyzer.py @@ -7,6 +7,8 @@ import fnmatch import locale import logging + +import logging_utils import os.path import shutil import sys @@ -14,25 +16,17 @@ import tempfile import traceback import zipfile -from pathlib import Path import py7zr from constants import DEFAULT_FILE_DELIMITER, DATA_OUTPUT_SUBDIR from javacore_set import JavacoreSet -LOGGING_FORMAT = '%(asctime)s [%(levelname)s][%(filename)s:%(lineno)s] %(message)s' SUPPORTED_ARCHIVES_FORMATS = {"zip", "gz", "tgz", "bz2", "lzma", "7z"} -def create_file_logging(logging_file_dir): - logging_file = logging_file_dir + "/wait2-debug.log" - Path(logging_file_dir).mkdir(parents=True, exist_ok=True) # Sometimes the folder of logging might not exist - file_handler = logging.FileHandler(logging_file, mode='w') - file_handler.setLevel(logging.DEBUG) - file_handler.setFormatter(logging.Formatter(LOGGING_FORMAT)) - logging.getLogger().addHandler(file_handler) + def extract_archive(input_archive_filename, output_path): @@ -75,11 +69,7 @@ def extract_archive(input_archive_filename, output_path): def main(): - logging.getLogger().setLevel(logging.NOTSET) - console_handler = logging.StreamHandler(sys.stdout) - console_handler.setLevel(logging.INFO) - console_handler.setFormatter(logging.Formatter(LOGGING_FORMAT)) - logging.getLogger().addHandler(console_handler) + logging_utils.create_console_logging() logging.info("Wait2 tool") logging.info("Python version: " + sys.version) logging.info("Preferred encoding: " + locale.getpreferredencoding()) @@ -100,7 +90,7 @@ def main(): logging.info("Report directory: " + output_param) # Needs to be created once output file structure is ready. - create_file_logging(output_param) + logging_utils.create_file_logging(output_param) # Check whether as input we got list of files or single file # Semicolon is separation mark for list of input files diff --git a/logging_utils.py b/logging_utils.py new file mode 100644 index 0000000..6fbed00 --- /dev/null +++ b/logging_utils.py @@ -0,0 +1,26 @@ +# +# Copyright IBM Corp. 2024 - 2024 +# SPDX-License-Identifier: Apache-2.0 +# + +import logging +import sys +from pathlib import Path + +LOGGING_FORMAT = '%(asctime)s [%(levelname)s][%(filename)s:%(lineno)s] %(message)s' + +def create_file_logging(logging_file_dir): + logging_file = logging_file_dir + "/wait2-debug.log" + Path(logging_file_dir).mkdir(parents=True, exist_ok=True) # Sometimes the folder of logging might not exist + file_handler = logging.FileHandler(logging_file, mode='w') + file_handler.setLevel(logging.DEBUG) + file_handler.setFormatter(logging.Formatter(LOGGING_FORMAT)) + logging.getLogger().addHandler(file_handler) + + +def create_console_logging(): + logging.getLogger().setLevel(logging.NOTSET) + console_handler = logging.StreamHandler(sys.stdout) + console_handler.setLevel(logging.INFO) + console_handler.setFormatter(logging.Formatter(LOGGING_FORMAT)) + logging.getLogger().addHandler(console_handler) From 03a492190a78562e187f2eace029939891d27e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 22:51:00 +0100 Subject: [PATCH 08/36] Ref #8 List of reports on main page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 4 +++- templates/index.html | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index 32229bc..c1101ac 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -25,12 +25,14 @@ logging.info("Python version: " + sys.version) logging.info("Preferred encoding: " + locale.getpreferredencoding()) reports_dir = os.getenv("REPORTS_DIR", DEFAULT_REPORTS_DIR) + logging.info("Reports directory: " + reports_dir) logging_utils.create_file_logging(reports_dir) @app.route('/') def index(): - return render_template('index.html') + reports = [Path(f).name for f in os.scandir(reports_dir) if f.is_dir()] + return render_template('index.html', reports=reports) @app.route('/reports/') diff --git a/templates/index.html b/templates/index.html index 43fdf9e..7bbb00b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,5 +13,12 @@

Upload Files

+ +

List of the reports:

+ + {% for report in reports %} + + {% endfor %} +
{{ report }}
From 11a6a1522ae284dd262213d2e537615c10cccf42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 22:52:54 +0100 Subject: [PATCH 09/36] Ref #8 Add links to the reports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- templates/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/index.html b/templates/index.html index 7bbb00b..ed7a41a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,7 +17,7 @@

Upload Files

List of the reports:

{% for report in reports %} - + {% endfor %}
{{ report }}
{{ report }}
From eaaa88160e174eb0ecba1493ddcbfa3f7901525c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 22:56:18 +0100 Subject: [PATCH 10/36] Ref #8 Some improvements in index.html MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- templates/index.html | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/templates/index.html b/templates/index.html index ed7a41a..3f993f3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,16 +5,21 @@ --> - Upload Files + Javacore Analyser -

Upload Files

+

Javacore Analyser

+ +

Generate report:

+

+ NOTE: The report generation is expensive operation and might take even few minutes. Please be patient +

-

List of the reports:

+

List of generated reports:

{% for report in reports %} From 6be0df02c6a5fccab39967c0940bbd4292a24ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 22:58:12 +0100 Subject: [PATCH 11/36] Ref #8 Some improvements in index.html MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- templates/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/index.html b/templates/index.html index 3f993f3..51cab8c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,7 +12,7 @@

Javacore Analyser

Generate report:

- + Select archive file or multiple javacore files:

From d63b7cf347ee1492b0bd83bc50184412b2f06bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 23:54:15 +0100 Subject: [PATCH 12/36] Ref #8 Added downloading zip file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 71 +++++++++++++++++++++++++--------------- templates/index.html | 5 ++- 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index c1101ac..dd159a0 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -4,6 +4,7 @@ # import locale import logging +import shutil import logging_utils import os @@ -13,7 +14,7 @@ from datetime import datetime from pathlib import Path -from flask import Flask, render_template, request, send_from_directory, redirect +from flask import Flask, render_template, request, send_from_directory, redirect, send_file import javacore_analyzer from constants import DEFAULT_REPORTS_DIR, DEFAULT_PORT @@ -40,35 +41,53 @@ def dir_listing(path): return send_from_directory(reports_dir, path) +@app.route('/zip/') +def compress(path): + try: + temp_zip_dir = tempfile.TemporaryDirectory() + temp_zip_dir_name = temp_zip_dir.name + zip_filename = path + ".zip" + report_location = os.path.join(reports_dir, path) + shutil.make_archive(os.path.join(temp_zip_dir_name, path), 'zip', report_location) + logging.debug("Generated zip file location:" + os.path.join(temp_zip_dir_name,zip_filename)) + logging.debug("Temp zip dir name: " + temp_zip_dir_name) + logging.debug("Zip filename: " + zip_filename) + return send_from_directory(temp_zip_dir_name, zip_filename, as_attachment=True) + finally: + temp_zip_dir.cleanup() + # Assisted by WCA@IBM # Latest GenAI contribution: ibm/granite-20b-code-instruct-v2 @app.route('/upload', methods=['POST']) def upload_file(): - # Create a temporary directory to store uploaded files - javacores_temp_dir = tempfile.TemporaryDirectory() - javacores_temp_dir_name = javacores_temp_dir.name - - # Get the list of files from webpage - files = request.files.getlist("files") - - input_files = [] - # Iterate for each file in the files List, and Save them - for file in files: - file_name = os.path.join(javacores_temp_dir_name, file.filename) - file.save(file_name) - input_files.append(file_name) - - if len(input_files) == 1: - report_name = Path(input_files[0]).name - else: - report_name = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - report_name = re.sub(r'[^a-zA-Z0-9]', '_', report_name) - - # Process the uploaded file - report_output_dir = reports_dir + '/' + report_name - javacore_analyzer.process_javacores_and_generate_report_data(input_files, report_output_dir) - - return redirect("/reports/" + report_name + "/index.html") + try: + # Create a temporary directory to store uploaded files + javacores_temp_dir = tempfile.TemporaryDirectory() + javacores_temp_dir_name = javacores_temp_dir.name + + # Get the list of files from webpage + files = request.files.getlist("files") + + input_files = [] + # Iterate for each file in the files List, and Save them + for file in files: + file_name = os.path.join(javacores_temp_dir_name, file.filename) + file.save(file_name) + input_files.append(file_name) + + if len(input_files) == 1: + report_name = Path(input_files[0]).name + else: + report_name = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + report_name = re.sub(r'[^a-zA-Z0-9]', '_', report_name) + + # Process the uploaded file + report_output_dir = reports_dir + '/' + report_name + javacore_analyzer.process_javacores_and_generate_report_data(input_files, report_output_dir) + + return redirect("/reports/" + report_name + "/index.html") + finally: + javacores_temp_dir.cleanup() if __name__ == '__main__': diff --git a/templates/index.html b/templates/index.html index 51cab8c..a7c7cda 100644 --- a/templates/index.html +++ b/templates/index.html @@ -22,7 +22,10 @@

Generate report:

List of generated reports:

{{ report }}
{% for report in reports %} - + + + + {% endfor %}
{{ report }}
{{ report }} download
From 00acd38ab3929c3c934627b8f0a357fb5c125a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Wed, 30 Oct 2024 23:54:52 +0100 Subject: [PATCH 13/36] Ref #8 Removed unused import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index dd159a0..6d0c17d 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -14,7 +14,7 @@ from datetime import datetime from pathlib import Path -from flask import Flask, render_template, request, send_from_directory, redirect, send_file +from flask import Flask, render_template, request, send_from_directory, redirect import javacore_analyzer from constants import DEFAULT_REPORTS_DIR, DEFAULT_PORT From 48df16027d577d4fb43ef01a7349effc92852901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 07:12:18 +0100 Subject: [PATCH 14/36] Removing exit on processing Javacore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyzer.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/javacore_analyzer.py b/javacore_analyzer.py index ed34b8c..c3d4382 100644 --- a/javacore_analyzer.py +++ b/javacore_analyzer.py @@ -57,10 +57,9 @@ def extract_archive(input_archive_filename, output_path): file = py7zr.SevenZipFile(input_archive_filename) logging.info("Processing 7z file") else: - logging.error("The format of file is not supported. " + raise Exception("The format of file is not supported. " "Currently we support only zip, tar.gz, tgz, tar.bz2 and 7z. " - "Cannot proceed. Exiting") - exit(13) + "Cannot proceed.") file.extractall(path=output_path) file.close() From 8bd0554c497d5d3f9660ed6535d92fb6d80a85b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 07:14:10 +0100 Subject: [PATCH 15/36] Cleanup javacores temp dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyzer.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/javacore_analyzer.py b/javacore_analyzer.py index c3d4382..423b1db 100644 --- a/javacore_analyzer.py +++ b/javacore_analyzer.py @@ -7,8 +7,6 @@ import fnmatch import locale import logging - -import logging_utils import os.path import shutil import sys @@ -19,10 +17,10 @@ import py7zr -from constants import DEFAULT_FILE_DELIMITER, DATA_OUTPUT_SUBDIR +import logging_utils +from constants import DEFAULT_FILE_DELIMITER from javacore_set import JavacoreSet - SUPPORTED_ARCHIVES_FORMATS = {"zip", "gz", "tgz", "bz2", "lzma", "7z"} @@ -122,20 +120,24 @@ def generate_javecore_set_data(files): """ # Location when we store extracted archive or copied javacores files - javacores_temp_dir = tempfile.TemporaryDirectory() - - javacores_temp_dir_name = javacores_temp_dir.name - for file in files: - if os.path.isdir(file): - shutil.copytree(file, javacores_temp_dir_name, dirs_exist_ok=True) - else: - filename, extension = os.path.splitext(file) - extension = extension[1:] # trim trailing "." - if extension.lower() in SUPPORTED_ARCHIVES_FORMATS: - extract_archive(file, javacores_temp_dir_name) # Extract archive to temp dir + try: + javacores_temp_dir = tempfile.TemporaryDirectory() + + javacores_temp_dir_name = javacores_temp_dir.name + for file in files: + if os.path.isdir(file): + shutil.copytree(file, javacores_temp_dir_name, dirs_exist_ok=True) else: - shutil.copy2(file, javacores_temp_dir_name) - return JavacoreSet.process_javacores(javacores_temp_dir_name) + filename, extension = os.path.splitext(file) + extension = extension[1:] # trim trailing "." + if extension.lower() in SUPPORTED_ARCHIVES_FORMATS: + extract_archive(file, javacores_temp_dir_name) # Extract archive to temp dir + else: + shutil.copy2(file, javacores_temp_dir_name) + return JavacoreSet.process_javacores(javacores_temp_dir_name) + finally: + javacores_temp_dir.cleanup() + # Assisted by WCA@IBM From 3b5598b4e28d6993335f252f4c5c3fdb31f942d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 07:19:47 +0100 Subject: [PATCH 16/36] Ref #8 logging thread id for better debugging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- logging_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/logging_utils.py b/logging_utils.py index 6fbed00..bb9dff1 100644 --- a/logging_utils.py +++ b/logging_utils.py @@ -7,7 +7,8 @@ import sys from pathlib import Path -LOGGING_FORMAT = '%(asctime)s [%(levelname)s][%(filename)s:%(lineno)s] %(message)s' +LOGGING_FORMAT = '%(asctime)s [thread: %(thread)d][%(levelname)s][%(filename)s:%(lineno)s] %(message)s' + def create_file_logging(logging_file_dir): logging_file = logging_file_dir + "/wait2-debug.log" From 3c412d0ed7cbed35901f2888406349723ec37499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 07:21:49 +0100 Subject: [PATCH 17/36] Ref #8 Parametrise debug option in system properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index 6d0c17d..543eb0e 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -4,11 +4,9 @@ # import locale import logging -import shutil - -import logging_utils import os import re +import shutil import sys import tempfile from datetime import datetime @@ -17,6 +15,7 @@ from flask import Flask, render_template, request, send_from_directory, redirect import javacore_analyzer +import logging_utils from constants import DEFAULT_REPORTS_DIR, DEFAULT_PORT app = Flask(__name__) @@ -91,4 +90,4 @@ def upload_file(): if __name__ == '__main__': - app.run(debug=True, port=os.getenv("PORT", DEFAULT_PORT)) + app.run(debug=os.getenv("DEBUG", False), port=os.getenv("PORT", DEFAULT_PORT)) From 9f81ab361a655c916aef16b41b9de937b2035548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 07:28:05 +0100 Subject: [PATCH 18/36] Ref #8 Add some documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index 543eb0e..34f8d7d 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -90,4 +90,10 @@ def upload_file(): if __name__ == '__main__': + """ + The application passes the following environmental variables: + DEBUG (default: False) - defines if we should run an app in debug mode + PORT - application port + REPORTS_DIR - the directory when the reports are stored as default + """ app.run(debug=os.getenv("DEBUG", False), port=os.getenv("PORT", DEFAULT_PORT)) From 7d058b913051bb04fba46743bcfc754d02a42a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 07:41:11 +0100 Subject: [PATCH 19/36] Ref #8 Add more documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index 34f8d7d..e651fbb 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -18,6 +18,11 @@ import logging_utils from constants import DEFAULT_REPORTS_DIR, DEFAULT_PORT +""" +To run the application from cmd type: +export REPORTS_DIR=/tmp/reports +flask --app javacore_analyser_web run +""" app = Flask(__name__) with app.app_context(): logging_utils.create_console_logging() From cb189d43623d7060c64c2b567dca83068b270182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 07:54:17 +0100 Subject: [PATCH 20/36] Ref #8 Deleting report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 7 +++++++ templates/index.html | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index e651fbb..515a743 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -60,6 +60,13 @@ def compress(path): finally: temp_zip_dir.cleanup() +@app.route('/delete/') +def delete(path): + report_location = os.path.join(reports_dir, path) + logging.info("Deleting directory " + report_location) + shutil.rmtree(report_location) + return redirect("/") + # Assisted by WCA@IBM # Latest GenAI contribution: ibm/granite-20b-code-instruct-v2 @app.route('/upload', methods=['POST']) diff --git a/templates/index.html b/templates/index.html index a7c7cda..d94c8fe 100644 --- a/templates/index.html +++ b/templates/index.html @@ -24,7 +24,12 @@

List of generated reports:

{% for report in reports %} {{ report }} - download + download + + + delete + + {% endfor %} From ac7fd99456934ae4af4c3125f78f00c656b1c07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 08:42:34 +0100 Subject: [PATCH 21/36] Ref #8 Added creation date to the report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 4 +++- templates/index.html | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index 515a743..8384139 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -9,6 +9,7 @@ import shutil import sys import tempfile +import time from datetime import datetime from pathlib import Path @@ -36,7 +37,8 @@ @app.route('/') def index(): - reports = [Path(f).name for f in os.scandir(reports_dir) if f.is_dir()] + reports = [{"name": Path(f).name, "date": time.ctime(os.path.getctime(f))} + for f in os.scandir(reports_dir) if f.is_dir()] return render_template('index.html', reports=reports) diff --git a/templates/index.html b/templates/index.html index d94c8fe..b7a576d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -21,12 +21,16 @@

Generate report:

List of generated reports:

+ {% for report in reports %} + {% set name = report['name'] %} + {% set date = report['date'] %} - - + + + From 79cfdaee3f36d1dbd72b95fd503547383af68aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 08:49:43 +0100 Subject: [PATCH 22/36] Ref #8 Sorting reports by last added date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index 8384139..7f6db54 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -37,8 +37,9 @@ @app.route('/') def index(): - reports = [{"name": Path(f).name, "date": time.ctime(os.path.getctime(f))} + reports = [{"name": Path(f).name, "date": time.ctime(os.path.getctime(f)), "timestamp": os.path.getctime(f)} for f in os.scandir(reports_dir) if f.is_dir()] + reports.sort(key=lambda item: item["timestamp"], reverse=True) return render_template('index.html', reports=reports) From 72443337ce9f068e5d97666bedb4a0a4ab417a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 09:09:48 +0100 Subject: [PATCH 23/36] Ref #8 Set name for the form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 6 +----- templates/index.html | 15 +++++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index 7f6db54..498db64 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -10,7 +10,6 @@ import sys import tempfile import time -from datetime import datetime from pathlib import Path from flask import Flask, render_template, request, send_from_directory, redirect @@ -89,10 +88,7 @@ def upload_file(): file.save(file_name) input_files.append(file_name) - if len(input_files) == 1: - report_name = Path(input_files[0]).name - else: - report_name = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + report_name = request.values.get("report_name") report_name = re.sub(r'[^a-zA-Z0-9]', '_', report_name) # Process the uploaded file diff --git a/templates/index.html b/templates/index.html index b7a576d..38148b3 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,7 +3,7 @@ // Assisted by WCA@IBM // Latest GenAI contribution: ibm/granite-20b-code-instruct-v2 --> - + Javacore Analyser @@ -12,12 +12,15 @@

Javacore Analyser

Generate report:

- Select archive file or multiple javacore files: - +
Report Name:
+
Archive file or multiple javacore files:
+ + NOTE: The report generation is expensive operation and might take even few minutes. Please be patient + +

-

- NOTE: The report generation is expensive operation and might take even few minutes. Please be patient -

+

+

List of generated reports:

Name Creation Date Download Delete
{{ report }} download {{ name }} {{ date }} download - + delete
From b38a2045eb00224cfb52819805b1d09a254cc084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 09:56:52 +0100 Subject: [PATCH 24/36] Ref #8 Documented Flask usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b0eab6c..59e8fca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -flask dicttoxml py7zr lxml pyana +flask # WSGI server for development the code From eaf95954af15939704b5a24d26df1ee7adaeadca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 10:23:19 +0100 Subject: [PATCH 25/36] Ref #8 Prevent security vulnerability to delete the reports outside temp directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- javacore_analyser_web.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/javacore_analyser_web.py b/javacore_analyser_web.py index 498db64..c369a22 100644 --- a/javacore_analyser_web.py +++ b/javacore_analyser_web.py @@ -64,9 +64,16 @@ def compress(path): @app.route('/delete/') def delete(path): - report_location = os.path.join(reports_dir, path) - logging.info("Deleting directory " + report_location) - shutil.rmtree(report_location) + # Checking if the report exists. This is to prevent attempt to delete any data by deleting any file outside + # report dir if you prepare path variable. + reports_list = os.listdir(reports_dir) + if path in reports_list: + report_location = os.path.join(reports_dir, path) + logging.info("Deleting directory " + report_location) + shutil.rmtree(report_location) + else: + logging.error("Deleted report in report list. Not deleting") + return "Cannot delete the report. The report " + path + " does not exist", 503 return redirect("/") # Assisted by WCA@IBM From eba89185b30c5342ec606eb48c5ac0e76af9e4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 10:26:54 +0100 Subject: [PATCH 26/36] Typo in README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e88a122..8507e1d 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Steps: `python javacore_analyzer.py ` Where `` is one of the following: * The directory containing javacores and optionally verbose gc -* Archive (7z, zip, tar.gz, tar.bz2) containint the same +* Archive (7z, zip, tar.gz, tar.bz2) containing the same * List of the javacores separated by `'` character. Optionally you can add `--separator` option to define your own separator. You can type the following command to obtain the help: `python javacore_analyzer.py --help` From 024f97df542695268475c2365e86223a2efa58aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Ka=C5=BAmierczyk?= Date: Thu, 31 Oct 2024 10:35:41 +0100 Subject: [PATCH 27/36] Ref #8 added instructions to readme how to run application MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Krzysztof Kaźmierczyk --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8507e1d..f1f5fd2 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,12 @@ Steps: `pip install -r requirements.txt` ### Running the tool: + +#### Running cmd application: 1. Activate your created virtual environment according to activate Virtual Environment according to [Creating virtual environments](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) -2. Navigate in command line to unpacked tool and run the following command: +2. Install the requirements using pip: + `pip install requirements.txt` +3. Navigate in command line to unpacked tool and run the following command: `python javacore_analyzer.py ` Where `` is one of the following: * The directory containing javacores and optionally verbose gc @@ -37,6 +41,15 @@ Where `` is one of the following: You can type the following command to obtain the help: `python javacore_analyzer.py --help` +#### Running web application: +1. Repeat steps 1 and 2 from cmd application +2. Navigate to unpacked tool and run the following commands: + ``` + export REPORTS_DIR=/tmp/reports + flask --app javacore_analyser_web run + ``` + The first command sets the location of the generated reports stored. + The second command starts the server which can be accessed by navigating to http://localhost:5000 +