Exemple #1
0
        public void ModelNamesParsed()
        {
            int          lines = File.ReadLines(@"D:\Games\HOI\mod-CORE\config\models.csv").Count();
            TraceCounter tc    = new TraceCounter();

            string        root   = @"D:\Games\HOI\mod-CORE";
            PrivateObject prCore = new PrivateObject(typeof(Core));

            Trace.Listeners.Add(tc);
            prCore.Invoke("ParseModelNames", root);

            int           modelsCount = 0;
            PrivateObject types       = new PrivateObject(prCore.GetField("_unitTypes"));

            foreach (var e1 in (Dictionary <UnitTypeName, UnitType>)types.GetField("_unitTypes"))
            {
                PrivateObject models = new PrivateObject(e1.Value);
                foreach (var e2 in (Dictionary <int, Model>)models.GetField("_models"))
                {
                    PrivateObject model = new PrivateObject(e2.Value);
                    modelsCount += ((Dictionary <string, string>)model.GetField("_namesByCountry")).Count;
                }
            }

            Assert.AreEqual(lines - 1, modelsCount + tc.Lines, "Model count ({0}) is wrong (should be {1} - {2} = {3})", modelsCount, lines - 2, tc.Lines, lines - 2 - tc.Lines);
        }
        /// <summary>
        /// Constructs a new processor for the provided data files.
        /// </summary>
        /// <param name="events">The data file containing events.</param>
        /// <param name="counters">The data file containing harware coutnters.</param>
        public EventProcessor(TraceLog events, TraceCounter[] counters)
        {
            // Add our data sources
            this.TraceLog = events;
            this.Counters = counters;
            this.CoreCount = this.Counters.Max(c => c.Core) + 1;

            // A last switch per core
            for (int i = 0; i < this.CoreCount; ++i)
                this.LookupLastSwitch.Add(i, null);
        }
Exemple #3
0
        public void TextDataParsed()
        {
            int          lines = File.ReadLines(@"D:\Games\HOI\mod-CORE\config\text.csv").Count(s => { return(s.StartsWith("#") || s.Contains(";;;;;;;;;;;") ? false : true); });
            TraceCounter tc    = new TraceCounter();

            string        root   = @"D:\Games\HOI\mod-CORE";
            PrivateObject prCore = new PrivateObject(typeof(Core));

            Trace.Listeners.Add(tc);
            prCore.Invoke("ParseTextData", root);

            int textCount = ((Dictionary <string, string>)prCore.GetField("_textData")).Count;

            Assert.AreEqual(lines, textCount + tc.Lines, "Text count ({0}) is wrong (should be {1} - {2} = {3})", textCount, lines, tc.Lines, lines - tc.Lines);
            Assert.AreEqual(tc.Lines, 0);
        }
 /// <summary>
 /// Constructs a new processor for the provided data files.
 /// </summary>
 /// <param name="events">The data file containing events.</param>
 /// <param name="counters">The data file containing harware coutnters.</param>
 public PreProcessor(TraceLog events, TraceCounter[] counters)
     : base(events, counters)
 {
 }
 public UserService(TraceCounter counter)
 {
     this.counter = counter;
 }
 public ContextService(TraceCounter counter)
 {
     this.counter = counter;
 }
Exemple #7
0
        /// <summary>
        /// Prepares the files in the experiment directory.
        /// </summary>
        /// <param name="processName">The process to analyze.</param>
        /// <param name="name">The friendly name to use.</param>
        /// <param name="os">The operating system data collector.</param>
        /// <param name="pcm">The hardware counters data collector.</param>
        public override void Merge(string processName, string name, HarvestProcess pcm, HarvestProcess os)
        {
            // Files
            var pcmCsv   = Path.Combine(this.WorkingDir.FullName, "raw-pcm.csv");
            var etlZip   = Path.Combine(this.WorkingDir.FullName, "raw-os.zip");
            var etlFile  = Path.Combine(this.WorkingDir.FullName, "PerfMonitorOutput.etl");
            var etlxFile = Path.Combine(this.WorkingDir.FullName, "PerfMonitorOutput.etlx");

            // Move the files
            if (!File.Exists(pcmCsv))
            {
                File.Copy(pcm.Output.FullName, pcmCsv);
            }
            if (!File.Exists(etlZip))
            {
                File.Move(Path.Combine(os.Executable.Directory.FullName, "PerfMonitorOutput.etl.zip"), etlZip);

                // Extract etl zip
                try
                {
                    ZipFile.ExtractToDirectory(etlZip, this.WorkingDir.FullName);
                }
                catch { }
            }


            // Load the etl and transform
            if (!File.Exists(etlxFile))
            {
                etlxFile = TraceLog.CreateFromETL(etlFile);
            }

            // Open it now
            var traceLog = TraceLog.OpenOrConvert(etlxFile);

            // Get the proces to monitor
            var process = traceLog.Processes
                          .Where(p => p.Name.StartsWith(processName))
                          .FirstOrDefault();

            var hwe = traceLog.Events
                      .Where(e => e.ProcessID == process.ProcessID)
                      .Select(e => e.EventName);

            var events = traceLog.Events.ToArray();

            // Get all context switches
            var switches = traceLog.Events
                           .Where(e => e.EventName.StartsWith("Thread/CSwitch"))
                           .Select(sw => new ContextSwitch(sw))
                           .ToArray();

            var majorFaults = traceLog.Events
                              .Where(e => e.EventName.StartsWith("PageFault/HardPageFault"))
                              .Select(pf => new PageFault(pf))
                              .ToArray();

            var minorFaults = traceLog.Events
                              .Where(e => e.EventName.StartsWith("PageFault/DemandZeroFault"))
                              .Select(pf => new PageFault(pf))
                              .ToArray();

            // Get all hardware counters
            var counters = TraceCounter.FromFile(pcmCsv, process.StartTime.Year, process.StartTime.Month, process.StartTime.Day)
                           .ToArray();

            // 50 ms window
            const int window = 50;

            // Use a preprocessor to speed things up
            var preprocessor = new PreProcessor(traceLog, counters);

            preprocessor.Analyze(processName, window);

            // Create a new experiment
            var analyzers = new Analyzer[] {
                new Analyzer(new DataLocalityProcessor(preprocessor), DataLocalityExporter.Default),
                new Analyzer(new StateProcessor(preprocessor), new JsonExporter()
                {
                    Name = "states"
                }),
                new Analyzer(new SwitchProcessor(preprocessor), new JsonExporter()
                {
                    Name = "switches"
                }),
                new Analyzer(new LockProcessor(preprocessor), new JsonExporter()
                {
                    Name = "locks"
                }),
            };

            // Now run every analyzer
            foreach (var analyzer in analyzers)
            {
                var processor = analyzer.Key;
                var exporter  = analyzer.Value;

                Console.WriteLine("Processing: " + process.GetType().Name);
                var output = processor.Analyze(processName, window);

                // Write the output
                output.Save(Path.Combine(this.WorkingDir.FullName, "output.csv"));
                output.WriteByThread(Path.Combine(this.WorkingDir.FullName, "outputByThread.csv"));

                // Export
                var fname = exporter.Name == null
                    ? name.ToLower()
                    : String.Format("{0}.{1}", name.ToLower(), exporter.Name);

                exporter.ExportToFile(output, Path.Combine(this.WorkingDir.FullName, fname + "." + exporter.Extension));
            }
        }