Created
December 24, 2017 18:52
-
-
Save gatoatigrado/158c52a8ed5f15b1b12e151d3a23ea41 to your computer and use it in GitHub Desktop.
Profiling script
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
# -*- coding: utf-8 -*- | |
"""Runs RawTherapee benchmarking""" | |
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
import glob | |
import os | |
import os.path | |
import subprocess | |
def main(): | |
input_file = "/tmp/test.arw" | |
profile_file = "/tmp/rawtherapee.prof" | |
rawtherapee_cli = os.path.expanduser("~/sandbox/oss/RawTherapee/build/relwithdebinfo" | |
"/rawtherapee-cli") | |
profile_svg = "/tmp/rawtherapee_profile.svg" | |
core_governors = glob.glob("/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor") | |
assert core_governors | |
for filename in core_governors: | |
with open(filename) as f: | |
# Example way to set governor: | |
# sudo bash -c 'for f in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo performance > $f; done' | |
assert f.read().strip() == "performance", ( | |
"For benchmark stability, please disable CPU frequency scaling") | |
assert os.path.isfile(input_file) | |
if os.path.isfile(profile_file): | |
os.unlink(profile_file) | |
if os.path.isfile(profile_svg): | |
os.unlink(profile_svg) | |
subprocess.check_call([ | |
rawtherapee_cli, | |
"-Y", "-t", "-c", input_file | |
], env=dict( | |
os.environ, | |
LD_PRELOAD="/usr/lib/libprofiler.so", | |
CPUPROFILE=profile_file, | |
# Sample the stack trace 1000 times per second. This doesn't seem to affect | |
# performance much over the default 100, and having more samples seems nice. | |
CPUPROFILE_FREQUENCY="1000" | |
)) | |
assert os.path.isfile(profile_file) | |
# Generate profile | |
svg_contents = subprocess.check_output([ | |
"google-pprof", "-svg", rawtherapee_cli, profile_file | |
]) | |
assert svg_contents.strip() | |
with open(profile_svg, "w") as f: | |
f.write(svg_contents) | |
# This is usually clickable in Konsole, etc. | |
print("Written to file://{}".format(profile_svg)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment