Exemplo n.º 1
0
        /// <summary>Returns an existing or creates a new statement metric for the index. </summary>
        /// <param name="index">of statement</param>
        /// <returns>metric to modify under read lock</returns>
        public StatementMetric GetAddMetric(int index)
        {
            StatementMetric metric = metrics[index];

            if (metric == null)
            {
                metric         = new StatementMetric(engineURI, statementNames[index]);
                metrics[index] = metric;
            }
            return(metric);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Returns an existing or creates a new statement metric for the index.
        /// </summary>
        /// <param name="index">of statement</param>
        /// <returns>metric to modify under read lock</returns>
        public StatementMetric GetAddMetric(int index)
        {
            var metric = metrics[index];
            if (metric == null) {
                metric = new StatementMetric(
                    runtimeURI,
                    statementNames[index].DeploymentId,
                    statementNames[index].Name);
                metrics[index] = metric;
            }

            return metric;
        }
Exemplo n.º 3
0
        /// <summary>Account row output. </summary>
        /// <param name="handle">statement handle</param>
        /// <param name="numIStream">num rows insert stream</param>
        /// <param name="numRStream">num rows remove stream</param>
        public void AccountOutput(StatementMetricHandle handle,
                                  int numIStream,
                                  int numRStream)
        {
            StatementMetricArray array = _groupMetrics[handle.GroupNum];

            using (array.RWLock.AcquireReadLock())
            {
                StatementMetric metric = array.GetAddMetric(handle.Index);
                metric.AddNumOutputIStream(numIStream);
                metric.AddNumOutputRStream(numRStream);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Flushes the existing metrics via array copy and swap.
        /// <para/>
        /// May report all statements (empty and non-empty slots) and thereby null values.
        /// <para/>
        /// Returns null to indicate no reports to do.
        /// </summary>
        /// <returns>metrics</returns>
        public StatementMetric[] FlushMetrics()
        {
            using (rwLock.AcquireWriteLock()) {
                bool isEmpty = false;
                if (currentLastElement == -1)
                {
                    isEmpty = true;
                }

                // first fill in the blanks if there are no reports and we report inactive statements
                if (isReportInactive)
                {
                    for (int i = 0; i <= currentLastElement; i++)
                    {
                        if (statementNames[i] != null)
                        {
                            metrics[i] = new StatementMetric(engineURI, statementNames[i]);
                        }
                    }
                }

                // remove statement ids that disappeared during the interval
                if ((currentLastElement > -1) && (removedStatementNames.IsNotEmpty()))
                {
                    for (int i = 0; i <= currentLastElement; i++)
                    {
                        if (removedStatementNames.Contains(statementNames[i]))
                        {
                            statementNames[i] = null;
                        }
                    }
                }

                // adjust last used element
                while ((currentLastElement != -1) && (statementNames[currentLastElement] == null))
                {
                    currentLastElement--;
                }

                if (isEmpty)
                {
                    return(null); // no copies made if empty collection
                }

                // perform flush
                var newMetrics = new StatementMetric[metrics.Length];
                StatementMetric[] oldMetrics = metrics;
                metrics = newMetrics;
                return(oldMetrics);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Account statement times.
        /// </summary>
        /// <param name="handle">statement handle</param>
        /// <param name="cpu">time</param>
        /// <param name="wall">time</param>
        /// <param name="numInput">The num input.</param>
        public void AccountTimes(StatementMetricHandle handle,
                                 long cpu,
                                 long wall,
                                 int numInput)
        {
            StatementMetricArray array = _groupMetrics[handle.GroupNum];

            using (array.RWLock.AcquireReadLock())
            {
                StatementMetric metric = array.GetAddMetric(handle.Index);
                metric.IncrementTime(cpu, wall);
                metric.AddNumInput(numInput);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Flushes the existing metrics via array copy and swap.
        ///     <para />
        ///     May report all statements (empty and non-empty slots) and thereby null values.
        ///     <para />
        ///     Returns null to indicate no reports to do.
        /// </summary>
        /// <returns>metrics</returns>
        public StatementMetric[] FlushMetrics()
        {
            using (RWLock.AcquireWriteLock()) {
                var isEmpty = currentLastElement == -1;

                // first fill in the blanks if there are no reports and we report inactive statements
                if (isReportInactive) {
                    for (var i = 0; i <= currentLastElement; i++) {
                        if (statementNames[i] != null) {
                            metrics[i] = new StatementMetric(
                                runtimeURI,
                                statementNames[i].DeploymentId,
                                statementNames[i].Name);
                        }
                    }
                }

                // remove statement ids that disappeared during the interval
                if (currentLastElement > -1 && !removedStatementNames.IsEmpty()) {
                    for (var i = 0; i <= currentLastElement; i++) {
                        if (removedStatementNames.Contains(statementNames[i])) {
                            statementNames[i] = null;
                        }
                    }
                }

                // adjust last used element
                while (currentLastElement != -1 && statementNames[currentLastElement] == null) {
                    currentLastElement--;
                }

                if (isEmpty) {
                    return null; // no copies made if empty collection
                }

                // perform flush
                var newMetrics = new StatementMetric[metrics.Length];
                var oldMetrics = metrics;
                metrics = newMetrics;
                return oldMetrics;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds a statement and returns the index added at.
        /// <para/>
        /// May reuse an empty slot, grow the underlying array, or append to the end.
        /// </summary>
        /// <param name="statementName">to add</param>
        /// <returns>index added to</returns>
        public int AddStatementGetIndex(String statementName)
        {
            using (rwLock.AcquireWriteLock()) {
                // see if there is room
                if ((currentLastElement + 1) < metrics.Length)
                {
                    currentLastElement++;
                    statementNames[currentLastElement] = statementName;
                    return(currentLastElement);
                }

                // no room, try to use an existing slot of a removed statement
                for (int i = 0; i < statementNames.Length; i++)
                {
                    if (statementNames[i] == null)
                    {
                        statementNames[i] = statementName;
                        if ((i + 1) > currentLastElement)
                        {
                            currentLastElement = i;
                        }
                        return(i);
                    }
                }

                // still no room, expand storage by 50%
                var newSize           = (int)(metrics.Length * 1.5);
                var newStatementNames = new String[newSize];
                var newMetrics        = new StatementMetric[newSize];
                Array.Copy(statementNames, 0, newStatementNames, 0, statementNames.Length);
                Array.Copy(metrics, 0, newMetrics, 0, metrics.Length);

                statementNames = newStatementNames;
                metrics        = newMetrics;

                currentLastElement++;
                statementNames[currentLastElement] = statementName;

                return(currentLastElement);
            }
        }
Exemplo n.º 8
0
        public void Execute(MetricExecutionContext context)
        {
            long timestamp = metricScheduleService.CurrentTime;

            StatementMetric[] metrics = context.StatementMetricRepository.ReportGroup(statementGroup);
            if (metrics != null)
            {
                for (int i = 0; i < metrics.Length; i++)
                {
                    StatementMetric metric = metrics[i];
                    if (metric != null)
                    {
                        metric.Timestamp = timestamp;
                        metricEventRouter.Route(metrics[i]);
                    }
                }
            }

            if (interval != -1)
            {
                metricScheduleService.Add(interval, this);
            }
        }
Exemplo n.º 9
0
        public void TestFlowReportActive()
        {
            var rep = new StatementMetricArray("uri", "name", 3, false, container.RWLockManager());

            var d001 = new DeploymentIdNamePair("A", "001");
            var d002 = new DeploymentIdNamePair("A", "002");
            var d003 = new DeploymentIdNamePair("A", "003");
            var d004 = new DeploymentIdNamePair("A", "004");
            var d005 = new DeploymentIdNamePair("A", "005");
            var d006 = new DeploymentIdNamePair("A", "006");
            var d007 = new DeploymentIdNamePair("A", "007");
            var d008 = new DeploymentIdNamePair("A", "008");
            var d009 = new DeploymentIdNamePair("A", "009");

            Assert.AreEqual(0, rep.SizeLastElement());

            Assert.AreEqual(0, rep.AddStatementGetIndex(d001));
            Assert.AreEqual(1, rep.SizeLastElement());

            Assert.AreEqual(1, rep.AddStatementGetIndex(d002));
            Assert.AreEqual(2, rep.AddStatementGetIndex(d003));
            Assert.AreEqual(3, rep.SizeLastElement());

            rep.RemoveStatement(d002);

            Assert.AreEqual(3, rep.AddStatementGetIndex(d004));
            Assert.AreEqual(4, rep.AddStatementGetIndex(d005));

            rep.RemoveStatement(d005);
            Assert.AreEqual(5, rep.AddStatementGetIndex(d006));

            var metrics = new StatementMetric[6];

            for (var i = 0; i < 6; i++)
            {
                metrics[i] = rep.GetAddMetric(i);
            }

            var flushed = rep.FlushMetrics();

            EPAssertionUtil.AssertSameExactOrder(metrics, flushed);

            Assert.AreEqual(1, rep.AddStatementGetIndex(d007));
            Assert.AreEqual(4, rep.AddStatementGetIndex(d008));

            rep.RemoveStatement(d001);
            rep.RemoveStatement(d003);
            rep.RemoveStatement(d004);
            rep.RemoveStatement(d006);
            rep.RemoveStatement(d007);
            Assert.AreEqual(6, rep.SizeLastElement());
            rep.RemoveStatement(d008);
            Assert.AreEqual(6, rep.SizeLastElement());

            flushed = rep.FlushMetrics();
            Assert.AreEqual(6, flushed.Length);
            Assert.AreEqual(0, rep.SizeLastElement());

            flushed = rep.FlushMetrics();
            Assert.IsNull(flushed);
            Assert.AreEqual(0, rep.SizeLastElement());

            Assert.AreEqual(0, rep.AddStatementGetIndex(d009));
            Assert.AreEqual(1, rep.SizeLastElement());

            flushed = rep.FlushMetrics();
            Assert.AreEqual(6, flushed.Length);
            for (var i = 0; i < flushed.Length; i++)
            {
                Assert.IsNull(flushed[i]);
            }
            Assert.AreEqual(1, rep.SizeLastElement());
        }
Exemplo n.º 10
0
        public void TestFlowReportActive()
        {
            var rep = new StatementMetricArray("uri", "name", 3, false);

            Assert.AreEqual(0, rep.SizeLastElement);

            Assert.AreEqual(0, rep.AddStatementGetIndex("001"));
            Assert.AreEqual(1, rep.SizeLastElement);

            Assert.AreEqual(1, rep.AddStatementGetIndex("002"));
            Assert.AreEqual(2, rep.AddStatementGetIndex("003"));
            Assert.AreEqual(3, rep.SizeLastElement);

            rep.RemoveStatement("002");

            Assert.AreEqual(3, rep.AddStatementGetIndex("004"));
            Assert.AreEqual(4, rep.AddStatementGetIndex("005"));

            rep.RemoveStatement("005");
            Assert.AreEqual(5, rep.AddStatementGetIndex("006"));

            var metrics = new StatementMetric[6];

            for (int i = 0; i < 6; i++)
            {
                metrics[i] = rep.GetAddMetric(i);
            }

            StatementMetric[] flushed = rep.FlushMetrics();
            ArrayAssertionUtil.AssertSameExactOrder(metrics, flushed);

            Assert.AreEqual(1, rep.AddStatementGetIndex("007"));
            Assert.AreEqual(4, rep.AddStatementGetIndex("008"));

            rep.RemoveStatement("001");
            rep.RemoveStatement("003");
            rep.RemoveStatement("004");
            rep.RemoveStatement("006");
            rep.RemoveStatement("007");
            Assert.AreEqual(6, rep.SizeLastElement);
            rep.RemoveStatement("008");
            Assert.AreEqual(6, rep.SizeLastElement);

            flushed = rep.FlushMetrics();
            Assert.AreEqual(6, flushed.Length);
            Assert.AreEqual(0, rep.SizeLastElement);

            flushed = rep.FlushMetrics();
            Assert.IsNull(flushed);
            Assert.AreEqual(0, rep.SizeLastElement);

            Assert.AreEqual(0, rep.AddStatementGetIndex("009"));
            Assert.AreEqual(1, rep.SizeLastElement);

            flushed = rep.FlushMetrics();
            Assert.AreEqual(6, flushed.Length);
            for (int i = 0; i < flushed.Length; i++)
            {
                Assert.IsNull(flushed[i]);
            }
            Assert.AreEqual(1, rep.SizeLastElement);
        }