Add GetDispatcherFromFileName to unify trace loading

Added a static method to decide which trace event dispatcher to use when
loading a trace file.
This commit is contained in:
Lee Culver
2016-05-31 17:49:30 -07:00
parent 2b93b59685
commit 26e6b7f78b
5 changed files with 26 additions and 25 deletions
+2 -10
View File
@@ -49,16 +49,8 @@ public class DotNetHeapDumpGraphReader
}
public void Append(MemoryGraph memoryGraph, string etlName, string processNameOrId = null, double startTimeRelativeMSec = 0)
{
if (etlName.EndsWith(".trace.zip", StringComparison.OrdinalIgnoreCase))
{
using (var source = new CtfTraceEventSource(etlName))
Append(memoryGraph, source, processNameOrId, startTimeRelativeMSec);
}
else
{
using (var source = new ETWTraceEventSource(etlName))
Append(memoryGraph, source, processNameOrId, startTimeRelativeMSec);
}
using (var source = TraceEventDispatcher.GetDispatcherFromFileName(etlName))
Append(memoryGraph, source, processNameOrId, startTimeRelativeMSec);
}
public void Append(MemoryGraph memoryGraph, TraceEventDispatcher source, string processNameOrId = null, double startTimeRelativeMSec = 0)
{
+3 -4
View File
@@ -2263,8 +2263,7 @@ namespace PerfViewExtensibility
if (gcDumpOutputFileName == null)
gcDumpOutputFileName = PerfViewFile.ChangeExtension(etlFileName, ".gcdump");
if (!etlFileName.EndsWith(".trace.zip", StringComparison.OrdinalIgnoreCase))
ETLPerfViewData.UnZipIfNecessary(ref etlFileName, LogFile);
ETLPerfViewData.UnZipIfNecessary(ref etlFileName, LogFile);
// TODO FIX NOW retrieve the process name, ID etc.
var reader = new DotNetHeapDumpGraphReader(LogFile);
@@ -2962,7 +2961,7 @@ namespace PerfViewExtensibility
{
ETLPerfViewData.UnZipIfNecessary(ref etlFile, LogFile);
var source = new ETWTraceEventSource(etlFile);
var source = TraceEventDispatcher.GetDispatcherFromFileName(etlFile);
var gcStats = Stats.GCProcess.Collect(source, 1); // TODO we don't know that it is 1 msec sampling.
var outputFileName = Path.ChangeExtension(etlFile, ".gcStats.html");
@@ -3014,7 +3013,7 @@ namespace PerfViewExtensibility
{
ETLPerfViewData.UnZipIfNecessary(ref etlFile, LogFile);
var source = new ETWTraceEventSource(etlFile);
var source = TraceEventDispatcher.GetDispatcherFromFileName(etlFile);
var jitStats = Stats.JitProcess.Collect(source);
var outputFileName = Path.ChangeExtension(etlFile, ".jitStats.html");
+6
View File
@@ -5209,6 +5209,12 @@ namespace PerfView
internal static void UnZipIfNecessary(ref string inputFileName, TextWriter log, bool unpackInCache = true, bool wprConventions = false)
{
if (inputFileName.EndsWith(".trace.zip", StringComparison.OrdinalIgnoreCase))
{
log.WriteLine($"'{inputFileName}' is a linux trace.");
return;
}
var extension = Path.GetExtension(inputFileName);
if (string.Compare(extension, ".zip", StringComparison.OrdinalIgnoreCase) == 0 ||
string.Compare(extension, ".vspx", StringComparison.OrdinalIgnoreCase) == 0)
+14
View File
@@ -2661,6 +2661,20 @@ namespace Microsoft.Diagnostics.Tracing
/// </summary>
abstract unsafe public class TraceEventDispatcher : TraceEventSource
{
/// <summary>
/// Obtains the correct TraceEventDispatcher for the given trace file name.
/// </summary>
/// <param name="traceFileName">A path to a trace file.</param>
/// <returns>A TraceEventDispatcher for the given trace file.</returns>
public static TraceEventDispatcher GetDispatcherFromFileName(string traceFileName)
{
if (traceFileName.EndsWith(".trace.zip", StringComparison.OrdinalIgnoreCase) ||
traceFileName.EndsWith(".lttng.zip", StringComparison.OrdinalIgnoreCase))
return new CtfTraceEventSource(traceFileName);
else
return new ETWTraceEventSource(traceFileName);
}
// Normally you subscribe to events using parsers that 'attach' themselves to the source. However
// there are a couple of events that TraceEventDispatcher can handle directly.
/// <summary>
+1 -11
View File
@@ -59,7 +59,7 @@ namespace Microsoft.Diagnostics.Tracing.Etlx
{
if (etlxFilePath == null)
etlxFilePath = Path.ChangeExtension(filePath, ".etlx");
using (TraceEventDispatcher source = GetDispatcherFromFileName(filePath))
using (TraceEventDispatcher source = TraceEventDispatcher.GetDispatcherFromFileName(filePath))
{
if (source.EventsLost != 0 && options != null && options.OnLostEvents != null)
options.OnLostEvents(false, source.EventsLost, 0);
@@ -590,16 +590,6 @@ namespace Microsoft.Diagnostics.Tracing.Etlx
}
}
private static TraceEventDispatcher GetDispatcherFromFileName(string filePath)
{
if (filePath.EndsWith(".trace.zip"))
{
return new CtfTraceEventSource(filePath);
}
return new ETWTraceEventSource(filePath);
}
/// <summary>
/// Given a process's virtual address 'address' and an event which acts as a
/// context (determines which process and what time in that process), return