Beispiel #1
0
        /**
         * @param myTotal
         * @param string
         * @return
         */
        private static String Format(String name, RunningSample s, String type)
        {
            StringBuilder tmp = new StringBuilder(20);  // for intermediate use
            StringBuilder sb  = new StringBuilder(100); // output line buffer

            sb.Append(name);
            sb.Append(" ");
            sb.Append(type);
            sb.Append(" ");
            sb.Append(s.getNumSamples());
            sb.Append(" in ");
            long elapsed    = s.getElapsed();
            long elapsedSec = (elapsed + 500) / 1000; // rounded seconds

            if (elapsedSec > 100 ||                   // No point displaying decimals (less than 1% error)
                (elapsed - elapsedSec * 1000) < 50    // decimal would be zero
                )
            {
                sb.Append(elapsedSec);
            }
            else
            {
                double elapsedSecf = elapsed / 1000.0d; // fractional seconds
                sb.Append(elapsedSecf);                 // This will round
            }
            sb.Append("s = ");
            if (elapsed > 0)
            {
                sb.Append(s.getRate());
            }
            else
            {
                sb.Append("******");// Rate is effectively infinite
            }
            sb.Append("/s Avg: ");
            sb.Append(s.getAverage());
            sb.Append(" Min: ");
            sb.Append(s.getMin());
            sb.Append(" Max: ");
            sb.Append(s.getMax());
            sb.Append(" Err: ");
            sb.Append(s.getErrorCount());
            sb.Append(" (");
            sb.Append(s.getErrorPercentageString());
            sb.Append(")");
            if ("+".Equals(type))
            {
                ThreadCounts tc = NetMeterContextManager.GetThreadCounts();
                sb.Append(" Active: ");
                sb.Append(tc.activeThreads);
                sb.Append(" Started: ");
                sb.Append(tc.startedThreads);
                sb.Append(" Finished: ");
                sb.Append(tc.finishedThreads);
            }
            return(sb.ToString());
        }
Beispiel #2
0
        /**
         * Accumulates the sample in two SampleResult objects - one for running
         * totals, and the other for deltas.
         *
         * @see org.apache.jmeter.samplers.SampleListener#sampleOccurred(org.apache.jmeter.samplers.SampleEvent)
         */
        public void ExecutionOccurred(ExecutionEvent e)
        {
            ExecuteResult s = e.getResult();

            Int64 now = DateTime.Now.Ticks;// in seconds

            RunningSample myDelta   = null;
            RunningSample myTotal   = null;
            Boolean       reportNow = false;

            /*
             * Have we reached the reporting boundary?
             * Need to allow for a margin of error, otherwise can miss the slot.
             * Also need to check we've not hit the window already
             */
            Monitor.Enter(myTotals);
            try
            {
                if (s != null)
                {
                    myTotals.delta.AddSample(s);
                }

                if ((now > myTotals.last + INTERVAL_WINDOW) && (now % INTERVAL <= INTERVAL_WINDOW))
                {
                    reportNow = true;

                    // copy the data to minimise the synch time
                    myDelta = new RunningSample(myTotals.delta);
                    myTotals.MoveDelta();
                    myTotal = new RunningSample(myTotals.total);

                    myTotals.last = now; // stop double-reporting
                }
            }
            finally
            {
                Monitor.Exit(myTotals);
            }

            if (reportNow)
            {
                String str;
                str = Format(myName, myDelta, "+");
                if (TOLOG)
                {
                    log.Info(str);
                }
                if (TOCONSOLE)
                {
                    System.Console.WriteLine(str);
                }

                // Only if we have updated them
                if (myTotal != null && myDelta != null && myTotal.getNumSamples() != myDelta.getNumSamples())
                {
                    str = Format(myName, myTotal, "=");
                    if (TOLOG)
                    {
                        log.Info(str);
                    }
                    if (TOCONSOLE)
                    {
                        System.Console.WriteLine(str);
                    }
                }
            }
        }