-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #843 from ziadhany/parallel-importer
test redhat importer performance by profiling
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |