Exemplo n.º 1
0
 /// <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);
         }
 }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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;

                /*var contextSwitches = this.TraceLog.Events
                 *  .Where(e => e.EventName == "Thread/CSwitch")
                 *  .Where(e => e.ProcessorNumber == core)
                 *  .Where(e => e.ProcessID == this.Process.ProcessID)
                 *  .Where(e => e.TimeStamp >= frame.Time)
                 *  .Where(e => e.TimeStamp <= frame.Time + frame.Duration)
                 *  .Count();
                 *
                 * output.Add("switch", frame, EventThread.Custom, contextSwitches);*/

                // Process every thread within this frame
                foreach (var thread in frame.Threads)
                {
                    // Get the number of cycles elapsed
                    var multiplier = frame.GetOnCoreRatio(thread);
                    var cycles     = Math.Round(multiplier * cn.Cycles);
                    output.Add("cycles", frame, thread, cycles);

                    // Time in milliseconds
                    output.Add("ready", frame, thread, frame.GetTime(thread, ThreadState.Ready) / 10000);
                    output.Add("running", frame, thread, frame.GetTime(thread, ThreadState.Running) / 10000);
                    output.Add("standby", frame, thread, frame.GetTime(thread, ThreadState.Standby) / 10000);
                    output.Add("wait", frame, thread, frame.GetTime(thread, ThreadState.Wait) / 10000);
                }
            }


            // Return the results
            return(output);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
 /// <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);
Exemplo n.º 7
0
 /// <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));
 }
Exemplo n.º 8
0
        /// <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));
        }