public void ProfileSession_Executino_Default() { var session = ProfilerSession.StartSession() .Task(c => { }); Assert.IsInstanceOf <SimpleTaskExecution>(session.Settings.Execution); }
public void TestTryEnterPolling() { DateTime startTime = DateTime.Now; // create new profiler session var profilerSession = new ProfilerSession(); // enter the polling block Assert.True(profilerSession.TryEnterPolling()); Assert.True(profilerSession.IsPolling); // verify we can't enter again Assert.False(profilerSession.TryEnterPolling()); // set polling to false to exit polling block profilerSession.IsPolling = false; bool outsideDelay = DateTime.Now.Subtract(startTime) >= profilerSession.PollingDelay; // verify we can only enter again if we're outside polling delay interval Assert.Equal(profilerSession.TryEnterPolling(), outsideDelay); // reset IsPolling in case the delay has elasped on slow machine or while debugging profilerSession.IsPolling = false; // wait for the polling delay to elapse Thread.Sleep(profilerSession.PollingDelay); // verify we can enter the polling block again Assert.True(profilerSession.TryEnterPolling()); }
public void ProfileSession_SetDuration_Runner() { var session = ProfilerSession.StartSession() .SetDuration(TimeSpan.FromSeconds(1)); session.Settings.Runner.Should().BeOfType <DurationRunner>(); }
public void TestFilterOldEvents() { // create a profiler session and get some test events var profilerSession = new ProfilerSession(); var allEvents = ProfilerTestObjects.TestProfilerEvents; var profilerEvents = ProfilerTestObjects.TestProfilerEvents; // filter all the results from the first poll // these events happened before the profiler began profilerSession.FilterOldEvents(profilerEvents); Assert.Equal(profilerEvents.Count, 0); // add a new event var newEvent = new ProfilerEvent("new event", "1/1/2017"); allEvents.Add(newEvent); // poll all events profilerEvents.AddRange(allEvents); // filtering should leave only the new event profilerSession.FilterOldEvents(profilerEvents); Assert.Equal(profilerEvents.Count, 1); Assert.True(profilerEvents[0].Equals(newEvent)); //poll again with no new events profilerEvents.AddRange(allEvents); // filter should now filter all the events since they've been seen before profilerSession.FilterOldEvents(profilerEvents); Assert.Equal(profilerEvents.Count, 0); }
public void LoadTesting_MultipleProcessors() { GlobalConfiguration.Setup(s => s.UseOptions(new Options { MaxItemsInQueue = 10, MinProcessors = 10, MaxProcessors = 50 })); var pipelineId = Guid.NewGuid().ToString(); var config = new PipelineConfiguration { Id = pipelineId, InputHandler = new HandlerNode("CustomInput"), OutputHandlers = new List <HandlerNode> { new HandlerNode("ConsoleOutput") { Filters = new List <string> { "Message -> msg", "Level -> lvl" } }, new HandlerNode(typeof(ThreadWaitHandler)) } }; var builder = new PipelineBuilder(); builder.BuildPipeline(config); var result = ProfilerSession.StartSession() .Task(ctx => { var client = new EventDispatcher(); client.Process(pipelineId, new LogMessage { Level = "Info", Message = $"Loadtesting {ctx.Get<int>(ContextKeys.Iteration)} on Thread {ctx.Get<int>(ContextKeys.ThreadId)}", Title = "Loadtest" }); }) .SetIterations(100) .SetThreads(10) .Settings(s => s.RunWarmup = false) .RunSession(); ProcessingServer.Server.WaitAll(pipelineId); // delay to ensure all threads are ended System.Threading.Tasks.Task.Delay(3000); var storage = GlobalConfiguration.Configuration.Resolve <IStorage>(); Assert.GreaterOrEqual(100 * 10, storage.Get <long>(new StorageKey(pipelineId, "ProcessedEventsMetric"))); var stats = new StatisticsApi(pipelineId); Assert.AreEqual(10, stats.GetMetricValue(MetricType.ThreadCount)); result.Trace("### LoadTesting"); }
public void ProfileSession_SetIterations_Runner() { var session = ProfilerSession.StartSession() .SetIterations(1); session.Settings.Runner.Should().BeOfType <IterationRunner>(); }
public void ProfilesSessionExtension_AfterPostExecuteTask_EnsureOrder() { string one = null; string two = null; string three = null; var session = ProfilerSession.StartSession() .PreExecute(() => three = "before") .PostExecute(() => { one = two; two = three; three = "after"; }) .Task(() => { two = three; three = "task"; }) .RunSession(); Assert.That(three == "after"); Assert.That(two == "task"); Assert.That(one == "before"); }
public void TestFilterOldEvents() { // create a profiler session and get some test events var profilerSession = new ProfilerSession(); var profilerEvents = ProfilerTestObjects.TestProfilerEvents; // filter old events shouldn't filter any new events var newProfilerEvents = profilerSession.FilterOldEvents(profilerEvents); Assert.Equal(profilerEvents.Count, newProfilerEvents.Count); // filter should now filter all the events since they've been seen before newProfilerEvents = profilerSession.FilterOldEvents(profilerEvents); Assert.Equal(newProfilerEvents.Count, 0); // add a new event var newEvent = new ProfilerEvent("new event", "1/1/2017"); profilerEvents.Add(newEvent); // verify we only have the new event when reprocessing the event list newProfilerEvents = profilerSession.FilterOldEvents(profilerEvents); Assert.Equal(newProfilerEvents.Count, 1); Assert.True(newProfilerEvents[0].Equals(newEvent)); // process whole list again and verify nothing new is available newProfilerEvents = profilerSession.FilterOldEvents(profilerEvents); Assert.Equal(newProfilerEvents.Count, 0); }
internal override void Process(ProfilerSession sess) { Tracing.PacketTrace("ALLOC: Objects relocated"); List <uint> newTable = new List <uint>(); for (int i = 0; i < sess.m_liveObjectTable.Count; i++) { uint ptr = sess.m_liveObjectTable[i]; uint j; for (j = 0; j < reloc.Length; j++) { if (ptr >= reloc[j].m_start && ptr <= reloc[j].m_end) { newTable.Add(ptr + reloc[j].m_offset); break; } } if (j == reloc.Length) { //No relocation for this object. newTable.Add(ptr); } } newTable.Sort(); sess.m_liveObjectTable = newTable; ObjectRelocation or = new ObjectRelocation(); or.m_relocationRegions = reloc; sess.AddEvent(or); }
public void ProfilesSessionExtension_AfterPostExecuteTask_MultiplePrePost() { var session = ProfilerSession.StartSession() .PreExecute(c => Assert.That(c.SessionData.Count <= 1)) .PreExecute(c => { c.Set("pre", "before"); Assert.That(c.Get <string>("post") == null); Assert.That(c.Get <string>("task") == null); }) .PostExecute(c => { Assert.That(c.SessionData.Count > 0); c.Clear(); }) .PostExecute(c => { c.Set("post", "after"); Assert.That(c.Get <string>("pre") == "before"); Assert.That(c.Get <string>("task") == "Task"); }) .Task(c => { c.Set("task", "Task"); Assert.That(c.Get <string>("pre") == "before"); Assert.That(c.Get <string>("post") == null); }) .SetIterations(10) .RunSession(); }
public void Acceptance_TrueCondition() { ProfilerSession.StartSession() .Task(Task) .Assert(pr => pr.Iterations.Count() == 1) .RunSession(); }
public void ProfilesSessionExtension_AfterPostExecuteTask_EnsureContext() { var session = ProfilerSession.StartSession() .PostExecute(c => c.Clear()) .PreExecute(c => { c.Set("pre", "before"); Assert.That(c.Get <string>("post") == null); Assert.That(c.Get <string>("task") == null); }) .Task(c => { c.Set("task", "Task"); Assert.That(c.Get <string>("pre") == "before"); Assert.That(c.Get <string>("post") == null); }) .PostExecute(c => { c.Set("post", "after"); Assert.That(c.Get <string>("pre") == "before"); Assert.That(c.Get <string>("task") == "Task"); }) .SetIterations(10) .RunSession(); }
public void ProfileSession_SetDuration() { var session = ProfilerSession.StartSession() .SetDuration(TimeSpan.FromSeconds(1)); Assert.AreEqual(TimeSpan.FromSeconds(1), session.Settings.Duration); }
public void ProfileSession_SetIterations() { var session = ProfilerSession.StartSession() .SetIterations(12); Assert.AreEqual(12, session.Settings.Iterations); }
internal override void Process(ProfilerSession sess) { Tracing.PacketTrace("ALLOC: Object allocated at address {0}", m_address); ObjectAllocation alloc = new ObjectAllocation(); alloc.m_thread = sess.m_currentThreadPID; alloc.m_address = m_address; alloc.m_size = m_size; if (!sess.m_threadCallStacks.ContainsKey(sess.m_currentThreadPID)) { sess.m_threadCallStacks.Add(sess.m_currentThreadPID, new Stack <uint>()); } alloc.m_callStack = sess.m_threadCallStacks[sess.m_currentThreadPID].ToArray(); Array.Reverse(alloc.m_callStack); sess.ResolveTypeName(m_type); //Cache type name. if (sess.m_liveObjectTable.BinarySearch(m_address) < 0) { sess.m_liveObjectTable.Add(m_address); sess.m_liveObjectTable.Sort(); } alloc.m_objectType = new ObjectType(m_type, m_rank); sess.AddEvent(alloc); }
internal override void Process(ProfilerSession sess) { m_thread = sess.m_currentThreadPID; if (m_assembly == 0) { m_assembly = sess.m_currentAssembly; } else { sess.m_currentAssembly = m_assembly; } uint md = m_assembly << Packets.Commands.Bits.AssemblyShift | m_method; Tracing.PacketTrace("CALLS: Thread {0} called function {1}", m_thread, md); if (!sess.m_threadCallStacks.ContainsKey(m_thread)) { sess.m_threadCallStacks.Add(m_thread, new Stack <uint>()); } sess.m_threadCallStacks[m_thread].Push(md); FunctionCall f = new FunctionCall(); f.m_thread = m_thread; f.m_callStack = sess.m_threadCallStacks[m_thread].ToArray(); Array.Reverse(f.m_callStack); sess.m_engine.GetMethodName(md, true); //Cache method name information while we still have a device. sess.AddEvent(f); }
public void ProfileSession_SetOptioins_After_Duration() { var session = ProfilerSession.StartSession() .SetDuration(TimeSpan.FromSeconds(1)) .SetSettings(new ProfilerSettings()); session.Settings.Duration.Should().Be(TimeSpan.FromSeconds(1)); }
public void ProfileSession_SetOptioins_After_Iterations() { var session = ProfilerSession.StartSession() .SetIterations(10) .SetSettings(new ProfilerSettings()); session.Settings.Iterations.Should().Be(10); }
public void Acceptance_FalseCondition() { Assert.Throws <MeasureMap.AssertionException>(() => ProfilerSession.StartSession() .Task(Task) .SetIterations(2) .Assert(pr => pr.Iterations.Count() == 1) .RunSession()); }
public void Acceptance_MultipleTrueCondition() { ProfilerSession.StartSession() .Task(Task) .Assert(pr => pr.Iterations.Count() == 1) .Assert(pr => pr.AverageMilliseconds > 0) .RunSession(); }
public void ProfileSession_Interval() { var session = ProfilerSession.StartSession() .Task(c => { }) .SetInterval(TimeSpan.FromSeconds(.5)); Assert.IsInstanceOf <TimedTaskExecution>(session.Settings.Execution); }
public void ProfileSession_SetDuration_TotalTime() { var result = ProfilerSession.StartSession() .SetDuration(TimeSpan.FromSeconds(1)) .Task(() => { }) .RunSession(); result.Elapsed().Should().BeGreaterThan(TimeSpan.FromSeconds(1)).And.BeLessThan(TimeSpan.FromSeconds(1.5)); }
public void ProfileSession_AverageTicks() { var result = ProfilerSession.StartSession() .Task(Task) .SetIterations(200) .RunSession(); Assert.IsTrue(result.AverageTicks > 0); }
internal override void Process(ProfilerSession sess) { Tracing.PacketTrace("CALLS: Switched to thread {0}", m_thread); ContextSwitch c = new ContextSwitch(); c.m_thread = m_thread; sess.m_currentThreadPID = m_thread; sess.AddEvent(c); }
public void ProfilerSettings_SetFromSession() { var session = ProfilerSession.StartSession() .Settings(s => { s.Iterations = 120; }); session.Settings.Iterations.Should().Be(120); }
internal override void Process(ProfilerSession sess) { Tracing.PacketTrace("GARBAGE COLLECTION BEGIN >>>"); sess.HeapBytesFree = m_freeBytes; GarbageCollectionBegin gc = new GarbageCollectionBegin(); sess.AddEvent(gc); }
internal override void Process(ProfilerSession sess) { Tracing.PacketTrace("HEAP COMPACTION BEGIN >>>"); sess.HeapBytesFree = m_freeBytes; HeapCompactionBegin hc = new HeapCompactionBegin(); sess.AddEvent(hc); }
public void ProfileSession_SetDuration_Iterations() { var cnt = 0; var result = ProfilerSession.StartSession() .SetDuration(TimeSpan.FromSeconds(1)) .Task(() => { cnt++; }) .RunSession(); result.Iterations.Count().Should().BeGreaterThan(100); }
public void Acceptance_RunSessionOnce() { int count = 0; var result = ProfilerSession.StartSession() .Task(() => count++) .RunSession(); // the task is rune once more to be able to initialize properly Assert.AreEqual(result.Iterations.Count() + 1, count); }
public void ProfilesSessionExtension_PostExecuteTask() { bool initialized = false; var session = ProfilerSession.StartSession() .PostExecute(() => initialized = true) .Task(() => Thread.Sleep(TimeSpan.FromSeconds(0.05))) .RunSession(); Assert.That(initialized); }