Exemplo n.º 1
0
 public void OnNewTraceEvent(TraceEvent traceEvent)
 {
     if (textDataMatchFilter != null || textDataNotMatchFilter != null)
     {
         string textdata = traceEvent.TextData;// traceEvent["TextData"].ToString();
         if (textDataMatchFilter != null && !textDataMatchFilter.IsMatch(textdata)) return;
         if (textDataNotMatchFilter != null && textDataNotMatchFilter.IsMatch(textdata)) return;
     }
     if (OnResultChange != null) OnResultChange(this.GetType().Name, new Result() { Content = (System.Data.DataRow)traceEvent, Action = ResultAction.Add });
 }
Exemplo n.º 2
0
        public void OnNewTraceEvent(TraceEvent traceEvent)
        {
            try
            {
                Int64 duration = Convert.ToInt64(traceEvent["Duration"].ToString());
                if (duration == 0) return;
                string textdata = traceEvent["TextData"].ToString();
                if (textDataMatchFilter != null && !textDataMatchFilter.IsMatch(textdata)) return;
                if (textDataNotMatchFilter != null && textDataNotMatchFilter.IsMatch(textdata)) return;
                textdata = FormatTextWithOutParameters(textdata);

                Int64 reads;
                Int64 writes;
                Int64 cpu;
                Int64.TryParse(traceEvent["Reads"].ToString(), out reads);
                Int64.TryParse(traceEvent["Writes"].ToString(), out writes);
                Int64.TryParse(traceEvent["CPU"].ToString(), out cpu);

                lock (resultlock)
                {
                    DataRow[] drarray = (from dr in result.Rows.Cast<DataRow>()
                                         where dr["TextData"].ToString() == textdata
                                         select dr).ToArray<DataRow>();

                    if (drarray != null && drarray.Length > 0)
                    {
                        if (Convert.ToDateTime(drarray[0]["LastCaptureTime"])!= Convert.ToDateTime(traceEvent["StartTime"]) ||
                           Convert.ToInt64(drarray[0]["LastDuration"]) != duration)
                        {
                            drarray[0]["AverageDuration"] = (Convert.ToInt64(drarray[0]["Count"]) * Convert.ToInt64(drarray[0]["AverageDuration"]) + duration)
                                / (Convert.ToInt64(drarray[0]["Count"]) + 1);

                            drarray[0]["AverageReads"] = (Convert.ToInt64(drarray[0]["Count"]) * Convert.ToInt64(drarray[0]["AverageReads"]) + reads)
                               / (Convert.ToInt64(drarray[0]["Count"]) + 1);

                            drarray[0]["AverageWrites"] = (Convert.ToInt64(drarray[0]["Count"]) * Convert.ToInt64(drarray[0]["AverageWrites"]) + writes)
                               / (Convert.ToInt64(drarray[0]["Count"]) + 1);

                            drarray[0]["AverageCPU"] = (Convert.ToInt64(drarray[0]["Count"]) * Convert.ToInt64(drarray[0]["AverageCPU"]) + cpu)
                              / (Convert.ToInt64(drarray[0]["Count"]) + 1);

                            drarray[0]["Count"] = Convert.ToInt64(drarray[0]["Count"]) + 1;

                            if (Convert.ToInt64(drarray[0]["MinDuration"]) > duration) drarray[0]["MinDuration"] = duration;
                            if (Convert.ToInt64(drarray[0]["MaxDuration"]) < duration) drarray[0]["MaxDuration"] = duration;

                            if (Convert.ToInt64(drarray[0]["MinReads"]) > reads) drarray[0]["MinReads"] = reads;
                            if (Convert.ToInt64(drarray[0]["MaxReads"]) < reads) drarray[0]["MaxReads"] = reads;

                            if (Convert.ToInt64(drarray[0]["MinWrites"]) > writes) drarray[0]["MinWrites"] = writes;
                            if (Convert.ToInt64(drarray[0]["MaxWrites"]) < writes) drarray[0]["MaxWrites"] = writes;

                            if (Convert.ToInt64(drarray[0]["MinCPU"]) > cpu) drarray[0]["MinCPU"] = cpu;
                            if (Convert.ToInt64(drarray[0]["MaxCPU"]) < cpu) drarray[0]["MaxCPU"] = cpu;

                            drarray[0]["LastCaptureTime"] = Convert.ToDateTime(traceEvent["StartTime"]);
                            drarray[0]["LastDuration"] = duration;
                        }

                    }
                    else
                    {

                        result.Rows.Add(new object[]{
                        textdata,
                        1,
                        duration,
                        duration,
                        duration,
                        Convert.ToDateTime(traceEvent["StartTime"]),
                        Convert.ToDateTime(traceEvent["StartTime"]),
                        duration,
                        reads,
                        reads,
                        reads,
                        writes,
                        writes,
                        writes,
                        cpu,
                        cpu,
                        cpu

                    });

                        if (result.Rows.Count > top)
                        {
                            var drdel = from dr in result.Rows.Cast<DataRow>()
                                        orderby Convert.ToDecimal(dr["AverageDuration"]) ascending
                                        select dr;
                            result.Rows.Remove(drdel.ToList<DataRow>()[0]);
                        }
                    }
                }
                OnResultChange(this.GetType().Name, new Result() { Action = ResultAction.Refresh, Content = result });
            }
            catch
            {
            }
        }
