Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test redhat importer performance by profiling #843

Merged
merged 4 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion vulnerabilities/management/commands/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions vulnerabilities/tests/test_performance.py
Original file line number Diff line number Diff line change
@@ -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)