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

Add --perf flag #701

Merged
merged 2 commits into from
Nov 24, 2020
Merged
Changes from all 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
17 changes: 17 additions & 0 deletions slither/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env python3

import argparse
import cProfile
import glob
import inspect
import json
import logging
import os
import pstats
import sys
import traceback
from typing import Optional

from pkg_resources import iter_entry_points, require

Expand Down Expand Up @@ -489,6 +492,10 @@ def parse_args(detector_classes, printer_classes):
default=defaults_flag_in_config["ignore_return_value"],
)

parser.add_argument(
"--perf", help=argparse.SUPPRESS, action="store_true", default=False,
)

# if the json is splitted in different files
parser.add_argument("--splitted", help=argparse.SUPPRESS, action="store_true", default=False)

Expand Down Expand Up @@ -598,6 +605,11 @@ def main_impl(all_detector_classes, all_printer_classes):
logger.setLevel(logging.INFO)
args = parse_args(all_detector_classes, all_printer_classes)

cp: Optional[cProfile.Profile] = None
if args.perf:
cp = cProfile.Profile()
cp.enable()

# Set colorization option
set_colorization_enabled(not args.disable_color)

Expand Down Expand Up @@ -773,6 +785,11 @@ def main_impl(all_detector_classes, all_printer_classes):
if outputting_zip:
output_to_zip(args.zip, output_error, json_results, args.zip_type)

if args.perf:
cp.disable()
stats = pstats.Stats(cp).sort_stats("cumtime")
stats.print_stats()

# Exit with the appropriate status code
if output_error:
sys.exit(-1)
Expand Down