fix(hints): log raw and prepared detection counts separately
2 files · +22 -1
M internal/adapters/hints/hints.go +2 -1
| @@ -222,6 +222,7 @@ func (w *worker) scan(ctx context.Context, req ports.HintScanRequest, fr frame, | |||
| 222 | 222 | t0 := time.Now() | |
| 223 | 223 | regions := tileRegions(req.Width, req.Height) | |
| 224 | 224 | dets, err := w.det.Detect(ctx, detFrame{width: req.Width, height: req.Height, stride: fr.stride, m: fr.m, regions: regions}) | |
| 225 | + | rawN := len(dets) | |
| 225 | 226 | detectDur := time.Since(t0) | |
| 226 | 227 | if err != nil { | |
| 227 | 228 | fr.m.unmap() | |
| @@ -241,7 +242,7 @@ func (w *worker) scan(ctx context.Context, req ports.HintScanRequest, fr frame, | |||
| 241 | 242 | fr.m.unmap() | |
| 242 | 243 | } | |
| 243 | 244 | log.Info().Str("output", req.Output).Float64("capture_ms", ms(captureDur)).Float64("detect_ms", ms(detectDur)). | |
| 244 | - | Int("regions", len(regions)).Int("raw_boxes", len(dets)).Int("targets", len(res.Targets)).Msg("hint scan") | |
| 245 | + | Int("regions", len(regions)).Int("raw_boxes", rawN).Int("prepared_boxes", len(dets)).Int("targets", len(res.Targets)).Msg("hint scan") | |
| 245 | 246 | return res | |
| 246 | 247 | } | |
| 247 | 248 | ||
| @@ -222,6 +222,7 @@ func (w *worker) scan(ctx context.Context, req ports.HintScanRequest, fr frame, | |||||
| 222 | t0 := time.Now() | 222 | t0 := time.Now() | ||
| 223 | regions := tileRegions(req.Width, req.Height) | 223 | regions := tileRegions(req.Width, req.Height) | ||
| 224 | dets, err := w.det.Detect(ctx, detFrame{width: req.Width, height: req.Height, stride: fr.stride, m: fr.m, regions: regions}) | 224 | dets, err := w.det.Detect(ctx, detFrame{width: req.Width, height: req.Height, stride: fr.stride, m: fr.m, regions: regions}) | ||
| 225 | + | rawN := len(dets) | |||
| 225 | detectDur := time.Since(t0) | 226 | detectDur := time.Since(t0) | ||
| 226 | if err != nil { | 227 | if err != nil { | ||
| 227 | fr.m.unmap() | 228 | fr.m.unmap() | ||
| @@ -241,7 +242,7 @@ func (w *worker) scan(ctx context.Context, req ports.HintScanRequest, fr frame, | |||||
| 241 | fr.m.unmap() | 242 | fr.m.unmap() | ||
| 242 | } | 243 | } | ||
| 243 | log.Info().Str("output", req.Output).Float64("capture_ms", ms(captureDur)).Float64("detect_ms", ms(detectDur)). | 244 | log.Info().Str("output", req.Output).Float64("capture_ms", ms(captureDur)).Float64("detect_ms", ms(detectDur)). | ||
| 244 | - | Int("regions", len(regions)).Int("raw_boxes", len(dets)).Int("targets", len(res.Targets)).Msg("hint scan") | 245 | + | Int("regions", len(regions)).Int("raw_boxes", rawN).Int("prepared_boxes", len(dets)).Int("targets", len(res.Targets)).Msg("hint scan") |
| 245 | return res | 246 | return res | ||
| 246 | } | 247 | } | ||
| 247 | 248 | ||||
M internal/adapters/hints/hints_test.go +20 -0
| @@ -1,10 +1,12 @@ | |||
| 1 | 1 | package hints | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | + | "bytes" | |
| 4 | 5 | "context" | |
| 5 | 6 | "encoding/json" | |
| 6 | 7 | "errors" | |
| 7 | 8 | "fmt" | |
| 9 | + | "github.com/bnema/zerowrap" | |
| 8 | 10 | "image" | |
| 9 | 11 | _ "image/png" | |
| 10 | 12 | "math" | |
| @@ -396,3 +398,21 @@ func TestHintLateCaptureReaped(t *testing.T) { | |||
| 396 | 398 | h.captured <- ports.CaptureDone{ID: creq.ID, Output: creq.Output} | |
| 397 | 399 | require.Eventually(t, func() bool { return len(h.captured) == 0 }, time.Second, time.Millisecond) | |
| 398 | 400 | } | |
| 401 | + | ||
| 402 | + | func TestScanLogsRawAndPreparedCounts(t *testing.T) { | |
| 403 | + | dets := make([]detection, maxWorkBoxes+5) | |
| 404 | + | for i := range dets { | |
| 405 | + | dets[i] = detection{x1: 10, y1: 10, x2: 30, y2: 30, score: .9} | |
| 406 | + | } | |
| 407 | + | det := newMockdetector(t) | |
| 408 | + | det.EXPECT().Detect(mock.Anything, mock.Anything).Return(dets, nil).Once() | |
| 409 | + | var out bytes.Buffer // scan logs synchronously on this goroutine | |
| 410 | + | ctx := zerowrap.WithCtx(context.Background(), zerowrap.New(zerowrap.Config{Level: "info", Format: "json", Output: &out})) | |
| 411 | + | w := &worker{det: det, dumpDir: "enabled"} | |
| 412 | + | w.scan(ctx, ports.HintScanRequest{Width: 100, Height: 100, Scale: 1}, frame{m: &mapping{}}, 0, ports.HintScanResult{}) | |
| 413 | + | var fields map[string]any | |
| 414 | + | require.NoError(t, json.Unmarshal(out.Bytes(), &fields)) | |
| 415 | + | require.Equal(t, float64(maxWorkBoxes+5), fields["raw_boxes"]) | |
| 416 | + | require.Equal(t, float64(maxWorkBoxes), fields["prepared_boxes"]) | |
| 417 | + | require.Equal(t, "hints", fields["component"]) | |
| 418 | + | } | |
| @@ -1,10 +1,12 @@ | |||||
| 1 | package hints | 1 | package hints | ||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | + | "bytes" | |||
| 4 | "context" | 5 | "context" | ||
| 5 | "encoding/json" | 6 | "encoding/json" | ||
| 6 | "errors" | 7 | "errors" | ||
| 7 | "fmt" | 8 | "fmt" | ||
| 9 | + | "github.com/bnema/zerowrap" | |||
| 8 | "image" | 10 | "image" | ||
| 9 | _ "image/png" | 11 | _ "image/png" | ||
| 10 | "math" | 12 | "math" | ||
| @@ -396,3 +398,21 @@ func TestHintLateCaptureReaped(t *testing.T) { | |||||
| 396 | h.captured <- ports.CaptureDone{ID: creq.ID, Output: creq.Output} | 398 | h.captured <- ports.CaptureDone{ID: creq.ID, Output: creq.Output} | ||
| 397 | require.Eventually(t, func() bool { return len(h.captured) == 0 }, time.Second, time.Millisecond) | 399 | require.Eventually(t, func() bool { return len(h.captured) == 0 }, time.Second, time.Millisecond) | ||
| 398 | } | 400 | } | ||
| 401 | + | ||||
| 402 | + | func TestScanLogsRawAndPreparedCounts(t *testing.T) { | |||
| 403 | + | dets := make([]detection, maxWorkBoxes+5) | |||
| 404 | + | for i := range dets { | |||
| 405 | + | dets[i] = detection{x1: 10, y1: 10, x2: 30, y2: 30, score: .9} | |||
| 406 | + | } | |||
| 407 | + | det := newMockdetector(t) | |||
| 408 | + | det.EXPECT().Detect(mock.Anything, mock.Anything).Return(dets, nil).Once() | |||
| 409 | + | var out bytes.Buffer // scan logs synchronously on this goroutine | |||
| 410 | + | ctx := zerowrap.WithCtx(context.Background(), zerowrap.New(zerowrap.Config{Level: "info", Format: "json", Output: &out})) | |||
| 411 | + | w := &worker{det: det, dumpDir: "enabled"} | |||
| 412 | + | w.scan(ctx, ports.HintScanRequest{Width: 100, Height: 100, Scale: 1}, frame{m: &mapping{}}, 0, ports.HintScanResult{}) | |||
| 413 | + | var fields map[string]any | |||
| 414 | + | require.NoError(t, json.Unmarshal(out.Bytes(), &fields)) | |||
| 415 | + | require.Equal(t, float64(maxWorkBoxes+5), fields["raw_boxes"]) | |||
| 416 | + | require.Equal(t, float64(maxWorkBoxes), fields["prepared_boxes"]) | |||
| 417 | + | require.Equal(t, "hints", fields["component"]) | |||
| 418 | + | } | |||