-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathEventPipeProvider.cs
77 lines (63 loc) · 2.3 KB
/
EventPipeProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Linq;
namespace Microsoft.Diagnostics.NETCore.Client
{
public sealed class EventPipeProvider
{
public EventPipeProvider(string name, EventLevel eventLevel, long keywords = 0xF00000000000, IDictionary<string, string> arguments = null)
{
Name = name;
EventLevel = eventLevel;
Keywords = keywords;
Arguments = arguments;
}
public long Keywords { get; }
public EventLevel EventLevel { get; }
public string Name { get; }
public IDictionary<string, string> Arguments { get; }
public override string ToString()
{
return $"{Name}:0x{Keywords:X16}:{(uint)EventLevel}{(Arguments == null ? "" : $":{GetArgumentString()}")}";
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
return this == (EventPipeProvider)obj;
}
public override int GetHashCode()
{
int hash = 0;
hash ^= Name.GetHashCode();
hash ^= Keywords.GetHashCode();
hash ^= EventLevel.GetHashCode();
hash ^= GetArgumentString().GetHashCode();
return hash;
}
public static bool operator ==(EventPipeProvider left, EventPipeProvider right)
{
return left.ToString() == right.ToString();
}
public static bool operator !=(EventPipeProvider left, EventPipeProvider right)
{
return !(left == right);
}
internal string GetArgumentString()
{
if (Arguments == null)
{
return "";
}
return string.Join(";", Arguments.Select(a => {
string escapedKey = a.Key.Contains(';') || a.Key.Contains('=') ? $"\"{a.Key}\"" : a.Key;
string escapedValue = a.Value.Contains(';') || a.Value.Contains('=') ? $"\"{a.Value}\"" : a.Value;
return $"{escapedKey}={escapedValue}";
}));
}
}
}