summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-02-27 15:29:32 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2019-02-27 15:29:32 +0100
commit52253a519609d6d8990d9d6812ea9bed0204c81c (patch)
treecaa6207d12fcff6ba78f714360d3fb01b6aa8c41
parent665f0c1c275a3575da4b01ea859a4c41a82a7321 (diff)
downloadpsutil-52253a519609d6d8990d9d6812ea9bed0204c81c.tar.gz
add arg parser for ad script
-rwxr-xr-x.ci/travis/run.sh3
-rw-r--r--Makefile2
-rwxr-xr-xscripts/internal/download_exes.py10
-rw-r--r--scripts/internal/print_api_speed.py17
4 files changed, 25 insertions, 7 deletions
diff --git a/.ci/travis/run.sh b/.ci/travis/run.sh
index 06cc5b7e..81838633 100755
--- a/.ci/travis/run.sh
+++ b/.ci/travis/run.sh
@@ -33,3 +33,6 @@ if [ "$PYVER" == "2.7" ] || [ "$PYVER" == "3.6" ]; then
python -m flake8
fi
fi
+
+PSUTIL_TESTING=1 python -Wa scripts/internal/print_access_denied.py
+PSUTIL_TESTING=1 python -Wa scripts/internal/print_api_speed.py
diff --git a/Makefile b/Makefile
index 6c64a0b5..839a6026 100644
--- a/Makefile
+++ b/Makefile
@@ -256,7 +256,7 @@ print-access-denied: ## Print AD exceptions
@$(TEST_PREFIX) $(PYTHON) scripts/internal/print_access_denied.py
print-api-speed: ## Benchmark all API calls
- @$(TEST_PREFIX) $(PYTHON) scripts/internal/print_api_speed.py
+ @$(TEST_PREFIX) $(PYTHON) scripts/internal/print_api_speed.py $(ARGS)
# ===================================================================
# Misc
diff --git a/scripts/internal/download_exes.py b/scripts/internal/download_exes.py
index e3e6a46d..efe4ef18 100755
--- a/scripts/internal/download_exes.py
+++ b/scripts/internal/download_exes.py
@@ -122,7 +122,7 @@ def rename_27_wheels():
os.rename(src, dst)
-def main(options):
+def run(options):
safe_rmtree('dist')
urls = get_file_urls(options)
completed = 0
@@ -149,10 +149,14 @@ def main(options):
rename_27_wheels()
-if __name__ == '__main__':
+def main():
parser = argparse.ArgumentParser(
description='AppVeyor artifact downloader')
parser.add_argument('--user', required=True)
parser.add_argument('--project', required=True)
args = parser.parse_args()
- main(args)
+ run(args)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/scripts/internal/print_api_speed.py b/scripts/internal/print_api_speed.py
index c0e0e0e0..b88ab3c5 100644
--- a/scripts/internal/print_api_speed.py
+++ b/scripts/internal/print_api_speed.py
@@ -25,18 +25,19 @@ PROCESS APIS
from __future__ import print_function, division
from timeit import default_timer as timer
+import argparse
import inspect
import os
import psutil
-SORT_BY_NAME = 0 # <- toggle this
+SORT_BY_TIME = False
timings = []
def print_timings():
- timings.sort(key=lambda x: x[0 if SORT_BY_NAME else 1])
+ timings.sort(key=lambda x: x[1 if SORT_BY_TIME else 0])
while timings[:]:
title, elapsed = timings.pop(0)
print("%-30s %f secs" % (title, elapsed))
@@ -49,7 +50,7 @@ def timecall(title, fun, *args, **kw):
timings.append((title, elapsed))
-def main():
+def run():
# --- system
public_apis = []
@@ -86,5 +87,15 @@ def main():
print_timings()
+def main():
+ global SORT_BY_TIME
+ parser = argparse.ArgumentParser(description='Benchmark all API calls')
+ parser.add_argument('-t', '--time', required=False, default=False,
+ action='store_true', help="sort by timings")
+ args = parser.parse_args()
+ SORT_BY_TIME = bool(args.time)
+ run()
+
+
if __name__ == '__main__':
main()