Beispiel #1
0
        public void AppendFromFile(int cnt, string filename, bool ignorenonamesp, bool transform)
        {
            var x   = new XmlSerializer(typeof(CEvent[]));
            var fs  = new FileStream(filename, FileMode.Open);
            var a   = (CEvent[])x.Deserialize(fs);
            var lex = new YukonLexer();

            foreach (var e in a)
            {
                if (e.TextData.Contains("statman") || e.TextData.Contains("UPDATE STATISTICS"))
                {
                    continue;
                }
                if (ignorenonamesp && e.ObjectName.Length == 0)
                {
                    continue;
                }
                if (transform)
                {
                    AddEvent(cnt, e.DatabaseID, e.DatabaseName
                             , e.ObjectName.Length == 0 ? 0 : e.ObjectID
                             , e.ObjectName.Length == 0 ? "" : e.ObjectName
                             , e.ObjectName.Length == 0 ? lex.StandardSql(e.TextData) : e.TextData, e.CPU, e.Reads, e.Writes,
                             e.Duration, e.Count, e.RowCounts);
                }
                else
                {
                    AddEvent(cnt, e.DatabaseID, e.DatabaseName, e.ObjectID, e.ObjectName, e.TextData, e.CPU, e.Reads,
                             e.Writes, e.Duration, e.Count, e.RowCounts);
                }
            }

            fs.Dispose();
        }
 private void AddTokens(string tokens, YukonLexer.TokenKind tokenkind)
 {
     StringBuilder curtoken = new StringBuilder();
     for (int i = 0; i < tokens.Length; i++)
     {
         if (tokens[i] == ',')
         {
             string s = curtoken.ToString().ToLower();
             if (!m_Words.ContainsKey(s))
                 m_Words.Add(s, tokenkind);
             curtoken = new StringBuilder();
         }
         else
         {
             curtoken.Append(tokens[i]);
         }
     }
     if (curtoken.Length != 0) m_Words.Add(curtoken.ToString(), tokenkind);
 }
        public SqlServerProfiler(string server, string database
                                 , string username, string password)
        {
            this.m_server              = server;
            this.m_database            = database;
            this.m_username            = username;
            this.m_password            = password;
            this.m_integrated_security = string.IsNullOrWhiteSpace(username);

            this.m_isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
                System.Runtime.InteropServices.OSPlatform.Windows
                );

            if (this.m_integrated_security && !this.m_isWindows)
            {
                throw new System.ArgumentException($"Username is NULL or empty. Cannot use integrated-security on non-windows platform.");
            }

            if (!this.m_integrated_security)
            {
                if (password == null)
                {
                    throw new System.ArgumentException($"{nameof(password)} cannot be NULL when integrated security is false.");
                }
            } // End if (!integratedSecurity)


            this.m_Lex = new YukonLexer();
            //this.m_events = new Queue<ProfilerEvent>(10);
            this.m_events          = new System.Collections.Concurrent.ConcurrentQueue <ProfilerEvent>();
            this.m_timer           = new System.Timers.Timer(1000);
            this.m_timer.AutoReset = false;
            this.m_timer.Elapsed  += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
            this.m_timer.Start();

            this.m_columns = new System.Collections.Generic.List <PerfColumn>();
            this.m_columns.Add(new PerfColumn {
                Caption = "Event Class", Column = ProfilerEventColumns.EventClass, Width = 122
            });
            this.m_columns.Add(new PerfColumn {
                Caption = "Text Data", Column = ProfilerEventColumns.TextData, Width = 255
            });
            this.m_columns.Add(new PerfColumn {
                Caption = "Login Name", Column = ProfilerEventColumns.LoginName, Width = 79
            });
            this.m_columns.Add(new PerfColumn {
                Caption = "CPU", Column = ProfilerEventColumns.CPU, Width = 82, Alignment = HorizontalAlignment.Right, Format = "#,0"
            });
            this.m_columns.Add(new PerfColumn {
                Caption = "Reads", Column = ProfilerEventColumns.Reads, Width = 78, Alignment = HorizontalAlignment.Right, Format = "#,0"
            });
            this.m_columns.Add(new PerfColumn {
                Caption = "Writes", Column = ProfilerEventColumns.Writes, Width = 78, Alignment = HorizontalAlignment.Right, Format = "#,0"
            });
            this.m_columns.Add(new PerfColumn {
                Caption = "Duration, ms", Column = ProfilerEventColumns.Duration, Width = 82, Alignment = HorizontalAlignment.Right, Format = "#,0"
            });
            this.m_columns.Add(new PerfColumn {
                Caption = "SPID", Column = ProfilerEventColumns.SPID, Width = 50, Alignment = HorizontalAlignment.Right
            });

            // if (m_currentsettings.EventsColumns.StartTime)
            m_columns.Add(new PerfColumn {
                Caption = "Start time", Column = ProfilerEventColumns.StartTime, Width = 140, Format = "yyyy-MM-ddThh:mm:ss.ffff"
            });
            // if (m_currentsettings.EventsColumns.EndTime)
            m_columns.Add(new PerfColumn {
                Caption = "End time", Column = ProfilerEventColumns.EndTime, Width = 140, Format = "yyyy-MM-ddThh:mm:ss.ffff"
            });
            // if (m_currentsettings.EventsColumns.DatabaseName)
            m_columns.Add(new PerfColumn {
                Caption = "DatabaseName", Column = ProfilerEventColumns.DatabaseName, Width = 70
            });
            // if (m_currentsettings.EventsColumns.ObjectName)
            m_columns.Add(new PerfColumn {
                Caption = "Object name", Column = ProfilerEventColumns.ObjectName, Width = 70
            });
            // if (m_currentsettings.EventsColumns.ApplicationName)
            m_columns.Add(new PerfColumn {
                Caption = "Application name", Column = ProfilerEventColumns.ApplicationName, Width = 70
            });
            // if (m_currentsettings.EventsColumns.HostName)
            m_columns.Add(new PerfColumn {
                Caption = "Host name", Column = ProfilerEventColumns.HostName, Width = 70
            });

            // m_columns.Add(new PerfColumn { Caption = "#", Column = -1, Width = 53, Alignment = HorizontalAlignment.Right });
        } // End Constructor
        public void AppendFromFile(int cnt, string filename, bool ignorenonamesp, bool transform)
        {
            XmlSerializer x = new XmlSerializer(typeof(CEvent[]));
            FileStream fs = new FileStream(filename, FileMode.Open);
            CEvent[] a = (CEvent[])x.Deserialize(fs);
            YukonLexer lex = new YukonLexer();
            foreach (CEvent e in a)
            {
                if (e.TextData.Contains("statman") || e.TextData.Contains("UPDATE STATISTICS")) continue;
                if (!ignorenonamesp || e.ObjectName.Length != 0)
                {
                    if (transform)
                    {

                        AddEvent(cnt, e.DatabaseID, e.DatabaseName
                                 , e.ObjectName.Length == 0 ? 0 : e.ObjectID
                                 , e.ObjectName.Length == 0 ? "" : e.ObjectName
                                 , e.ObjectName.Length == 0 ?
                                                                lex.StandardSql(e.TextData) : e.TextData, e.CPU, e.Reads, e.Writes, e.Duration, e.Count,e.RowCounts);
                    }
                    else
                    {
                        AddEvent(cnt, e.DatabaseID, e.DatabaseName, e.ObjectID, e.ObjectName, e.TextData, e.CPU, e.Reads, e.Writes, e.Duration, e.Count,e.RowCounts);
                    }
                }
            }
            fs.Dispose();

        }