File: SqlEventSource.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (76 lines) | stat: -rw-r--r-- 4,052 bytes parent folder | download | duplicates (7)
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
//------------------------------------------------------------------------------
// <copyright file="SqlEventSource.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <owner current="true" primary="true">mihailsm</owner>
//------------------------------------------------------------------------------

namespace System.Data
{
    using System;
    using System.Diagnostics.Tracing;

    [EventSource(Name = SqlEventSource.EventSourceName)]
    internal sealed class SqlEventSource : EventSource
    {
        internal const string EventSourceName = "Microsoft-AdoNet-SystemData";

        /// <summary>
        /// Defines EventId for BeginExecute (Reader, Scalar, NonQuery, XmlReader).
        /// </summary>
        private const int BeginExecuteEventId = 1;

        /// <summary>
        /// Defines EventId for EndExecute (Reader, Scalar, NonQuery, XmlReader).
        /// </summary>
        private const int EndExecuteEventId = 2;

        // Defines the singleton instance for the Resources ETW provider
        internal static readonly SqlEventSource Log = new SqlEventSource();


        /// <summary>
        /// Keyword definitions.  These represent logical groups of events that can be turned on and off independently
        /// Often each task has a keyword, but where tasks are determined by subsystem, keywords are determined by
        /// usefulness to end users to filter.  Generally users don't mind extra events if they are not high volume
        /// so grouping low volume events together in a single keywords is OK (users can post-filter by task if desired)
        /// <remarks>The visibility of the enum has to be public, otherwise there will be an ArgumentException on calling related WriteEvent method.</remarks>
        /// </summary>
        public static class Keywords
        {
            public const EventKeywords SqlClient = (EventKeywords)0x0001; // This is bit 0
        }

        public static class Tasks // this name is important for EventSource
        {
            /// <summary>Task that tracks sql command execute.</summary>
            public const EventTask ExecuteCommand = (EventTask)1;
        }

        private SqlEventSource() 
        {
        }

        // unfortunately these are not marked as Start/Stop opcodes.  The reason is that we dont want them to participate in 
        // the EventSource activity IDs (because they currently don't use tasks and this simply confuses the logic) and 
        // because of versioning requirements we don't have ActivityOptions capability (because mscorlib and System.Data version 
        // at different rates)  Sigh...
        [Event(SqlEventSource.BeginExecuteEventId, Keywords = Keywords.SqlClient)]
        public void BeginExecute(int objectId, string dataSource, string database, string commandText)
        {
            // we do not use unsafe code for better performance optization here because optimized helpers make the code unsafe where that would not be the case otherwise. 
            // This introduces the question of partial trust, which is complex in the SQL case (there are a lot of scenarios and SQL has special security support).   
            WriteEvent(SqlEventSource.BeginExecuteEventId, objectId, dataSource, database, commandText);
        }

        // unfortunately these are not marked as Start/Stop opcodes.  The reason is that we dont want them to participate in 
        // the EventSource activity IDs (because they currently don't use tasks and this simply confuses the logic) and 
        // because of versioning requirements we don't have ActivityOptions capability (because mscorlib and System.Data version 
        // at different rates)  Sigh...
        [Event(SqlEventSource.EndExecuteEventId, Keywords = Keywords.SqlClient)]
        public void EndExecute(int objectId, int compositeState, int sqlExceptionNumber)
        {
            WriteEvent(SqlEventSource.EndExecuteEventId, objectId, compositeState, sqlExceptionNumber);
        }
    }
}