Skip to content

Commit

Permalink
Performance measurement tools
Browse files Browse the repository at this point in the history
  • Loading branch information
bgbsww committed May 2, 2024
1 parent e4eb859 commit 6557fb3
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/Mod/Test/TestPerf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ADD COPYRIGHT HERE

Check warning on line 1 in src/Mod/Test/TestPerf.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing module docstring (missing-module-docstring)

import os

Check warning on line 3 in src/Mod/Test/TestPerf.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Unused import os (unused-import)
import sys
import unittest
import FreeCAD as App
import Part

try:
from guppy import hpy

Memtest = True
except:

Check warning on line 13 in src/Mod/Test/TestPerf.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

No exception type(s) specified (bare-except)
Memtest = False

try:
import cProfile

Pyprofile = True
except:

Check warning on line 20 in src/Mod/Test/TestPerf.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

No exception type(s) specified (bare-except)
Pyprofile = False


class PerfTestCase(unittest.TestCase):
"""
Test Case to test python syntax of all python files in FreeCAD
"""

def setUp(self):
start = -1
for index in range(0, 20):
if sys.argv[index] == "--pass":
start = index + 1
break
print("Setup", index, sys.argv)
if start != -1:
self.fileList = sys.argv[start:]
if Part.Shape().ElementMapVersion == "":
self.tnp = ""
else:
self.tnp = ".tnp"
if Memtest:
self.memfile = open(self.fileList[0] + self.tnp + ".mprofile", "w")

Check warning on line 43 in src/Mod/Test/TestPerf.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Using open without explicitly specifying an encoding (unspecified-encoding)

Check warning on line 43 in src/Mod/Test/TestPerf.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Consider using 'with' for resource-allocating operations (consider-using-with)

def testAll(self):

Check warning on line 45 in src/Mod/Test/TestPerf.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing function or method docstring (missing-function-docstring)
if Pyprofile:
pr = cProfile.Profile()
pr.enable()
start = sys.activate_stack_trampoline

Check failure on line 49 in src/Mod/Test/TestPerf.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'sys' has no 'activate_stack_trampoline' member (no-member)
start("perf") # avoid strange IDE syntax highlight error.
for fileName in self.fileList:
doc = App.openDocument(fileName)
doc.recompute() # The heart of the performance measurement.
if Memtest:
dumpdata = hpy().heap()
dumpdata.stat.dump(self.memfile)
self.memfile.flush()
App.closeDocument(doc.Name)
sys.deactivate_stack_trampoline()

Check failure on line 59 in src/Mod/Test/TestPerf.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'sys' has no 'deactivate_stack_trampoline' member (no-member)
if Pyprofile:
pr.disable()
pr.dump_stats(self.fileList[0] + self.tnp + ".cprofile")
if Memtest:
self.memfile.close()
13 changes: 13 additions & 0 deletions tools/profile/perftest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! /bin/bash

# --no-buffering
perf record -o $1.perf /home/brad/git/FreeCADtoponaming/build/bin/FreeCADCmd -t TestPerf --pass $@

# For interactive walking of the details:
#perf report -i $1.perf

# Output a total time in seconds to execute the document load and recompute
times=($(perf script -F time -i $1.perf | sed -e's/://' -e'1p;$!d')) # Grab the first and last line timestamps
totaltime=$(echo ${times[1]} - ${times[0]} | bc)
echo $totaltime

0 comments on commit 6557fb3

Please sign in to comment.