示例#1
0
        public static PerformanceData EndTrace(string uri, TraceServer traceServerReader)
        {
            PerformanceData perf = new PerformanceData(uri);

            traceServerReader.Stop();

            while (traceServerReader.Read())
            {
                string ApplicationName = traceServerReader.GetString(2);
                if (ApplicationName == null)
                {
                    ApplicationName = string.Empty;
                }
                if (ApplicationName == "SQL Management")
                {
                    continue;
                }
                if (ApplicationName == "Microsoft SQL Server Management Studio")
                {
                    continue;
                }
                if (ApplicationName.StartsWith("SQL Server Profiler"))
                {
                    continue;
                }

                //0: EventClass
                //1: TextData
                //2: ApplicationName
                //3: NTUserName
                //4: LoginName
                //5: CPU
                //6: Reads
                //7: Writes
                //8: Duration
                //9: ClientProcessID
                //10: SPID
                //11: StartTime
                //12: EndTime
                //13: BinaryData

                //string query = traceServerReader.GetString(1);
                //if (string.IsNullOrEmpty(query)) query = string.Empty;
                //if (query.StartsWith("exec sp_executesql N'")) query = query.Remove(0, 21);
                // if (query.Length > 64) query = query.Substring(0, 64);

                //Console.WriteLine("{0}: {1} -> {2} | CPU={3} | Duration={4}", nEventNum,
                //    query,
                //    traceServerReader.GetString(2),
                //    traceServerReader.GetOrdinal("CPU"),
                //    traceServerReader.GetOrdinal("Duration"));

                perf.Queries++;
                object duration = traceServerReader.GetValue(8);
                perf.TotalDuration += (duration == null ? 0 : (long)duration);
            }

            return(perf);
        }
示例#2
0
文件: SqlTrace.cs 项目: dblock/sncore
        public static PerformanceData EndTrace(string uri, TraceServer traceServerReader)
        {
            PerformanceData perf = new PerformanceData(uri);
            traceServerReader.Stop();

            while (traceServerReader.Read())
            {
                string ApplicationName = traceServerReader.GetString(2);
                if (ApplicationName == null) ApplicationName = string.Empty;
                if (ApplicationName == "SQL Management") continue;
                if (ApplicationName == "Microsoft SQL Server Management Studio") continue;
                if (ApplicationName.StartsWith("SQL Server Profiler")) continue;

                //0: EventClass
                //1: TextData
                //2: ApplicationName
                //3: NTUserName
                //4: LoginName
                //5: CPU
                //6: Reads
                //7: Writes
                //8: Duration
                //9: ClientProcessID
                //10: SPID
                //11: StartTime
                //12: EndTime
                //13: BinaryData

                //string query = traceServerReader.GetString(1);
                //if (string.IsNullOrEmpty(query)) query = string.Empty;
                //if (query.StartsWith("exec sp_executesql N'")) query = query.Remove(0, 21);
                // if (query.Length > 64) query = query.Substring(0, 64);

                //Console.WriteLine("{0}: {1} -> {2} | CPU={3} | Duration={4}", nEventNum, 
                //    query,
                //    traceServerReader.GetString(2),
                //    traceServerReader.GetOrdinal("CPU"),
                //    traceServerReader.GetOrdinal("Duration"));

                perf.Queries++;
                object duration = traceServerReader.GetValue(8);
                perf.TotalDuration += (duration == null ? 0 : (long)duration);
            }

            return perf;
        }