Exemplo n.º 3
0
 public void OnNewTraceEvent(TraceEvent traceEvent)
 {
     //throw new NotImplementedException();
     if (OnResultChange != null) OnResultChange(this.GetType().Name, new Result() { Content = traceEvent, Action = ResultAction.Add });
 }
Exemplo n.º 4
0
        public void OnNewTraceEvent(TraceEvent traceEvent)
        {
            if (traceEvent["EventClass"].ToString().StartsWith("Showplan"))
            {
                string textdata = traceEvent["TextData"].ToString();
                XmlDocument xdoc = new XmlDocument();
                string header = "<?xml version=\"1.0\" encoding=\"utf-16\"?>";
                try
                {
                    xdoc.LoadXml(header + textdata.Replace("xmlns=\"http://schemas.microsoft.com/sqlserver/2004/07/showplan\"", ""));
                    //var nsmgr = new XmlNamespaceManager(xdoc.NameTable);
                    //nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                    //nsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
                    //XmlNode statementNode = xdoc.SelectSingleNode("//StmtSimple", nsmgr);
                    //string statement = "Cached";
                    //if (statementNode.Attributes["StatementText"] != null)
                    //{
                    //    statement = statementNode.Attributes["StatementText"].Value;
                    //}

                    DataRow[] rows = result.Select(" TransactionID ='" + traceEvent["TransactionID"].ToString() + "'");
                    DataRow row;
                    bool newrowflag = false;
                    if (rows.Length > 0)
                    {
                        row = rows[0];
                    }
                    else
                    {
                        newrowflag = true;
                        string objectname = traceEvent["ObjectName"].ToString();
                        object[] newrow = new object[result.Columns.Count];
                        newrow[0] = objectname;
                        newrow[2] = textdata;
                        newrow[3] = traceEvent["TransactionID"].ToString();

                        for (int idx = 5; idx < newrow.Length; idx += 2) newrow[idx] = 0;
                        row = result.Rows.Add(newrow);
                    }

                    bool hasheavy = false;
                    foreach (XmlNode relop in xdoc.SelectNodes("//RelOp"))
                    {
                        if (relop.Attributes["PhysicalOp"] != null)
                        {
                            HeavyOperations heavyop;
                            bool isheavy = Enum.TryParse<HeavyOperations>(relop.Attributes["PhysicalOp"].Value.Replace(" ", ""), out heavyop);

                            if (isheavy)
                            {
                                string table = string.Empty;
                                XmlNode scanobject = relop.SelectSingleNode(".//Object");
                                if (scanobject != null && scanobject.Attributes["Table"] != null) table = scanobject.Attributes["Table"].Value;
                                if (table != string.Empty)
                                {
                                    row[Enum.GetName(typeof(HeavyOperations), heavyop) + "Count"] = int.Parse(row[Enum.GetName(typeof(HeavyOperations), heavyop) + "Count"].ToString()) + 1;
                                    if (!row[Enum.GetName(typeof(HeavyOperations), heavyop) + "Tables"].ToString().Contains(table))
                                    {
                                        row[Enum.GetName(typeof(HeavyOperations), heavyop) + "Tables"] = row[Enum.GetName(typeof(HeavyOperations), heavyop) + "Tables"].ToString() + table;
                                    }
                                    row.AcceptChanges();
                                    hasheavy = true;
                                }
                            }
                        }
                    }
                    if (hasheavy)
                    {
                        if (OnResultChange != null) OnResultChange(this.GetType().Name, new Result() { Content = result, Action = ResultAction.Refresh });
                    }
                    else
                    {
                        if (newrowflag) result.Rows.Remove(row);
                    }
                }
                catch (Exception)
                {
                }
            }//other trace event
            else if (traceEvent["EventClass"].ToString().Contains("Completed"))
            {
                if (result.Rows.Count > 0)
                {
                    result.Rows[result.Rows.Count-1][1] = traceEvent["TextData"].ToString();
                    if (OnResultChange != null) OnResultChange(this.GetType().Name, new Result() { Content = result, Action = ResultAction.Refresh });
                }
            }
        }
Exemplo n.º 5
0
 public abstract void OnNewTraceEvent(TraceEvent traceEvent);
