@@ -87,42 +87,45 @@ func wasiExecute(contID ContainerID, req *executor.InvocationRequest) (*executor
8787 }
8888
8989 res := & executor.InvocationResult {Success : false }
90+ t0 := time .Now ()
91+ var invocationWait time.Duration
9092 if wr .wasiType == WASI_TYPE_MODULE {
9193 // Create a new Wasi Configuration
9294 wcc , err := wr .BuildStore (contID , wf .engine , req .Handler , string (paramsBytes ))
9395 if err != nil {
94- return nil , 0 , err
96+ return nil , time . Now (). Sub ( t0 ) , err
9597 }
9698 defer wcc .Close ()
9799
98100 // Create an instance of the module
99101 instance , err := wr .linker .Instantiate (wcc .store , wr .module )
100102 if err != nil {
101- return nil , 0 , fmt .Errorf ("Failed to instantiate WASI module: %v" , err )
103+ return nil , time . Now (). Sub ( t0 ) , fmt .Errorf ("Failed to instantiate WASI module: %v" , err )
102104 }
103105
104106 // Get the _start function (entrypoint of any wasm module)
105107 start := instance .GetFunc (wcc .store , "_start" )
106108 if start == nil {
107- return nil , 0 , fmt .Errorf ("WASI Module does not have a _start function" )
109+ return nil , time . Now (). Sub ( t0 ) , fmt .Errorf ("WASI Module does not have a _start function" )
108110 }
109111
112+ invocationWait = time .Now ().Sub (t0 )
110113 // Call the _start function
111114 if _ , err := start .Call (wcc .store ); err != nil &&
112115 ! strings .Contains (err .Error (), "exit status 0" ) {
113- return nil , 0 , fmt .Errorf ("Failed to run WASI module: %v" , err )
116+ return nil , invocationWait , fmt .Errorf ("Failed to run WASI module: %v" , err )
114117 }
115118
116119 // Read stdout from the temp file
117120 stdout , err := io .ReadAll (wcc .stdout )
118121 if err != nil {
119- return nil , 0 , fmt .Errorf ("Failed to read stdout for WASI: %v" , err )
122+ return nil , invocationWait , fmt .Errorf ("Failed to read stdout for WASI: %v" , err )
120123 }
121124
122125 // Read stderr from the temp file
123126 stderr , err := io .ReadAll (wcc .stderr )
124127 if err != nil {
125- return nil , 0 , fmt .Errorf ("Failed to read stderr for WASI: %v" , err )
128+ return nil , invocationWait , fmt .Errorf ("Failed to read stderr for WASI: %v" , err )
126129 }
127130
128131 // Populate result
@@ -143,6 +146,9 @@ func wasiExecute(contID ContainerID, req *executor.InvocationRequest) (*executor
143146 var stdoutBuffer , stderrBuffer bytes.Buffer
144147 execCmd .Stdout = & stdoutBuffer
145148 execCmd .Stderr = & stderrBuffer
149+
150+ invocationWait = time .Now ().Sub (t0 )
151+
146152 // Execute wasmtime CLI
147153 err := execCmd .Run ()
148154 if err != nil {
@@ -169,7 +175,7 @@ func wasiExecute(contID ContainerID, req *executor.InvocationRequest) (*executor
169175 }
170176 }
171177
172- return res , 0 , nil
178+ return res , invocationWait , nil
173179}
174180
175181// Execute interacts with the Executor running in the container to invoke the
0 commit comments