Handling multiple instances of the same class derived from EventSource

This commit is contained in:
georgis 2013-02-25 11:28:37 -08:00
Родитель 155884b0a7
Коммит b1eb6f347f
3 изменённых файлов: 53 добавлений и 14 удалений

Просмотреть файл

@ -39,30 +39,57 @@ namespace Tx.LinqPad
if (outputTimestamp == metadataTimestamp)
continue;
Dictionary<string, string> sources;
Dictionary<string, string> sources = new Dictionary<string,string>();
switch(Path.GetExtension(f).ToLower())
{
case ".man":
{
string manifest = File.ReadAllText(f);
sources = ManifestParser.Parse(manifest);
var s = ManifestParser.Parse(manifest);
foreach (string type in s.Keys)
{
if (!sources.ContainsKey(type))
{
sources.Add(type, s[type]);
}
}
break;
}
case ".etl":
{
string manifest = ManifestParser.ExtractFromTrace(f);
if (manifest == "")
string[] manifests = ManifestParser.ExtractFromTrace(f);
if (manifests.Length == 0)
continue;
sources = ManifestParser.Parse(manifest);
break;
foreach (string manifest in manifests)
{
Dictionary<string, string> s = ManifestParser.Parse(manifest);
foreach (string type in s.Keys)
{
if (!sources.ContainsKey(type))
{
sources.Add(type, s[type]);
}
}
}
}
break;
case ".blg":
case ".csv":
case ".tsv":
sources = PerfCounterParser.Parse(f);
{
var s = PerfCounterParser.Parse(f);
foreach (string type in s.Keys)
{
if (!sources.ContainsKey(type))
{
sources.Add(type, s[type]);
}
}
}
break;
default:

Просмотреть файл

@ -19,9 +19,9 @@ namespace Tx.Windows
return parser._code;
}
public static string ExtractFromTrace(string etlFile)
public static string[] ExtractFromTrace(string etlFile)
{
return EtwObservable.ExtractManifest(etlFile);
return EtwObservable.ExtractManifests(etlFile);
}
XElement _root;

Просмотреть файл

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Text;
using System.Threading;
@ -46,17 +47,20 @@ namespace Tx.Windows
/// </summary>
/// <param name="etlFile">Trace file</param>
/// <returns></returns>
public static string ExtractManifest(string etlFile)
public static string[] ExtractManifests(string etlFile)
{
IObservable<EtwNativeEvent> all = EtwObservable.FromFiles(etlFile);
StringBuilder sb = new StringBuilder();
ManualResetEvent evt = new ManualResetEvent(false);
var manifests = new SortedSet<string>();
var sb = new StringBuilder();
var evt = new ManualResetEvent(false);
IDisposable d = all.Subscribe(e =>
{
if (e.Id != 0xfffe) // 65534
{
return;
}
byte format = e.ReadByte();
if (format != 1)
@ -75,14 +79,22 @@ namespace Tx.Windows
sb.Append(chunk);
if (chunkNumber == totalChunks - 1)
evt.Set();
{
string manifest = sb.ToString();
sb = new StringBuilder();
if (!manifests.Contains(manifest))
{
manifests.Add(manifest);
}
}
},
()=> evt.Set());
evt.WaitOne();
d.Dispose();
return sb.ToString();
return new List<string>(manifests).ToArray();
}
}
}