(runID, sessionID, containerID, profile string)
| 550 | } |
| 551 | |
| 552 | func (s Service) setContainerCPUProfile(runID, sessionID, containerID, profile string) error { |
| 553 | weight, normalized, err := cpuWeightForProfile(profile) |
| 554 | if err != nil { |
| 555 | return err |
| 556 | } |
| 557 | start := time.Now() |
| 558 | if s.Driver == nil { |
| 559 | return fmt.Errorf("runtime driver is required") |
| 560 | } |
| 561 | if err := s.Driver.SetCPUWeight(context.Background(), containerID, weight); err != nil { |
| 562 | return err |
| 563 | } |
| 564 | switchMS := time.Since(start).Milliseconds() |
| 565 | now := time.Now().UTC().Format(time.RFC3339Nano) |
| 566 | _, _ = s.DB.Exec(`INSERT INTO events (id, run_id, session_id, source, event_type, payload, created_at) |
| 567 | VALUES (?, ?, ?, 'control_plane', 'cpu_weight_set', ?, ?)`, |
| 568 | ids.New("evt"), runID, sessionID, fmt.Sprintf(`{"profile":%q,"cpu_weight":%d,"switch_ms":%d}`, normalized, weight, switchMS), now) |
| 569 | return nil |
| 570 | } |
| 571 | |
| 572 | func (s Service) lockWrites() { |
| 573 | if s.WriteMu != nil { |
no test coverage detected