Exemple #1
0
        private void AddTelemetryConstants(ITelemetry telemetry, string methodName, double executionTime)
        {
            string lastExecTime = $"{methodName}_LastExecutionTime, ms";
            string execCounter  = $"{methodName}_ExecutionCount";

            if (telemetry.ContainsKey(lastExecTime))
            {
                telemetry[lastExecTime] = executionTime;
            }
            else
            {
                telemetry.TryAdd(lastExecTime, executionTime);
            }
            long executionCount = 1;

            if (telemetry.ContainsKey(execCounter))
            {
                executionCount         = ((long)telemetry[execCounter]) + 1;
                telemetry[execCounter] = executionCount;
            }
            else
            {
                telemetry.TryAdd(execCounter, executionCount);
            }
            AddAverageExecutionTime(telemetry, methodName, executionTime, executionCount);
            AddTotalExecutionTime(telemetry, methodName, executionTime);
            AddRequestPerSecondFromStartTelemetry(telemetry, methodName, executionCount);
            AddRequestPerSecondByTotalExecutionTime(telemetry, methodName, executionCount);
        }
Exemple #2
0
        private void AddRequestPerSecondFromStartTelemetry(ITelemetry telemetry, string methodName, long executionCount)
        {
            string startMethodTelemetry = $"{methodName}_StartTelemetry";
            string requestPerSecond     = $"{methodName}_RequestsPerSecondFromStartTelemetry";

            if (telemetry.ContainsKey(startMethodTelemetry))
            {
                double requestPerSecondCount = executionCount / (DateTime.Now - (DateTime)telemetry[startMethodTelemetry]).TotalSeconds;
                if (telemetry.ContainsKey(requestPerSecond))
                {
                    telemetry[requestPerSecond] = requestPerSecondCount;
                }
                telemetry.TryAdd(requestPerSecond, requestPerSecondCount);
            }
        }
Exemple #3
0
        private void AddRequestPerSecondByTotalExecutionTime(ITelemetry telemetry, string methodName, long executionCount)
        {
            string totalExecutionTime = $"{methodName}_TotalExecutionTime, sec";
            string requestPerSecond   = $"{methodName}_RequestsPerSecondByTotalExecutionTime";

            if (telemetry.ContainsKey(totalExecutionTime))
            {
                double totalExecutionTimeCount = (double)telemetry[totalExecutionTime];
                double requestPerSecondCount   = executionCount / (totalExecutionTimeCount != 0d? totalExecutionTimeCount : 1d);
                if (telemetry.ContainsKey(requestPerSecond))
                {
                    telemetry[requestPerSecond] = requestPerSecondCount;
                }
                else
                {
                    telemetry.TryAdd(requestPerSecond, requestPerSecondCount);
                }
            }
        }
Exemple #4
0
        private void AddTotalExecutionTime(ITelemetry telemetry, string methodName, double executionTime)
        {
            string totalExecutionTime = $"{methodName}_TotalExecutionTime, sec";

            if (telemetry.ContainsKey(totalExecutionTime))
            {
                double totalExecutionTimeCount = (double)telemetry[totalExecutionTime] + TimeSpan.FromMilliseconds(executionTime).TotalSeconds;
                telemetry[totalExecutionTime] = totalExecutionTimeCount;
            }
            else
            {
                telemetry.TryAdd(totalExecutionTime, TimeSpan.FromMilliseconds(executionTime).TotalSeconds);
            }
        }
Exemple #5
0
        private void AddAverageExecutionTime(ITelemetry telemetry, string methodName, double executionTime, long executionCount)
        {
            string avgExecTime = $"{methodName}_AverageExecutionTime, ms";

            if (telemetry.ContainsKey(avgExecTime))
            {
                var avgExecutionTime = (((double)telemetry[avgExecTime]) + executionTime) / executionCount;
                telemetry[avgExecTime] = avgExecutionTime;
            }
            else
            {
                telemetry.TryAdd(avgExecTime, executionTime);
            }
        }