private static long ExecuteStressTest(ProtocolWrapper protocol) { var timer = new Stopwatch(); int n = 0; while (n < NUM_ROUND) { for (int i = 0; i < NUM_WRITES_PER_ROUND; ++i) { int key = n * NUM_WRITES_PER_ROUND + i; object[] prms = new object[] { key, key.ToString("X") }; timer.Start(); protocol.Execute(prms); timer.Stop(); Thread.Sleep(10); } double rate = (1000.0 * NUM_WRITES_PER_ROUND) / timer.ElapsedMilliseconds; Console.WriteLine("[{0} Time: {1} ms (rate: {2})", protocol.Name, timer.ElapsedMilliseconds, rate); ++n; } return(timer.ElapsedMilliseconds); }
private static void ExportTracingInfo(ProtocolWrapper protocol, long totalTime) { Console.WriteLine("Exporting performance for {0}", protocol.Name); Guid guid = Guid.NewGuid(); string filename = protocol.Name + "-" + guid + ".csv"; using (TextWriter txtWriter = new StreamWriter(filename, false, Encoding.ASCII)) { txtWriter.WriteLine("SessionId,Activity,EventId,Source,SourceElapsed,Stage,Thread"); int count = 0; StringBuilder sb; foreach (Guid tracingId in PerformanceInstrumentation.TracingIds) { Console.WriteLine("Query tracing info {0}", tracingId); var tracingSession = protocol.QueryTracingInfo(tracingId); sb = new StringBuilder(); foreach (TracingEvent te in tracingSession.TracingEvents) { sb.AppendFormat("{0},\"{1}\",{2},{3},{4},{5},{6}", tracingSession.SessionId, te.Activity, te.EventId, te.Source, te.SourceElapsed, te.Stage, te.Thread); sb.AppendLine(); } txtWriter.Write(sb); ++count; } sb = new StringBuilder(); sb.AppendFormat("{0},\"{1}\",{2},{3},{4},{5},{6}", Guid.Empty, "Write elapsed", Guid.Empty, "", PerformanceInstrumentation.TotalWrite, "ClientWrite", 0); sb.AppendLine(); sb.AppendFormat("{0},\"{1}\",{2},{3},{4},{5},{6}", Guid.Empty, "Read elapsed", Guid.Empty, "", PerformanceInstrumentation.TotalRead, "ClientRead", 0); sb.AppendLine(); sb.AppendFormat("{0},\"{1}\",{2},{3},{4},{5},{6}", Guid.Empty, "Total elapsed", Guid.Empty, "", totalTime, "ClientElapsed", 0); sb.AppendLine(); txtWriter.Write(sb); } }