Skip to content

Commit 6bad931

Browse files
authored
Merge pull request #843 from ziadhany/parallel-importer
test redhat importer performance by profiling
2 parents 8e8624b + f6ddb32 commit 6bad931

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

vulnerabilities/management/commands/import.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# See https://github.com/nexB/vulnerablecode for support or download.
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
9-
109
import traceback
1110

1211
from django.core.management.base import BaseCommand
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
#
3+
# Copyright (c) nexB Inc. and others. All rights reserved.
4+
# VulnerableCode is a trademark of nexB Inc.
5+
# SPDX-License-Identifier: Apache-2.0
6+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
7+
# See https://github.com/nexB/vulnerablecode for support or download.
8+
# See https://aboutcode.org for more information about nexB OSS projects.
9+
#
10+
import pytest
11+
12+
# this import are used in the script
13+
from vulnerabilities.importers import redhat
14+
15+
script = """for i, data in enumerate(redhat.RedhatImporter().advisory_data()):
16+
if 1 == 100:
17+
break"""
18+
19+
20+
@pytest.mark.skip("Use only for local profiling")
21+
@pytest.mark.django_db
22+
class TestImporter:
23+
def test_redhat_importer_performance_profiling(self):
24+
print_profiling_status(script, "redhat.txt")
25+
26+
27+
def print_profiling_status(test_py, stats_file, top=50):
28+
import cProfile as profile
29+
import pstats
30+
31+
profile.runctx(test_py, globals(), locals(), stats_file)
32+
p = pstats.Stats(stats_file)
33+
p.sort_stats("time").print_stats(top)

0 commit comments

Comments
 (0)