17.12.2012 Views

Programmation PYTHON - Zenk - Security - Repository

Programmation PYTHON - Zenk - Security - Repository

Programmation PYTHON - Zenk - Security - Repository

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

434<br />

Techniques avancées<br />

QUATRIÈME PARTIE<br />

Utilisation de profile<br />

$ python -m "profile" --help<br />

Usage: profile.py [-o output_file_path] [-s sort] scriptfile [arg] ...<br />

Options:<br />

-h, --help show this help message and exit<br />

-o OUTFILE, --outfile=OUTFILE<br />

Save stats to <br />

-s SORT, --sort=SORT Sort order when printing to stdout, based on<br />

pstats.Stats class<br />

$ python -m "profile" -s time<br />

listbench.py<br />

155 function calls in 30.830 CPU seconds<br />

Ordered by: internal time<br />

ncalls tottime percall cumtime percall filename:lineno(function)<br />

1 16.760 16.760 17.120 17.120 listbench.py:19(fonc2)<br />

1 11.160 11.160 13.000 13.000 listbench.py:14(fonc1)<br />

3 1.250 0.417 1.250 0.417 :0(range)<br />

2 1.030 0.515 1.030 0.515 :0(join)<br />

1 0.590 0.590 30.810 30.810 listbench.py:2(?)<br />

2 0.020 0.010 30.140 15.070 listbench.py:7(duree)<br />

1 0.020 0.020 0.020 0.020 :0(setprofile)<br />

[...]<br />

Le module hotshot<br />

Un nouveau module plus rapide et complet a été introduit à la version 2.2 : hotshot.<br />

Les fonctionnalités de hotshot sont similaires au module profile, mais réduisent<br />

l’impact sur les performances introduites par l’outillage mis en place pour le<br />

profiling : le code est majoritairement écrit en C.<br />

hotshot définit une unique classe Profile, permettant de créer des instances de profiler,<br />

ainsi qu’une fonction hotshot.stats.load(logfile), qui permet de charger et<br />

renvoyer les résultats du profiler dans un objet de type Stats, du module pstats.<br />

class Profile(logfile[, lineevents[, linetimings]])<br />

Créer une instance de profiler se fait en fournissant un nom de fichier logfile, utilisé<br />

pour stocker les données récoltées par le profiling.<br />

lineevents détermine la granularité du profiler, à savoir si seuls les appels de<br />

méthodes ou fonctions sont enregistrées (0 ou non défini) ou si toutes les lignes de<br />

code sont observées (1).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!