Ejemplo n.º 1
0
        private void BuildReport()
        {
            if (!_logger.IsInfo)
            {
                return;
            }

            Swap();

            if (!_previousStats.Any())
            {
                return;
            }

            const string reportHeader = "method                                  | " +
                                        "successes | " +
                                        " avg time | " +
                                        " max time | " +
                                        "   errors | " +
                                        " avg time | " +
                                        " max time |";

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("***** JSON RPC report *****");
            string divider = new string(Enumerable.Repeat('-', reportHeader.Length).ToArray());

            stringBuilder.AppendLine(divider);
            stringBuilder.AppendLine(reportHeader);
            stringBuilder.AppendLine(divider);
            MethodStats total = new MethodStats();

            foreach (KeyValuePair <string, MethodStats> methodStats in _previousStats.OrderBy(kv => kv.Key))
            {
                total.AvgTimeOfSuccesses = total.Successes + methodStats.Value.Successes == 0
                    ? 0
                    : (total.AvgTimeOfSuccesses * total.Successes + methodStats.Value.Successes * methodStats.Value.AvgTimeOfSuccesses)
                                           / (total.Successes + methodStats.Value.Successes);
                total.AvgTimeOfErrors = total.Errors + methodStats.Value.Errors == 0
                    ? 0
                    : (total.AvgTimeOfErrors * total.Errors + methodStats.Value.Errors * methodStats.Value.AvgTimeOfErrors)
                                        / (total.Errors + methodStats.Value.Errors);
                total.Successes       += methodStats.Value.Successes;
                total.Errors          += methodStats.Value.Errors;
                total.MaxTimeOfSuccess = Math.Max(total.MaxTimeOfSuccess, methodStats.Value.MaxTimeOfSuccess);
                total.MaxTimeOfError   = Math.Max(total.MaxTimeOfError, methodStats.Value.MaxTimeOfError);
                stringBuilder.AppendLine(PrepareReportLine(methodStats.Key, methodStats.Value));
            }

            stringBuilder.AppendLine(divider);
            stringBuilder.AppendLine(PrepareReportLine("TOTAL", total));
            stringBuilder.AppendLine(divider);

            _logger.Info(stringBuilder.ToString());
            _previousStats.Clear();
        }
Ejemplo n.º 2
0
 public static void AddDuration(long duration,
                                [CallerMemberName] string methodName = "Unknown Method")
 {
     if (!_countLog.ContainsKey(methodName))
     {
         var stats = new MethodStats(methodName);
         stats.AddCall(duration);
         _countLog.Add(methodName, stats);
     }
     else
     {
         var stats = _countLog[methodName];
         stats.AddCall(duration);
     }
 }
Ejemplo n.º 3
0
 public ClrProfilerMethodSizeStackSource(string clrProfilerFileName)
 {
     m_fileName          = clrProfilerFileName;
     m_clrProfiler       = new ClrProfilerParser();
     m_calls             = new GrowableArray <int>(1000000);
     m_clrProfiler.Call += delegate(ProfilerStackTraceID stackId, uint threadId)
     {
         m_calls.Add((int)stackId);
         var method = m_clrProfiler.Method(stackId);
         var stats  = (MethodStats)method.UserData;
         if (stats == null)
         {
             m_totalMethodSize += (int)method.size;
             m_totalMethodCount++;
             method.UserData = stats = new MethodStats();
             // Debug.WriteLine(string.Format("METHOD Size {1,6}: {0}", method.name, method.size));
         }
         stats.count++;
     };
     m_clrProfiler.ReadFile(m_fileName);
     // Debug.WriteLine(string.Format("MethodSize {0} MethodCount {1} callCount {2}", m_totalMethodSize, m_totalMethodCount, m_calls.Count));
 }
Ejemplo n.º 4
0
 public Method(string name, MethodStats methodStats)
 {
     _name = name;
     _methodStats = methodStats;
 }