public static IEnumerable <SampleWithTrace> ParseFromFile(string filename) { var samples = VTuneStackParser.ReadFromFile(filename) .Skip(1) .Select(s => String.Join(",", s.Split(',') .Select(VTuneStackParser.RemovePrePosComma))) .ParseFromStream(); return(samples); }
public static void CPUReportToDWJson(string filename, string outfname, double timeTotal = 0.0) { if (!File.Exists(filename)) { throw new ArgumentException($"Cannot find specified CPU utilization report {filename}"); } if (timeTotal <= 0) { throw new Exception("Invalid runtime specification in CPU utilization report"); } LongInt durationli = TraceUtils.ToNanoseconds(timeTotal); var cpuRecords = VTuneStackParser.ReadFromFile(filename) .Skip(2) .ParseCPURecords(); /* * CPUUtilRecord first = cpuRecords.First(); * CPUUtilRecord last = cpuRecords.Last(); * * CPUUtilTrace trace = new CPUUtilTrace(); * trace.beginTime = new LongInt(0, (long)(first.Start)); * trace.duration = new LongInt(0, (long)(last.End - first.Start)); * trace.counters = new List<ValueTrace> { new ValueTrace(cpuRecords.Select(r => new CPUSample(new LongInt(0, (long)r.Start), (float)r.CPUUtil)).ToList()) }; */ int steps = cpuRecords.Count() - 1; double totalTime = timeTotal; double stepSize = totalTime / steps; List <ValueTrace> vts = new List <ValueTrace>(); vts.Add(new ValueTrace(Enumerable.Range(0, int.MaxValue).Take(steps).Zip(cpuRecords, (x, y) => new CPUSample(TraceUtils.ToNanoseconds(x * stepSize), (float)(y.CPUUtil))))); CPUUtilTrace trace = new CPUUtilTrace { beginTime = new LongInt(0, 0), //duration = new LongInt(0, totalTime), duration = durationli, counters = vts }; string json = JsonConvert.SerializeObject(trace, Formatting.Indented); // var fs = new FileStream(@"C:\users\perf\Sample2.counters", FileMode.Create); var fs = new FileStream(outfname, FileMode.Create); using (StreamWriter writer = new StreamWriter(fs, Encoding.Unicode)) // encoding in Unicode here is key { writer.WriteLine(json); } }