private void OnTimeout(object state) { try { mTimer.Change(-1, -1); long timeout = EventCenter.Watch.ElapsedMilliseconds; var items = mAwaiterItemGroup.GetTimeouts(timeout); if (items.Count > 0) { for (int i = 0; i < items.Count; i++) { TimeoutWork tw = new TimeoutWork(); tw.Awaiter = items[i]; EventOutput output = new EventOutput(); output.ID = tw.Awaiter.ID; NextQueueGroup.Enqueue(tw); } } } catch { } finally { mTimer.Change(1000, 1000); } }
public bool Completed(OutputAwaiter item, EventOutput data) { if (item.Completed(data)) { return(true); } return(false); }
/// <summary> /// Exports the data to a file. /// </summary> /// <param name="source">The source to export.</param> /// <param name="destination">The destination.</param> public void ExportToFile(EventOutput source, string destination) { using (var fs = File.Create(destination)) using (var sw = new StreamWriter(fs)) { this.Export(source, sw); } }
/// <summary> /// Invoked when an analysis needs to be performed. /// </summary> protected override EventOutput OnAnalyze() { // Here we will store our results var output = new EventOutput(this.Process.Name); // Process every frame foreach(var frame in this.Frames) { // Build some shortcuts var core = frame.Core; // Get corresponding hardware counters var cn = frame.HwCounters; // Process every thread within this frame foreach (var thread in frame.Threads) { // Get the multiplier for that thread var multiplier = frame.GetOnCoreRatio(thread); // Get the number of demand zero faults. var dzf = frame.PageFaults .Where(pf => pf.Type == PageFaultType.Minor) .Where(pf => pf.Thread == thread.Tid && pf.Process == thread.Pid) .Count(); // Get the number of har" page faults. var hpf = frame.PageFaults .Where(pf => pf.Type == PageFaultType.Major) .Where(pf => pf.Thread == thread.Tid && pf.Process == thread.Pid) .Count(); // Get the number of cycles elapsed var cycles = Math.Round(multiplier * cn.Cycles); output.Add("cycles", frame, thread, cycles); output.Add("time", frame, thread, multiplier); output.Add("l1miss", frame, thread, Math.Round(multiplier * cn.L1Misses)); output.Add("l2miss", frame, thread, Math.Round(multiplier * cn.L2Misses)); output.Add("l3miss", frame, thread, Math.Round(multiplier * cn.L3Misses)); output.Add("tlbmiss", frame, thread, Math.Round(multiplier * cn.TLBMisses)); output.Add("dzf", frame, thread, dzf); output.Add("hpf", frame, thread, hpf); output.Add("ipc", frame, thread, cn.IPC); output.Add("tlbperf", frame, thread, cn.TLBClock); output.Add("l1perf", frame, thread, (multiplier * cn.L2Hits * 10) / cycles); output.Add("l2perf", frame, thread, cn.L2Clock); output.Add("l3perf", frame, thread, cn.L3Clock); output.Add("hpfperf", frame, thread, (hpf * 1050) / cycles); // "page fault and return is about 1050 cycles" - Linus Torvalds } } // Return the results return output; }
public bool Completed(EventOutput data) { if (System.Threading.Interlocked.CompareExchange(ref mFree, 1, 0) == 0) { completionSource.TrySetResult(data); return(true); } return(false); }
private void MfswL_EventHandler(object sender, EventOutput e) { Control.CheckForIllegalCrossThreadCalls = false; if (e.OldChangedFullPath != null) { listBox2.Items.Add(e.Event + " - " + e.ChangedFullPath + " - " + e.OldChangedFullPath + " - " + DateTime.Now); } else { listBox2.Items.Add(e.Event + " - " + e.ChangedFullPath + " - " + DateTime.Now); } Control.CheckForIllegalCrossThreadCalls = true; }
/// <summary> /// Invoked when an analysis needs to be performed. /// </summary> protected override EventOutput OnAnalyze() { // Here we will store our results var output = new EventOutput(this.Process.Name); // This is for mapping pointers to a lock number var locks = new Dictionary<long, int>(); var locki = 0; // Export every event foreach (var ev in this.LockAcquisitions) { if (!locks.ContainsKey(ev.Lock)) locks[ev.Lock] = ++locki; output.Add(ev.Type.ToString().ToLowerInvariant(), this.Process.Name, "", ev.TimeStamp, locks[ev.Lock], ev.ThreadId, ev.ProcessId, ev.ProcessorNumber, 0); } // Return the results return output; }
/// <summary> /// Invoked when an analysis needs to be performed. /// </summary> protected override EventOutput OnAnalyze() { // Here we will store our results var output = new EventOutput(this.Process.Name); var processes = this.TraceLog.Processes .Select(p => new { Name = p.Name, Id = p.ProcessID }) .ToArray(); // Get the context switches var contextSwitches = this.Switches .Where(e => e.TimeStamp >= this.Start) .Where(e => e.TimeStamp <= this.End) .ToArray(); foreach(var sw in contextSwitches) { var program = processes .Where(p => p.Id == sw.NewProcessId) .First(); output.Add("sw", program.Name, "", sw.TimeStamp, 1, sw.NewThreadId, sw.NewProcessId, sw.ProcessorNumber, 0); } // Only export relevant processes var lifetimes = this.Lifetimes .Where(e => e.ProcessId == this.Process.ProcessID); foreach(var lt in lifetimes) { output.Add(lt.State.ToString().ToLowerInvariant(), this.Process.Name, "", lt.TimeStamp, 1, lt.ThreadId, lt.ProcessId, lt.ProcessorNumber, 0); } // Return the results return output; }
/// <summary> /// Exports the data. /// </summary> /// <param name="source">The source output to export.</param> /// <param name="destination">The output destination.</param> public override void Export(EventOutput source, StreamWriter destination) { var threads = source.Select(e => e.Tid).Distinct().ToArray(); var types = source.Select(e => e.Type) .Distinct() .Where(t => t.EndsWith("perf") || t == "ipc" || t == "time") .ToArray(); var min = new DateTime(source.Select(e => e.Time).Min()); var max = new DateTime(source.Select(e => e.Time).Max()); // The output and global values var output = new JsonOutput(); output.Name = source.ProcessName; foreach(var tid in threads) { var thread = new JsonThread(tid); var runtime = new List<double>(); foreach(var type in types) { var measure = new JsonMeasure(type.Replace("perf", String.Empty).ToUpper()); foreach (var timeGroup in source.GroupBy(e => e.Time)) { // Get the values var values = timeGroup .Where(t => t.Tid == tid && t.Type == type) .Select(e => e.Value) .ToArray(); var average = values.Length == 0 ? 0 : values.Average(); if (type.EndsWith("perf") || type == "ipc") average *= 100; if (type == "time") runtime.Add(average); else measure.Data.Add(Math.Min(Math.Round(average, 2), 100)); } // Add the thread to the output if(measure.Data.Count > 0) thread.Measures.Add(measure); } // Calculate the lifetime thread.RuntimeAvg = runtime.Average() * 100; // Add the thread to the output output.Threads.Add(thread); } // Only threads of the process we monitor var ownThreads = source.Where(t => t.Pid != 0).ToArray(); var summableTypes = source .Select(e => e.Type) .Distinct() .Where(t => !t.EndsWith("perf") && !t.EndsWith("ipc") && !t.EndsWith("time")) .ToArray(); // Various variables output.Info["duration"] = (max - min).TotalMilliseconds; output.Info["frames"] = output.Threads.First().Measures.First().Data.Count; foreach (var type in summableTypes) { output.Info[type] = ownThreads .Where(t => t.Type == type) .Select(t => t.Value) .Sum(); } // Sort by runtime and remove the '0' thread output.Threads = output.Threads .Where(t => t.Id != "0") .OrderBy(t => t.RuntimeAvg) .ToList(); // Write destination.WriteLine(JsonConvert.SerializeObject(output)); }
public static void RegisterOutput(EventOutput handler) { s_HandOutput = handler; }
/// <summary> /// Exports the data. /// </summary> /// <param name="source">The source output to export.</param> /// <param name="destination">The output destination.</param> public override void Export(EventOutput source, StreamWriter destination) { destination.Write(JsonConvert.SerializeObject(source, Formatting.Indented)); }
/// <summary> /// Exports the data. /// </summary> /// <param name="source">The source output to export.</param> /// <param name="destination">The output destination.</param> public abstract void Export(EventOutput source, StreamWriter destination);