Exemplo n.º 6
0
        public void OnNewTraceEvent(TraceEvent traceEvent)
        {
            if (traceEvent["EventClass"].ToString().StartsWith("Showplan") || traceEvent["EventClass"].ToString() == "146")
            {
                string objectname = traceEvent["ObjectName"].ToString();
                string textdata = traceEvent["TextData"].ToString();
                XmlDocument xdoc = new XmlDocument();
                string header = "<?xml version=\"1.0\" encoding=\"utf-16\"?>";
                try
                {
                    xdoc.LoadXml(header + textdata.Replace("xmlns=\"http://schemas.microsoft.com/sqlserver/2004/07/showplan\"", ""));

                    DataRow[] rows = Result.Tables["StoredProcedure"].Select(" Object ='" + objectname + "'");
                    DataRow row;
                    if (rows.Length > 0)
                    {
                        row = rows[0];
                        int lineNumber = Convert.ToInt32(traceEvent["LineNumber"].ToString());
                        int entryLineNumber = Convert.ToInt32(row["EntryLineNumber"].ToString());
                        if (lineNumber <= entryLineNumber) row["Count"] = Convert.ToInt32(row["Count"]) + 1;
                        if (lineNumber < entryLineNumber) row["EntryLineNumber"] = lineNumber.ToString();
                        row["LastCaptureTime"] = Convert.ToDateTime(traceEvent["StartTime"]);
                    }
                    else
                    {

                        object[] newrow = new object[5];
                        newrow[0] = objectname;
                        newrow[1] = 1;
                        newrow[2] = traceEvent["LineNumber"].ToString();
                        newrow[3] = Convert.ToDateTime(traceEvent["StartTime"]);
                        newrow[4] = Convert.ToDateTime(traceEvent["StartTime"]);

                        row = Result.Tables["StoredProcedure"].Rows.Add(newrow);
                    }

                    bool hasheavy = false;
                    foreach (XmlNode relop in xdoc.SelectNodes("//RelOp"))
                    {
                        if (relop.Attributes["PhysicalOp"] != null)
                        {

                            string operation =relop.Attributes["PhysicalOp"].Value.Replace(" ", "");

                            if (HeavyOperations.Contains(operation) || HeavyOperations.Count==0)
                            {
                                string table = string.Empty;
                                XmlNode scanobject = relop.SelectSingleNode(".//Object");
                                if (scanobject != null && scanobject.Attributes["Table"] != null) table = scanobject.Attributes["Table"].Value.Substring(1,scanobject.Attributes["Table"].Value.Length-2);
                                if (table != string.Empty)
                                {
                                    DataRow[] oprows = Result.Tables["Operation"].Select(" Object ='" + objectname + "' and Table='" + table + "' and Operation='"+operation+"'");
                                    DataRow oprow;
                                    if (oprows.Length > 0)
                                    {
                                        oprow = oprows[0];
                                        oprow["Count"] = Convert.ToInt32(oprow["Count"]) + 1;
                                        oprow["LastCaptureTime"] = Convert.ToDateTime(traceEvent["StartTime"]);
                                    }
                                    else
                                    {

                                        object[] newrow = new object[6];
                                        newrow[0] = objectname;
                                        newrow[1] = table;
                                        newrow[2] = operation;
                                        newrow[3] = 1;
                                        newrow[4] = Convert.ToDateTime(traceEvent["StartTime"]);
                                        newrow[5] = Convert.ToDateTime(traceEvent["StartTime"]);
                                        Result.Tables["Operation"].Rows.Add(newrow);
                                    }
                                    hasheavy = true;
                                }
                            }
                        }
                    }
                    if (hasheavy)
                    {
                        if (OnResultChange != null) OnResultChange(this.GetType().Name, new Result() { Content = Result, Action = ResultAction.Refresh });
                    }

                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.StackTrace);
                    System.Diagnostics.Trace.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 7
0
 public void OnNewTraceEvent(TraceEvent traceEvent)
 {
     mi.Invoke(null, new object[] { traceEvent, new Action<Result>(this.UpdateResult) });
 }
Exemplo n.º 8
0
        protected void HandleEventData(TraceEvent traceevent)
        {
            if (Handlers != null)
            {
                try
                {
                    if (Interval.Ticks != 0)
                    {
                        if (sentinal == DateTime.MaxValue) sentinal = DateTime.UtcNow;
                        if (DateTime.UtcNow.Subtract(sentinal) > Interval)
                        {
                            foreach (IResultHandler handler in Handlers)
                            {
                                try
                                {
                                    handler.SaveResult(resultSaveAdapter);
                                }
                                catch
                                {
                                }
                            }
                            sentinal = DateTime.UtcNow;
                        }
                    }

                    if (traceevent.EventClass.HasValue)
                    {
                        foreach (IResultHandler handler in Handlers)
                        {
                            if (handler.TraceDefinition.ContainsKey(traceevent.EventClass.Value)) handler.OnNewTraceEvent(traceevent);
                        }
                    }
                }
                catch (Exception ex)
                {
                    FireException(ex.Message);
                }

            }
        }