Skip to content

Commit 209494f

Browse files
authored
Move Command start/stop out of NpgsqlEventSource (#3023)
Fixes #3022
1 parent adefbbf commit 209494f

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/Npgsql/NpgsqlEventSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ public void CommandStart(string sql)
5555
{
5656
Interlocked.Increment(ref _totalCommands);
5757
Interlocked.Increment(ref _currentCommands);
58-
WriteEvent(CommandStartId, sql);
58+
NpgsqlSqlEventSource.CommandStart(sql);
5959
}
6060

6161
[MethodImpl(MethodImplOptions.NoInlining)]
6262
[Event(CommandStopId, Level = EventLevel.Informational)]
6363
public void CommandStop()
6464
{
6565
Interlocked.Decrement(ref _currentCommands);
66-
WriteEvent(CommandStopId);
66+
NpgsqlSqlEventSource.CommandStop();
6767
}
6868

6969
internal void CommandStartPrepared() => Interlocked.Increment(ref _totalPreparedCommands);

src/Npgsql/NpgsqlSqlEventSource.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Diagnostics.Tracing;
2+
using System.Runtime.CompilerServices;
3+
4+
namespace Npgsql
5+
{
6+
sealed class NpgsqlSqlEventSource : EventSource
7+
{
8+
static readonly NpgsqlSqlEventSource Log = new NpgsqlSqlEventSource();
9+
10+
const string EventSourceName = "Npgsql.Sql";
11+
12+
const int CommandStartId = 3;
13+
const int CommandStopId = 4;
14+
15+
internal NpgsqlSqlEventSource() : base(EventSourceName) {}
16+
17+
// NOTE
18+
// - The 'Start' and 'Stop' suffixes on the following event names have special meaning in EventSource. They
19+
// enable creating 'activities'.
20+
// For more information, take a look at the following blog post:
21+
// https://blogs.msdn.microsoft.com/vancem/2015/09/14/exploring-eventsource-activity-correlation-and-causation-features/
22+
// - A stop event's event id must be next one after its start event.
23+
24+
[Event(CommandStartId, Level = EventLevel.Informational)]
25+
public static void CommandStart(string sql) => Log.WriteEvent(CommandStartId, sql);
26+
27+
[MethodImpl(MethodImplOptions.NoInlining)]
28+
[Event(CommandStopId, Level = EventLevel.Informational)]
29+
public static void CommandStop() => Log.WriteEvent(CommandStopId);
30+
}
31+
}

0 commit comments

Comments
 (0)