Skip to content

Commit

Permalink
Merge pull request #843 from ziadhany/parallel-importer
Browse files Browse the repository at this point in the history
test redhat importer performance by profiling
  • Loading branch information
pombredanne authored Oct 18, 2022
2 parents 8e8624b + f6ddb32 commit 6bad931
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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)

0 comments on commit 6bad931

Please sign in to comment.