⏲ Analyse comparative
Exécutez zi analytics pour voir les sous-commandes Zi disponibles pour les statistiques et les informations.
Plugins de profilage
zi ice atinit'zmodload zsh/zprof' \ atload'zprof | head -n 20; zmodload -u zsh/zprof'zi light z-shell/F-Sy-H| Syntaxe | Description |
|---|---|
atinit'…' | loads thezsh/zprof module, shipped with Zsh, before loading the plugin – this starts the profiling. |
atload'…' | fonctionne après le chargement du plugin - montre les résultats du profilage zprof / head, décharge zsh/zprof - ceci arrête le profilage. |
Lorsqu'il est en vigueur, seul un seul plugin, dans ce cas, z-shell/F-Sy-H, sera profilé.
Les autres plugins se dérouleront tout à fait normalement, comme lorsque les plugins sont chargés avec light - le reporting est désactivé.
Less code is being run in the background, the automatic data gathering, during loading of a plugin, for the reports and the possibility to unload the plugin will be activated and the functions will not appear in the zprof report.
- Exemple de rapport
zprof:
num calls time self name---------------------------------------------------------------------------- 1) 1 57,76 57,76 57,91% 57,76 57,76 57,91% _zsh_highlight_bind_widgets 2) 1 25,81 25,81 25,88% 25,81 25,81 25,88% compinit 3) 4 10,71 2,68 10,74% 8,71 2,18 8,73% --zi-shadow-autoload 4) 43 2,06 0,05 2,07% 2,06 0,05 2,07% -zi-add-report 5) 8 1,98 0,25 1,98% 1,98 0,25 1,98% compdef 6) 1 2,85 2,85 2,85% 0,87 0,87 0,87% -zi-compdef-replay 7) 1 0,68 0,68 0,68% 0,68 0,68 0,68% -zi-shadow-off 8) 1 0,79 0,79 0,79% 0,49 0,49 0,49% add-zsh-hook 9) 1 0,47 0,47 0,47% 0,47 0,47 0,47% -zi-shadow-on10) 3 0,34 0,11 0,35% 0,34 0,11 0,35% (anon)11) 4 10,91 2,73 10,94% 0,20 0,05 0,20% autoload12) 1 0,19 0,19 0,19% 0,19 0,19 0,19% -fast-highlight-fill-option-variables13) 1 25,98 25,98 26,05% 0,17 0,17 0,17% zicompinit14) 1 2,88 2,88 2,89% 0,03 0,03 0,03% zicdreplay15) 1 0,00 0,00 0,00% 0,00 0,00 0,00% -zi-load-plugin-----------------------------------------------------------------------------------La première colonne est le temps en millisecondes:
- Il indique le temps total passé dans une fonction.
- Par exemple,
--zi-shadow-autoloada consommé 10,71 ms du temps d'exécution,
La quatrième colonne est également un temps en millisecondes, mais elle indique le temps passé à exécuter uniquement le propre codede la fonction , elle ne compte pas le temps passé dans fonctions descendantes qui sont appelées depuis la fonction;
- Par exemple,
--zi-shadow-autoloada dépensé 8,71 ms pour exécuter uniquement son code.
- Par exemple,
The table is sorted in the self-time column.
Profilage du démarrage de .zshrc
Méthode 1
PROFILE_STARTUP=truepour activer le profilage.
Placez le snippet ci-dessous en haut de .zshrc.
PROFILE_STARTUP=falseif [[ "$PROFILE_STARTUP" == true ]]; then zmodload zsh/zprof PS4=$'%D{%M%S%.} %N:%i> ' exec 3>&2 2>$HOME/startlog.$$ setopt xtrace prompt_substfiZsh Sourceforge docs: Prompt Expansion
Placez au bas de .zshrc
if [[ "$PROFILE_STARTUP" == true ]]; then unsetopt xtrace exec 2>&3 3>&-; zprof > ~/zshprofile$(date +'%s')fiLa prochaine fois, votre .zshrc sera exécuté, il générera 2 fichiers dans le répertoire $HOME.
Méthode 2
Store multiple values to a variable:
# Définir la variabletypeset -Ag ZLOGS# Message à stockerzmsg() { ZLOGS+=( "\n[$1] : ${(M)$(( SECONDS * 1000 ))#*.?} ms" ) ; } }# Démarrer le profilagetypeset -F4 SECONDS=0# <RUN SOME FUNCTIONS TO MEASURE>zmsg "Loaded functions"# <RUN SOMETHING ELSE>zmsg "Loaded something else"# <THE FINAL CODEBLOCK HERE>zmsg "Done"Then use the $ZLOGS variable to retrieve:
❯ echo $ZLOGS[Loaded functions]: 0.0 ms[Loaded something else]: 0.0 ms[Done]: 0.1 ms