]> git.sesse.net Git - nageru/commitdiff
Add MJPEG export metrics.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 14 Feb 2019 23:10:06 +0000 (00:10 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 14 Feb 2019 23:10:06 +0000 (00:10 +0100)
nageru/mjpeg_encoder.cpp
nageru/mjpeg_encoder.h

index f920bf5508e00fc0ba490ebdf4a18aea07bf0099..8192be4cfa8e62e8fa6430ad211d740baaba393c 100644 (file)
@@ -16,6 +16,7 @@ extern "C" {
 #include "flags.h"
 #include "shared/httpd.h"
 #include "shared/memcpy_interleaved.h"
+#include "shared/metrics.h"
 #include "pbo_frame_allocator.h"
 #include "shared/timebase.h"
 #include "va_display_with_cleanup.h"
@@ -177,12 +178,26 @@ MJPEGEncoder::MJPEGEncoder(HTTPD *httpd, const string &va_display)
                va_receiver_thread = thread(&MJPEGEncoder::va_receiver_thread_func, this);
        }
 
+       global_metrics.add("mjpeg_frames", {{ "status", "dropped" }, { "reason", "zero_size" }}, &metric_mjpeg_frames_zero_size_dropped);
+       global_metrics.add("mjpeg_frames", {{ "status", "dropped" }, { "reason", "interlaced" }}, &metric_mjpeg_frames_interlaced_dropped);
+       global_metrics.add("mjpeg_frames", {{ "status", "dropped" }, { "reason", "unsupported_pixel_format" }}, &metric_mjpeg_frames_unsupported_pixel_format_dropped);
+       global_metrics.add("mjpeg_frames", {{ "status", "dropped" }, { "reason", "oversized" }}, &metric_mjpeg_frames_oversized_dropped);
+       global_metrics.add("mjpeg_frames", {{ "status", "dropped" }, { "reason", "overrun" }}, &metric_mjpeg_overrun_dropped);
+       global_metrics.add("mjpeg_frames", {{ "status", "submitted" }}, &metric_mjpeg_overrun_submitted);
+
        running = true;
 }
 
 MJPEGEncoder::~MJPEGEncoder()
 {
        av_free(avctx->pb->buffer);
+
+       global_metrics.remove("mjpeg_frames", {{ "status", "dropped" }, { "reason", "zero_size" }});
+       global_metrics.remove("mjpeg_frames", {{ "status", "dropped" }, { "reason", "interlaced" }});
+       global_metrics.remove("mjpeg_frames", {{ "status", "dropped" }, { "reason", "unsupported_pixel_format" }});
+       global_metrics.remove("mjpeg_frames", {{ "status", "dropped" }, { "reason", "oversized" }});
+       global_metrics.remove("mjpeg_frames", {{ "status", "dropped" }, { "reason", "overrun" }});
+       global_metrics.remove("mjpeg_frames", {{ "status", "submitted" }});
 }
 
 void MJPEGEncoder::stop()
@@ -247,27 +262,33 @@ void MJPEGEncoder::upload_frame(int64_t pts, unsigned card_index, RefCountedFram
 {
        PBOFrameAllocator::Userdata *userdata = (PBOFrameAllocator::Userdata *)frame->userdata;
        if (video_format.width == 0 || video_format.height == 0) {
+               ++metric_mjpeg_frames_zero_size_dropped;
                return;
        }
        if (video_format.interlaced) {
                fprintf(stderr, "Card %u: Ignoring JPEG encoding for interlaced frame\n", card_index);
+               ++metric_mjpeg_frames_interlaced_dropped;
                return;
        }
        if (userdata->pixel_format != PixelFormat_8BitYCbCr ||
            !frame->interleaved) {
                fprintf(stderr, "Card %u: Ignoring JPEG encoding for unsupported pixel format\n", card_index);
+               ++metric_mjpeg_frames_unsupported_pixel_format_dropped;
                return;
        }
        if (video_format.width > 4096 || video_format.height > 4096) {
                fprintf(stderr, "Card %u: Ignoring JPEG encoding for oversized frame\n", card_index);
+               ++metric_mjpeg_frames_oversized_dropped;
                return;
        }
 
        lock_guard<mutex> lock(mu);
        if (frames_to_be_encoded.size() + frames_encoding.size() > 50) {
                fprintf(stderr, "WARNING: MJPEG encoding doesn't keep up, discarding frame.\n");
+               ++metric_mjpeg_overrun_dropped;
                return;
        }
+       ++metric_mjpeg_overrun_submitted;
        frames_to_be_encoded.push(QueuedFrame{ pts, card_index, frame, video_format, y_offset, cbcr_offset });
        any_frames_to_be_encoded.notify_all();
 }
index 3630d9f26a6f94048b0c3df0b9a9593955948c1a..6610e1315a7d26ee41d024d48caca65f60a67377 100644 (file)
@@ -146,6 +146,13 @@ private:
        static std::unique_ptr<VADisplayWithCleanup> try_open_va(const std::string &va_display, std::string *error, VAConfigID *config_id);
 
        uint8_t *tmp_y, *tmp_cbcr, *tmp_cb, *tmp_cr;  // Private to the encoder thread. Used by the libjpeg backend only.
+
+       std::atomic<int64_t> metric_mjpeg_frames_zero_size_dropped{0};
+       std::atomic<int64_t> metric_mjpeg_frames_interlaced_dropped{0};
+       std::atomic<int64_t> metric_mjpeg_frames_unsupported_pixel_format_dropped{0};
+       std::atomic<int64_t> metric_mjpeg_frames_oversized_dropped{0};
+       std::atomic<int64_t> metric_mjpeg_overrun_dropped{0};
+       std::atomic<int64_t> metric_mjpeg_overrun_submitted{0};
 };
 
 #endif  // !defined(_MJPEG_ENCODER_H)