public void ComputeActualConcurrency() { List <PipSpan> spans = new List <PipSpan>(); LongestRunningPips = GetSortedPips(20, true, n => true, n => Durations[n]); ShortestRunningProcesses = GetSortedPips(20, false, n => PipTypes[n] == PipType.Process, n => Durations[n]); foreach (var node in DataflowGraph.Nodes) { Interlocked.Increment(ref PipTypeCounts[(int)PipTypes[node]]); var startTime = StartTimes[node]; if (PipTypes[node] == PipType.Process) { spans.Add(new PipSpan() { Id = node, StartTime = startTime - MinStartTime, Duration = Durations[node] }); } } spans.Sort(new ComparerBuilder <PipSpan>().CompareByAfter(s => s.StartTime).CompareByAfter(s => s.Duration)); Spans = spans; ConcurrentDenseIndex <int> concurrencyIndex = new ConcurrentDenseIndex <int>(false); ConcurrentDenseIndex <int> concurrencyCount = new ConcurrentDenseIndex <int>(false); for (int i = 0; i < spans.Count; i++) { PipSpan s = spans[i]; ulong endTime = s.EndTime; for (int j = i; j < spans.Count; j++) { PipSpan t = spans[j]; if (t.StartTime <= s.EndTime) { int value = concurrencyIndex[(uint)j] + 1; concurrencyIndex[(uint)j] = value; Max(ref ActualConcurrency, value); } else { break; } } var c = concurrencyIndex[(uint)i]; concurrencyCount[(uint)c] = concurrencyCount[(uint)c] + 1; } }
public void AddExecution(NodeId pip, ulong minimumStartTime, ulong duration, SimulationResult result, SortedSet <PipAndPriority> pips) { var execution = new PipSpan() { Id = pip, StartTime = Math.Max(EndTime, minimumStartTime), Duration = duration, Thread = Id, }; Executions.Add(execution); EndTime = execution.StartTime + duration; ActiveTime += duration; result.EndTimes[pip] = EndTime; result.CompletePip(execution.StartTime, pip, pips); }
private static void CreateSpanImage(string path, List <PipSpan> spans, ulong totalTime, int threadCount) { Bitmap bitmap = new Bitmap(1200, 800); Graphics graphics = Graphics.FromImage(bitmap); int width = 1000; int height = 600; graphics.FillRectangle(Brushes.Gray, 100, 100, width, height); Pen pen = new Pen(Brushes.Green, 1); int bottomY = 700; ulong currentTime = 0; ulong timeInterval = totalTime / (ulong)width; ConcurrentDenseIndex <double> timeSliceConcurrencies = new ConcurrentDenseIndex <double>(false); ConcurrentDenseIndex <int> minConcurrencies = new ConcurrentDenseIndex <int>(false); ConcurrentDenseIndex <int> maxConcurrencies = new ConcurrentDenseIndex <int>(false); ConcurrentDenseIndex <int> concurrencyIndex = new ConcurrentDenseIndex <int>(false); for (int i = 0; i < spans.Count; i++) { PipSpan s = spans[i]; uint firstTimeSlice = (uint)(s.StartTime / timeInterval); uint lastTimeSlice = (uint)(s.EndTime / timeInterval); ((uint)width).Min(ref lastTimeSlice); uint firstFullTimeSlice = firstTimeSlice + 1; uint lastFullTimeSlice = lastTimeSlice - 1; for (uint sliceIndex = firstTimeSlice; sliceIndex <= lastTimeSlice; sliceIndex++) { ulong sliceStart = sliceIndex * timeInterval; ulong sliceEnd = sliceStart + timeInterval; s.StartTime.Max(ref sliceStart); s.EndTime.Min(ref sliceEnd); double concurrency = ((double)(sliceEnd - sliceStart)) / (double)timeInterval; timeSliceConcurrencies[sliceIndex] = timeSliceConcurrencies[sliceIndex] + concurrency; } } int lastConcurrency = 0; for (int i = 0; i < width; i++) { int x = 100 + i; Point bottom = new Point(x, bottomY); int concurrency = (int)lastConcurrency; int concurrencyHeight = (int)(timeSliceConcurrencies[(uint)i] * height / threadCount); var top = bottom; top.Offset(0, -concurrencyHeight); graphics.DrawLine(pen, top, bottom); currentTime += timeInterval; } bitmap.Save(path, ImageFormat.Png); }