FreeCAD-Doc/localwiki/Macro_Recompute_Profiler-fr.html
2018-07-19 18:47:02 -05:00

260 lines
11 KiB
HTML

<html><head><title>Macro Recompute Profiler/fr</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link type='text/css' href='wiki.css' rel='stylesheet'></head><body><h1>Macro Recompute Profiler/fr</h1></div>
<div id="mw-content-text" lang="fr" dir="ltr" class="mw-content-ltr"><hr/><div class="mw-parser-output"><table class="fcinfobox wikitable ct" width="100%" style="float: right; width: 230px; margin-left: 10px;">
<tr>
<td class="ctTitle">
<h3><span class="mw-headline" id="Macro_Recompute_Profiler"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Text-x-python.png" class="image"><img alt="Text-x-python.png" src="32px-Text-x-python.png" width="32" height="32" srcset="/wiki/images/2/2c/Text-x-python.png 1.5x" /></a> Macro Recompute Profiler</span></h3>
</td></tr>
<tr>
<th class="ctOdd">Description
</th></tr>
<tr>
<td class="ctEven left">Mesure le temps nécessaire pour recalculer chaque objet dans un projet
</td></tr>
<tr>
<th class="ctOdd">Auteur
</th></tr>
<tr>
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=User:DeepSOIC" title="User:DeepSOIC">DeepSOIC</a>
</td></tr>
<tr>
<th class="ctOdd">Liens
</th></tr>
<tr>
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=Macros_recipes/fr" title="Macros recipes/fr">Recettes macros</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=How_to_install_macros/fr" title="How to install macros/fr">Comment installer une macro</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=Customize_Toolbars/fr" title="Customize Toolbars/fr">Comment ajouter une barre d'outils</a>
</td></tr>
<tr>
<th class="ctOdd">Version
</th></tr>
<tr>
<td class="ctEven macro-version">0.1
</td></tr>
<tr>
<th class="ctOdd">Date dernière modification
</th></tr>
<tr>
<td class="ctEven macro-date">2017-04-03
</td></tr>
<tr>
<th class="ctOdd">
</th></tr>
<tr>
<td class="ctToc"><br /><div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1"><a href="#Macro_Recompute_Profiler"><span class="tocnumber">1</span> <span class="toctext">Macro Recompute Profiler</span></a></li>
<li class="toclevel-1 tocsection-1"><a href="#Description"><span class="tocnumber">2</span> <span class="toctext">Description</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Utilisation"><span class="tocnumber">3</span> <span class="toctext">Utilisation</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#R.C3.A9sultats_Post-processing"><span class="tocnumber">4</span> <span class="toctext">Résultats Post-processing</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#Macro"><span class="tocnumber">5</span> <span class="toctext">Macro</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#FC_version"><span class="tocnumber">6</span> <span class="toctext">FC version</span></a></li>
</ul>
</div>
</td></tr>
</table>
<p><br />
</p>
<h2><span class="mw-headline" id="Description">Description</span></h2>
<p>Cette macro vous permet de localiser quelles fonctionnalités provoquent de longs retards dans les mises à jour de votre projet. cette macro chronomètre le temps nécessaire pour recalculer chaque fonction.
</p>
<h2><span class="mw-headline" id="Utilisation">Utilisation</span></h2>
<p>Cette macro requiers FreeCAD 0.17.10644 ou plus
</p><p>Sauvez la macro dans un fichier
</p><p>1. Ouvrez votre projet
</p><p>2. Faites clic droit sur votre objet dans la vue 3D, et cliquez sur "Mark to recompute"
</p><p>3. Lancez cette macro
</p><p>Une barre de progression apparait. Votre objet est recalculé, une ligne est affichée dans la vue rapport contenant le temps et le label de l'objet. Si le recalcul de l'objet n'est pas possible, la macro affiche une erreur et termine le processus.
</p>
<h2><span class="mw-headline" id="R.C3.A9sultats_Post-processing">Résultats Post-processing</span></h2>
<p>L'affichage des messages des processus lors du fonctionnement de la macro sont en général comme ceux-ci
</p>
<pre>Recomputing... (time in seconds, label)
Sketcher::setUpSketch()-T:0
Sketcher::Solve()-DogLeg-T:0
0.00999999046326Sketch - master section
0.0199999809265Clone of Sketch - master section (2D)001
Sketcher::setUpSketch()-T:0
Sketcher::Solve()-DogLeg-T:0
0.00999999046326Sketch013
Sketcher::setUpSketch()-T:0
Sketcher::Solve()-DogLeg-T:0
0.00999999046326Sketch011
0.0Clone of Sketch - master section (2D)
Sketcher::setUpSketch()-T:0
Sketcher::Solve()-DogLeg-T:0
0.0Sketch008
0.130000114441LinearArray
Sketcher::setUpSketch()-T:0
Sketcher::Solve()-DogLeg-T:0
... </pre>
<p>Les lignes affichant les résultats sont facilement séparables&#160;: elles commencent par une tabulation. Donc, si vous copiez-collez le bloc entier dans un tableur, les messages générés se retrouveront dans la colonne 1, tandis que les autres résultats se trouveront dans les colonnes 2 et 3. Donc, vous pouvez faire un tri sur la colonne 2, pour obtenir une belle table comme celle-ci&#160;:
</p>
<pre>0.59100008Slice
0.352999926Populate LinearArray with Compound
0.160000086CompoundFilter
0.138999939Cut
0.130000114LinearArray
0.108999968Fusion
0.069999933Moved CompoundFilter
0.067000151Module - spokes
0.029999971Sweep
0.019999981Clone of Sketch - master section (2D)001
0.010999918ArrayFilter003
... </pre>
<p>(Pour MS-Excel, après avoir copié le texte dans la vue rapport coller le texte dans le Bloc-notes et le recopier depuis Bloc-notes puis coller-le dans MS-Excel ... la copie dans la vue rapport ne sépare pas les colonnes car les tabulations sont inexplicablement perdues.)
</p>
<h2><span class="mw-headline" id="Macro">Macro</span></h2>
<p><b>RecomputeProfiler.FCMacro</b>
</p>
<pre>__Title__="Macro Recompute Profiler"
__Author__ = "DeepSOIC"
__Version__ = "0.1"
__Date__ = "03.04.2017"
__Comment__ = "Measures time it takes to recmpute features in a project"
__Wiki__ = "https://www.freecadweb.org/wiki/index.php?title=Macro_Recompute_Profiler"
__Help__ = "Right-click an object, and pick 'Mark to recompute', then run this macro. This will only profile recomputing the subgraph. To profile the whole project, right-click the project in tree view, and pick 'Mark to recompute', then run this macro. Results will be printed to report view."
__Status__ = "experimental"
__Requires__ = "freecad 0.17.10644"
__Communication__ = "https://forum.freecadweb.org/memberlist.php?mode=viewprofile&amp;u=3888"
import FreeCAD as App
import FreeCADGui as Gui
class ExecutionError(Exception):
pass
class CancelError(Exception):
pass
def execute(feature):
feature.recompute()
if 'Invalid' in feature.State:
raise ExecutionError("Feature '{label}' failed to recompute".format(label= feature.Label))
def msgbox(title, text):
from PySide import QtGui
mb = QtGui.QMessageBox()
mb.setIcon(mb.Icon.Information)
mb.setText(text)
mb.setWindowTitle(title)
mb.exec_()
def log(string):
App.Console.PrintWarning(string+"\n")
def getAllDependent(feat_list):
'''getAllDependent(feat_list): gets all features that depend on features in feat_list, directly or indirectly.
Returns a set. Features from feat_list are not included, unless there are interdependencies between them.'''
list_traversing_now = feat_list
set_of_deps = set()
list_of_deps = []
while len(list_traversing_now) &gt; 0:
list_to_be_traversed_next = []
for feat in list_traversing_now:
for dep in feat.InList:
if not (dep in set_of_deps):
set_of_deps.add(dep)
list_of_deps.append(dep)
list_to_be_traversed_next.append(dep)
list_traversing_now = list_to_be_traversed_next
return set_of_deps
def run():
touched = [obj for obj in App.ActiveDocument.Objects if 'Touched' in obj.State]
if len(touched) == 0:
App.ActiveDocument.RecomputesFrozen = True
msgbox("Macro Recompute Profiler", "Project was switched to suspend recomputes. Please modify an object that triggers a recompute, and run this macro again. The macro will perform a step-by-step recompute, and measure the time it takes to recompute features.")
return
log("{n} features are touched".format(n= len(touched)))
log("Generating execution order...")
to_be_executed = set.union(getAllDependent(touched), set(touched))
log("Number of features to execute: {n}".format(n= len(to_be_executed)))
exec_list = []
for obj in App.ActiveDocument.TopologicalSortedObjects[::-1]:
if obj in to_be_executed:
exec_list.append(obj)
assert(len(exec_list) == len(to_be_executed))
n = len(exec_list)
log("Execution order:")
for obj in exec_list:
log(" "+obj.Label)
import PySide
progress = PySide.QtGui.QProgressDialog(u"Preparing to recompute....", u"Abort", 0, n+1)
progress.setModal(True)
progress.show()
try:
log("Recomputing... (time in seconds, label)")
import time
for obj in exec_list:
progress.setValue(progress.value()+1)
progress.setLabelText("Recomputing {feature}...".format(feature= obj.Label))
if progress.wasCanceled():
raise CancelError()
time_start = time.time()
try:
execute(obj)
finally:
exec_time = time.time()-time_start
log("\t{time}\t{label}".format(time= exec_time, label= obj.Label))
progress.setValue(n+1)
msgbox("Macro Recompute Profiler", "Recompute completed. Results are in report view.")
for obj in exec_list:
obj.purgeTouched()
except Exception as err:
msgbox("Macro Recompute Profiler", "An error occured: {err}".format(err= str(err)))
finally:
progress.hide()
App.ActiveDocument.RecomputesFrozen = False
run() </pre>
<h2><span class="mw-headline" id="FC_version">FC version</span></h2>
<p>Cette macro nécessite FreeCAD 0.17.10644 ou plus, qui sont les versions où App.ActiveDocument.RecomputesFrozen est disponible. Elle ne fonctionnera pas avec la version v0.16.
</p><p>Cette macro a été créée avec cette version de FreeCAD:
</p>
<pre>OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.10665 (Git)
Build type: Release
Branch: master
Hash: 47847513a85ff6615774ef628230f79e37471daf
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.0.0 </pre>
<div style="clear:both"></div>
</div>
</div>
</div><div class="printfooter">
Online version: "<a dir="ltr" href="https://www.freecadweb.org/wiki/index.php?title=Macro_Recompute_Profiler/fr&amp;oldid=245023">http://www.freecadweb.org/wiki/index.php?title=Macro_Recompute_Profiler/fr&amp;oldid=245023</a>"</div>
<div id="catlinks" class="catlinks" data-mw="interface"></div><div class="visualClear"></div>
</div>
</div>
<div id="mw-navigation">
<h2>Navigation menu</h2>
</body></html>