Bonjour !

J'ai un script bash à optimiser, il s’exécute en 200 ms, il faudrait qu'il descende en dessous des 50 ms . Quand je parle de l'exécution, je veux parler d'un parcours total de la boucle While)

J'ai beaucoup de mal à l'optimiser, connaissant mal ce langage.. Je sais par exemple qu'il faut limiter les appels extérieurs, mais difficile à mettre en pratique ^^

Voici le code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
#
##### take_screenshot #####
#
# Permet de capture l'image d'un display
#
# Param 1 = Display
# Param 2 = Token
#
*
display=$1
token=$2
*
counter=0
is_closed=0
errorCounter=0
*
import -display :$display -window "$token" ../tmp/$token.png > /dev/null
cp ../tmp/$token.png ../tmp/import_$token.png
cp ../tmp/$token.png ../tmp/import_$token"_tmp_1.png"
*
while [ $is_closed -eq 0 ]; do
*
#################################
#
# CAPTURE_FENETRE_PRINCIPALE
#
#################################
*
**#TEST DE FERMETURE DE LA FENETRE
**retour=$(DISPLAY=:$display xdotool search --name "$token")
*
**if [ $retour -z ]
**then
****if [ $errorCounter -ge 20 ]
****then
*******is_closed=1
*******./log.sh "log_flux.txt" "Fermeture brutale de $token survenue" &
****fi*
****errorCounter=$(($errorCounter+1))
**else
****errorCounter=0
**fi
**#FIN DE TEST
*
**info=$(xwininfo -name "$token" -display :$display)
**width_actu=$(echo $info | awk {'print $25'})
**height_actu=$(echo $info | awk {'print $27'})
*
**offsetX=$(echo $info | awk {'print $11'})
**offsetY=$(echo $info | awk {'print $15'})
*
**import -display :$display -screen -window root -crop $width_actu"x"$height_actu"+"$offsetX"+"$offsetY ../tmp/$token.png
*
**cp ../tmp/$token.png ../tmp/import_$token.png &
**cp ../tmp/$token.png ../tmp/import_$token"_tmp_2.png" &
*
#################################
#
# CAPTURE_MULTI_FENETRAGE
#
#################################
*
***window_list=$(./get_all_window.sh $token)
*
***for word in $window_list
***do
******if [ "$word" != "$token" ]
******then
*****#Si l'image root n'existe pas, on la créer
*****if [ test -f ../tmp/import_$word"_tmp_1.png" ]
*****then
********import -display :$display -window "$word" ../tmp/$word.png > /dev/null
********cp ../tmp/$word.png ../tmp/import_$word.png
********cp ../tmp/$word.png ../tmp/import_$word"_tmp_1.png"
*****fi
*
*****info=$(xwininfo -name "$word" -display :$display)
*****width_actu_child=$(echo $info | awk {'print $25'})
*****height_actu_child=$(echo $info | awk {'print $27'})
*
*****offsetX_child=$(echo $info | awk {'print $11'})
*****offsetY_child=$(echo $info | awk {'print $15'})
*
*****import -display :$display -window root -crop $width_actu_child"x"$height_actu_child"+"$offsetX_child"+"$offsetY_child ../tmp/$word.png > /dev/null
*********cp ../tmp/$word.png ../tmp/import_$word.png &
*****cp ../tmp/$word.png ../tmp/import_$word"_tmp_2.png" &
******fi
***done
done
Quelques conseils d'optimisations serait les bienvenues !

En vous remerciant d'avance,

Bonne journée