@@ -112,16 +112,20 @@ func (s *service) setupVMInstance(ctx context.Context, state *createState) error
112112 r := state .request
113113
114114 // Check KVM availability
115+ kvmStart := time .Now ()
115116 if err := lifecycle .CheckKVM (); err != nil {
116117 return err
117118 }
119+ kvmDuration := time .Since (kvmStart )
118120
119121 // Load and transform bundle
122+ bundleStart := time .Now ()
120123 b , err := transform .LoadForCreate (ctx , r .Bundle )
121124 if err != nil {
122125 return err
123126 }
124127 state .bundle = b
128+ bundleDuration := time .Since (bundleStart )
125129
126130 // Compute resource configuration
127131 resourceCfg , _ := resources .ComputeConfig (ctx , & b .Spec )
@@ -135,19 +139,23 @@ func (s *service) setupVMInstance(ctx context.Context, state *createState) error
135139 }).Debug ("VM resource configuration" )
136140
137141 // Create VM instance
142+ vmCreateStart := time .Now ()
138143 vmi , err := s .vmLifecycle .CreateVM (ctx , r .ID , r .Bundle , resourceCfg )
139144 if err != nil {
140145 return err
141146 }
142147 state .vmInstance = vmi
148+ vmCreateDuration := time .Since (vmCreateStart )
143149
144150 // Setup mounts
151+ mountStart := time .Now ()
145152 setupResult , err := s .platformMounts .Setup (ctx , vmi , r .ID , r .Rootfs )
146153 if err != nil {
147154 return err
148155 }
149156 state .mountCleanup = setupResult .Cleanup
150157 state .mounts = setupResult .Mounts
158+ mountDuration := time .Since (mountStart )
151159
152160 // Register mount cleanup
153161 state .cleanup .add ("mounts" , func (ctx context.Context ) error {
@@ -158,19 +166,29 @@ func (s *service) setupVMInstance(ctx context.Context, state *createState) error
158166 })
159167
160168 // Setup networking
169+ networkStart := time .Now ()
161170 state .netnsPath = "/var/run/netns/" + r .ID
162171 netCfg , err := s .platformNetwork .Setup (ctx , s .networkManager , vmi , r .ID , state .netnsPath )
163172 if err != nil {
164173 return err
165174 }
166175 state .netConfig = netCfg
176+ networkDuration := time .Since (networkStart )
167177
168178 // Register network cleanup
169179 state .cleanup .add ("network" , func (ctx context.Context ) error {
170180 env := & network.Environment {ID : r .ID }
171181 return s .networkManager .ReleaseNetworkResources (ctx , env )
172182 })
173183
184+ log .G (ctx ).WithFields (log.Fields {
185+ "t_kvm_check" : kvmDuration ,
186+ "t_bundle" : bundleDuration ,
187+ "t_vm_create" : vmCreateDuration ,
188+ "t_mounts" : mountDuration ,
189+ "t_network" : networkDuration ,
190+ }).Info ("setupVMInstance timings" )
191+
174192 return nil
175193}
176194
@@ -187,21 +205,30 @@ func (s *service) startVM(ctx context.Context, state *createState) error {
187205 }
188206
189207 bootTime := time .Since (prestart )
190- log .G (ctx ).WithField ("bootTime" , bootTime ).Debug ("VM boot completed" )
191208 s .stateMachine .SetIntentionalShutdown (false )
192209
193210 // Get VM client for event stream
211+ clientStart := time .Now ()
194212 vmc , err := s .vmLifecycle .Client ()
195213 if err != nil {
196214 return err
197215 }
216+ clientDuration := time .Since (clientStart )
198217
199218 // Start forwarding events
219+ eventStart := time .Now ()
200220 ns , _ := namespaces .Namespace (ctx )
201221 eventCtx := namespaces .WithNamespace (context .WithoutCancel (ctx ), ns )
202222 if err := s .startEventForwarder (eventCtx , vmc ); err != nil {
203223 return err
204224 }
225+ eventDuration := time .Since (eventStart )
226+
227+ log .G (ctx ).WithFields (log.Fields {
228+ "t_boot" : bootTime ,
229+ "t_client" : clientDuration ,
230+ "t_event" : eventDuration ,
231+ }).Info ("startVM timings" )
205232
206233 return nil
207234}
@@ -213,18 +240,23 @@ func (s *service) createTaskInVM(ctx context.Context, state *createState) (*task
213240 // Dial TTRPC client for Create RPCs.
214241 // NOTE: We intentionally do NOT cache this connection because vsock connections
215242 // can become stale between Create completing and Start being called.
243+ dialStart := time .Now ()
216244 rpcClient , err := s .vmLifecycle .DialClient (ctx )
217245 if err != nil {
218246 log .G (ctx ).WithError (err ).Error ("create: failed to dial RPC client" )
219247 return nil , err
220248 }
249+ dialDuration := time .Since (dialStart )
221250
222251 // Create bundle in VM
252+ bundleFilesStart := time .Now ()
223253 bundleFiles , err := state .bundle .Files ()
224254 if err != nil {
225255 return nil , err
226256 }
257+ bundleFilesDuration := time .Since (bundleFilesStart )
227258
259+ bundleRPCStart := time .Now ()
228260 bundleService := bundleAPI .NewTTRPCBundleClient (rpcClient )
229261 br , err := bundleService .Create (ctx , & bundleAPI.CreateRequest {
230262 ID : r .ID ,
@@ -233,8 +265,10 @@ func (s *service) createTaskInVM(ctx context.Context, state *createState) (*task
233265 if err != nil {
234266 return nil , err
235267 }
268+ bundleRPCDuration := time .Since (bundleRPCStart )
236269
237270 // Setup I/O forwarding
271+ ioSetupStart := time .Now ()
238272 state .containerIO = stdio.Stdio {
239273 Stdin : r .Stdin ,
240274 Stdout : r .Stdout ,
@@ -248,8 +282,10 @@ func (s *service) createTaskInVM(ctx context.Context, state *createState) (*task
248282 }
249283 state .guestIO = cio
250284 state .ioForwarder = ioForwarder
285+ ioSetupDuration := time .Since (ioSetupStart )
251286
252287 // Create task in VM
288+ taskRPCStart := time .Now ()
253289 vr := & taskAPI.CreateTaskRequest {
254290 ID : r .ID ,
255291 Bundle : br .Bundle ,
@@ -270,12 +306,24 @@ func (s *service) createTaskInVM(ctx context.Context, state *createState) (*task
270306 }
271307 return nil , err
272308 }
309+ taskRPCDuration := time .Since (taskRPCStart )
273310
274311 // Start the I/O forwarder AFTER guest has created the process
312+ ioStartStart := time .Now ()
275313 if err := ioForwarder .Start (ctx ); err != nil {
276314 log .G (ctx ).WithError (err ).Error ("failed to start I/O forwarder" )
277315 // Don't fail the create, just log - I/O may not work but container is created
278316 }
317+ ioStartDuration := time .Since (ioStartStart )
318+
319+ log .G (ctx ).WithFields (log.Fields {
320+ "t_dial" : dialDuration ,
321+ "t_bundle_files" : bundleFilesDuration ,
322+ "t_bundle_rpc" : bundleRPCDuration ,
323+ "t_io_setup" : ioSetupDuration ,
324+ "t_task_rpc" : taskRPCDuration ,
325+ "t_io_start" : ioStartDuration ,
326+ }).Info ("createTaskInVM timings" )
279327
280328 return resp , nil
281329}
0 commit comments