Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/build_config/performance.py
169673 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2011-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file performance.py
15
# @author Michael Behrisch
16
# @date 2023-10-02
17
18
"""
19
This script builds all sumo versions in a certain revision range
20
and tries to eliminate duplicates afterwards.
21
"""
22
23
import os
24
import sys
25
import subprocess
26
import glob
27
import time
28
import psutil
29
30
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
31
import sumolib # noqa
32
33
34
arg_parser = sumolib.options.ArgumentParser()
35
arg_parser.add_argument("cfg", nargs="+", help="sumo config to run")
36
arg_parser.add_argument("-d", "--version-dir", default=".history", help="where to find sumo versions")
37
arg_parser.add_argument("-r", "--repeat", type=int, default=5, help="number of runs")
38
options = arg_parser.parse_args()
39
40
versions = []
41
for sumo in glob.glob(os.path.join(options.version_dir, "bin*", "sumo")):
42
versions.append(([int(d) for d in sumo[len(options.version_dir) + 5:-5].split("_")], sumo))
43
versions.sort()
44
45
for c in options.cfg:
46
for version, sumo in versions:
47
times = []
48
mems = []
49
for _ in range(options.repeat):
50
p = subprocess.Popen([sumo, c], stdout=subprocess.DEVNULL)
51
ps = psutil.Process(p.pid)
52
utime = None
53
mem = 0
54
while p.poll() is None:
55
with ps.oneshot():
56
utime = ps.cpu_times().user
57
mem = max(mem, ps.memory_full_info().uss)
58
time.sleep(0.1)
59
times.append(utime)
60
mems.append(mem)
61
times.sort()
62
mems.sort()
63
num = options.repeat
64
if num > 4:
65
times = times[1:-1]
66
mems = mems[1:-1]
67
num -= 2
68
print(".".join(map(str, version)), "%.2f" % (sum(times) / num), "%.2f" % (sum(mems) / num / 2 ** 20))
69
70