diff --git a/vulnerabilities/management/commands/import.py b/vulnerabilities/management/commands/import.py index 17c2140cc..386cbbcae 100644 --- a/vulnerabilities/management/commands/import.py +++ b/vulnerabilities/management/commands/import.py @@ -6,7 +6,6 @@ # See https://github.com/nexB/vulnerablecode for support or download. # See https://aboutcode.org for more information about nexB OSS projects. # - import traceback from django.core.management.base import BaseCommand diff --git a/vulnerabilities/tests/test_performance.py b/vulnerabilities/tests/test_performance.py new file mode 100644 index 000000000..1dd376aee --- /dev/null +++ b/vulnerabilities/tests/test_performance.py @@ -0,0 +1,33 @@ +# +# +# Copyright (c) nexB Inc. and others. All rights reserved. +# VulnerableCode is a trademark of nexB Inc. +# SPDX-License-Identifier: Apache-2.0 +# See http://www.apache.org/licenses/LICENSE-2.0 for the license text. +# See https://github.com/nexB/vulnerablecode for support or download. +# See https://aboutcode.org for more information about nexB OSS projects. +# +import pytest + +# this import are used in the script +from vulnerabilities.importers import redhat + +script = """for i, data in enumerate(redhat.RedhatImporter().advisory_data()): + if 1 == 100: + break""" + + +@pytest.mark.skip("Use only for local profiling") +@pytest.mark.django_db +class TestImporter: + def test_redhat_importer_performance_profiling(self): + print_profiling_status(script, "redhat.txt") + + +def print_profiling_status(test_py, stats_file, top=50): + import cProfile as profile + import pstats + + profile.runctx(test_py, globals(), locals(), stats_file) + p = pstats.Stats(stats_file) + p.sort_stats("time").print_stats(top)