コード例 #1
0
        } // main_data

        /*
         * compute the number of bits required to flush all mp3 frames currently in
         * the buffer. This should be the same as the reservoir size. Only call this
         * routine between frames - i.e. only after all headers and data have been
         * added to the buffer by format_bitstream().
         *
         * Also compute total_bits_output = size of mp3 buffer (including frame
         * headers which may not have yet been send to the mp3 buffer) + number of
         * bits needed to flush all mp3 frames.
         *
         * total_bytes_output is the size of the mp3 output buffer if
         * lame_encode_flush_nogap() was called right now.
         */

        private int compute_flushbits(LameGlobalFlags gfp, TotalBytes total_bytes_output)
        {
            var gfc = gfp.internal_flags;
            int flushbits, remaining_headers;
            int bitsPerFrame;
            int last_ptr, first_ptr;

            first_ptr = gfc.w_ptr;
            /* first header to add to bitstream */
            last_ptr = gfc.h_ptr - 1;
            /* last header to add to bitstream */
            if (last_ptr == -1)
            {
                last_ptr = LameInternalFlags.MAX_HEADER_BUF - 1;
            }

            /* add this many bits to bitstream so we can flush all headers */
            flushbits = gfc.header[last_ptr].write_timing - totbit;
            total_bytes_output.total = flushbits;

            if (flushbits >= 0)
            {
                /* if flushbits >= 0, some headers have not yet been written */
                /* reduce flushbits by the size of the headers */
                remaining_headers = 1 + last_ptr - first_ptr;
                if (last_ptr < first_ptr)
                {
                    remaining_headers = 1 + last_ptr - first_ptr + LameInternalFlags.MAX_HEADER_BUF;
                }

                flushbits -= remaining_headers * 8 * gfc.sideinfo_len;
            }

            /*
             * finally, add some bits so that the last frame is complete these bits
             * are not necessary to decode the last frame, but some decoders will
             * ignore last frame if these bits are missing
             */
            bitsPerFrame              = getframebits(gfp);
            flushbits                += bitsPerFrame;
            total_bytes_output.total += bitsPerFrame;
            /* round up: */
            if (total_bytes_output.total % 8 != 0)
            {
                total_bytes_output.total = 1 + total_bytes_output.total / 8;
            }
            else
            {
                total_bytes_output.total = total_bytes_output.total / 8;
            }

            total_bytes_output.total += bufByteIdx + 1;

            if (flushbits < 0)
            {
                Console.Error.WriteLine("strange error flushing buffer ... \n");
            }

            return(flushbits);
        }
コード例 #2
0
        public static void Write(TextWriter writer)
        {
            TotalTime = TotalTimes.Sum();

            var elapsed = DateTime.UtcNow - Start;
            var avg     = TotalTime / TotalCount;

            Array.Sort(QuantileSample);

            writer.WriteLine("Requests/sec:    {0}", (TotalCount / (elapsed.TotalSeconds + 0.000001)).ToStdString());
            writer.WriteLine("Min time:        {0} ms", MinTime.TicksToMs());
            writer.WriteLine("Max time:        {0} ms", MaxTime.TicksToMs());
            writer.WriteLine("Avg time:        {0} ms", avg.TicksToMs());
            writer.WriteLine("Median time:     {0} ms", QuantileSample[QuantileSample.Length >> 1].TicksToMs());
            writer.WriteLine("Std deviation:   {0}", Math.Sqrt((double)QuantileSample.Sum(time => (time - avg) * (time - avg)) / (QuantileSample.Length - 1)).TicksToMs().ToStdString(suffix: "ms"));
            writer.WriteLine();
            writer.WriteLine("Time taken:      {0}", elapsed.TotalSeconds.ToStdString(suffix: "sec"));
            writer.WriteLine("Data received:   {0}", TotalBytes.ToSmartString(suffix: "B"));
            writer.WriteLine("Transfer rate:   {0}", (TotalBytes / (elapsed.TotalSeconds + 0.000001)).ToSmartString(suffix: "B/sec"));
            writer.WriteLine();

            writer.WriteLine("=== http status codes ===");
            HttpCodes.OrderBy(pair => pair.Key).ForEach(pair => writer.WriteLine("{0,10}\t{1,-10}\t{2}", pair.Value, pair.Key == 0 ? "Unknown error" : ((int)pair.Key).ToString(), ((double)pair.Value / TotalCount).ToPercentString()));
            writer.WriteLine();

            writer.WriteLine("=== quantiles ===");
            for (int i = 0; i < Quantiles.Length; i++)
            {
                var quantile = Quantiles[i];
                writer.WriteLine("{0,10}\t{1} ms", quantile.ToPercentString(), QuantileSample[Math.Max(1, quantile * QuantileSample.Length / 100) - 1].TicksToMs());
            }
            writer.WriteLine();

            long sum = 0;

            writer.WriteLine("=== times ===");
            for (int i = 0; i < Marks.Length; i++)
            {
                sum += TotalCounts[i];
                writer.WriteLine("{0,10}\t{1,-10}\t{2}", TotalCounts[i], $"<{(Marks[i] == long.MaxValue ? "inf" : Marks[i].TicksToMs().ToString())} ms", ((double)sum / TotalCount).ToPercentString());
            }
            writer.WriteLine("----------");
            writer.WriteLine("{0,10}\t{1,-10}\t{2}", TotalCount, $"<{MaxTime.TicksToMs()} ms", 1.0.ToPercentString());
        }
コード例 #3
0
 public Config() => AddColumn(new ThroughputColumn(TotalBytes, error : false), new ThroughputColumn(TotalBytes, error : true));