} // End Sub CloseConnection protected void ProfilerThread(object state) { try { while (!this.m_NeedStop && this.m_Rdr.TraceIsActive) { ProfilerEvent evt = this.m_Rdr.Next(); if (evt != null) { // lock (this) m_events.Enqueue(evt); } // End if (evt != null) } // Whend } catch (System.Exception e) { // lock (this) // { if (!this.m_NeedStop && this.m_Rdr.TraceIsActive) { System.Console.WriteLine($"Error: {e.Message}\n{e.StackTrace}"); } // } // End lock } // End Catch } // End Sub ProfilerThread
private void SetByteColumn(ProfilerEvent evt, int columnid) { var b = new byte[(int)this.m_Reader[1]]; evt.m_Events[columnid] = b; evt.m_ColumnMask |= 1UL << columnid; }
public ProfilerEvent Next() { if (!this.TraceIsActive) { return(null); } var columnid = (int)this.m_Reader[0]; // skip to begin of new event while (columnid != 65526 && this.Read() && this.TraceIsActive) { columnid = (int)this.m_Reader[0]; } // start of new event if (columnid != 65526) { return(null); } if (!this.TraceIsActive) { return(null); } // get potential event class this.m_Reader.GetBytes(2, 0, this.m_B2, 0, 2); var eventClass = ToInt16(this.m_B2); // we got new event if (eventClass >= 0 && eventClass < 255) { var evt = new ProfilerEvent(); evt.m_Events[27] = eventClass; evt.m_ColumnMask |= 1 << 27; while (this.Read()) { columnid = (int)this.m_Reader[0]; if (columnid > 64) { return(evt); } this.m_Delegates[columnid](evt, columnid); } } this.Read(); return(null); }
} // End Sub StopProfiling protected string GetEventCaption(ProfilerEvent evt) { if (evt == m_EventStarted) { return("Trace started"); } if (evt == m_EventPaused) { return("Trace paused"); } if (evt == m_EventStopped) { return("Trace stopped"); } return(ProfilerEvents.Names[evt.EventClass]); } // End Function GetEventCaption
private void SetDateTimeColumn(ProfilerEvent evt, int columnid) { // 2 byte - year // 2 byte - month // 2 byte - ??? // 2 byte - day // 2 byte - hour // 2 byte - min // 2 byte - sec // 2 byte - msec this.m_Reader.GetBytes(2, 0, this.m_B16, 0, 16); var year = this.m_B16[0] | this.m_B16[1] << 8; var month = this.m_B16[2] | this.m_B16[3] << 8; var day = this.m_B16[6] | this.m_B16[7] << 8; var hour = this.m_B16[8] | this.m_B16[9] << 8; var min = this.m_B16[10] | this.m_B16[11] << 8; var sec = this.m_B16[12] | this.m_B16[13] << 8; var msec = this.m_B16[14] | this.m_B16[15] << 8; evt.m_Events[columnid] = new DateTime(year, month, day, hour, min, sec, msec); evt.m_ColumnMask |= (ulong)1 << columnid; }
private static void SetGuidColumn(ProfilerEvent evt, int columnid) { throw new NotImplementedException(); }
} // End Function GetEventCaption protected void NewEventArrived(ProfilerEvent evt, bool last) { // if (evt == m_EventStarted || evt == m_EventPaused || evt == m_EventStopped) return; //m_columns.Add(new PerfColumn { Caption = "Event Class", Column = ProfilerEventColumns.EventClass, Width = 122 }); //m_columns.Add(new PerfColumn { Caption = "Text Data", Column = ProfilerEventColumns.TextData, Width = 255 }); //m_columns.Add(new PerfColumn { Caption = "Login Name", Column = ProfilerEventColumns.LoginName, Width = 79 }); //m_columns.Add(new PerfColumn { Caption = "CPU", Column = ProfilerEventColumns.CPU, Width = 82, Alignment = HorizontalAlignment.Right, Format = "#,0" }); //m_columns.Add(new PerfColumn { Caption = "Reads", Column = ProfilerEventColumns.Reads, Width = 78, Alignment = HorizontalAlignment.Right, Format = "#,0" }); //m_columns.Add(new PerfColumn { Caption = "Writes", Column = ProfilerEventColumns.Writes, Width = 78, Alignment = HorizontalAlignment.Right, Format = "#,0" }); //m_columns.Add(new PerfColumn { Caption = "Duration, ms", Column = ProfilerEventColumns.Duration, Width = 82, Alignment = HorizontalAlignment.Right, Format = "#,0" }); //m_columns.Add(new PerfColumn { Caption = "SPID", Column = ProfilerEventColumns.SPID, Width = 50, Alignment = HorizontalAlignment.Right }); //m_columns.Add(new PerfColumn { Caption = "Start time", Column = ProfilerEventColumns.StartTime, Width = 140, Format = "yyyy-MM-ddThh:mm:ss.ffff" }); //m_columns.Add(new PerfColumn { Caption = "End time", Column = ProfilerEventColumns.EndTime, Width = 140, Format = "yyyy-MM-ddThh:mm:ss.ffff" }); //m_columns.Add(new PerfColumn { Caption = "DatabaseName", Column = ProfilerEventColumns.DatabaseName, Width = 70 }); //m_columns.Add(new PerfColumn { Caption = "Object name", Column = ProfilerEventColumns.ObjectName, Width = 70 }); //m_columns.Add(new PerfColumn { Caption = "Application name", Column = ProfilerEventColumns.ApplicationName, Width = 70 }); //m_columns.Add(new PerfColumn { Caption = "Host name", Column = ProfilerEventColumns.HostName, Width = 70 }); // System.Console.WriteLine(evt); System.Console.ResetColor(); string caption = GetEventCaption(evt); System.Console.Write(caption); System.Console.Write(new string(' ', System.Console.BufferWidth - System.Console.CursorLeft)); if (!this.m_isWindows) { System.Console.Write(System.Environment.NewLine); } string td = evt.GetFormattedData(ProfilerEventColumns.TextData, null); // System.Console.WriteLine(td); // System.Windows.Forms.RichTextBox rich, // RTFBuilder rb = new RTFBuilder { // BackColor = System.Drawing.Color.White // }; // rich.Text = ""; ConsoleOutputWriter cw = new ConsoleOutputWriter() { BackColor = System.Drawing.Color.White }; if (!string.IsNullOrEmpty(td)) { // var lex = new YukonLexer(); lex.SyntaxHighlight(cw, td); this.m_Lex.SyntaxHighlight(cw, td); // rich.Rtf = this.m_Lex.SyntaxHighlight(rb, td); } // for(int i = 0; i < 65; ++i) // 65 is size of array // System.Console.WriteLine(evt.GetFormattedData(i, null)); //for (int i = 1; i < this.m_columns.Count; ++i) //{ // System.Console.WriteLine(i); // System.Console.WriteLine(this.m_columns[i].Caption); // System.Console.WriteLine(evt.GetFormattedData(this.m_columns[i].Column, this.m_columns[i].Format)); //} // Next i } // End Sub NewEventArrived
private void SetLongColumn(ProfilerEvent evt, int columnid) { m_Reader.GetBytes(2, 0, m_B8, 0, 8); evt.m_Events[columnid] = ToInt64(m_B8); evt.m_ColumnMask |= 1UL << columnid; }
private void SetStringColumn(ProfilerEvent evt, int columnid) { evt.m_Events[columnid] = Encoding.Unicode.GetString((byte[])m_Reader[2]); evt.m_ColumnMask |= 1UL << columnid; }
private void CreateEventRow(ProfilerEvent evt, XmlNode root) { XmlNode row = root.OwnerDocument.CreateElement("event"); NewAttribute(row, "EventClass", evt.EventClass.ToString(CultureInfo.InvariantCulture)); NewAttribute(row, "CPU", evt.CPU.ToString(CultureInfo.InvariantCulture)); NewAttribute(row, "Reads", evt.Reads.ToString(CultureInfo.InvariantCulture)); NewAttribute(row, "Writes", evt.Writes.ToString(CultureInfo.InvariantCulture)); NewAttribute(row, "Duration", evt.Duration.ToString(CultureInfo.InvariantCulture)); NewAttribute(row, "SPID", evt.SPID.ToString(CultureInfo.InvariantCulture)); NewAttribute(row, "LoginName", evt.LoginName); NewAttribute(row, "DatabaseName", evt.DatabaseName); NewAttribute(row, "ObjectName", evt.ObjectName); NewAttribute(row, "ApplicationName", evt.ApplicationName); row.InnerText = evt.TextData; root.AppendChild(row); }
private void SetLongColumn(ProfilerEvent evt, int columnid) { this.m_Reader.GetBytes(2, 0, this.m_B8, 0, 8); evt.m_Events[columnid] = ToInt64(this.m_B8); evt.m_ColumnMask |= 1UL << columnid; }
private void SetIntColumn(ProfilerEvent evt, int columnid) { this.m_Reader.GetBytes(2, 0, this.m_B4, 0, 4); evt.m_Events[columnid] = ToInt32(this.m_B4); evt.m_ColumnMask |= 1UL << columnid; }
private void SetStringColumn(ProfilerEvent evt, int columnid) { evt.m_Events[columnid] = Encoding.Unicode.GetString((byte[])this.m_Reader[2]); evt.m_ColumnMask |= 1UL << columnid; }
private void SetDateTimeColumn(ProfilerEvent evt, int columnid) { //2 byte - year //2 byte - month //2 byte - ??? //2 byte - day //2 byte - hour //2 byte - min //2 byte - sec //2 byte - msec m_Reader.GetBytes(2, 0, m_B16, 0, 16); int year = m_B16[0]|m_B16[1]<<8; int month = m_B16[2] | m_B16[3] << 8; int day = m_B16[6] | m_B16[7] << 8; int hour = m_B16[8] | m_B16[9] << 8; int min = m_B16[10] | m_B16[11] << 8; int sec = m_B16[12] | m_B16[13] << 8; int msec = m_B16[14] | m_B16[15] << 8; evt.m_Events[columnid] = new DateTime(year,month,day,hour,min,sec,msec); evt.m_ColumnMask |= (ulong)1 << columnid; }
private string GetEventCaption(ProfilerEvent evt) { if (evt == m_EventStarted) { return "Trace started"; } if (evt == m_EventPaused) { return "Trace paused"; } if (evt == m_EventStopped) { return "Trace stopped"; } return ProfilerEvents.Names[evt.EventClass]; }
private void SetByteColumn(ProfilerEvent evt, int columnid) { byte[] b = new byte[(int)m_Reader[1]]; evt.m_Events[columnid] = b; evt.m_ColumnMask |= 1UL << columnid; }
private string GetFormattedValue(ProfilerEvent evt, int column, string format) { return ProfilerEventColumns.Duration == column ? (evt.Duration / 1000).ToString(format) : evt.GetFormattedData(column, format); }
private void SetIntColumn(ProfilerEvent evt, int columnid) { m_Reader.GetBytes(2, 0, m_B4, 0, 4); evt.m_Events[columnid] = ToInt32(m_B4); evt.m_ColumnMask |= 1UL << columnid; }
private void NewEventArrived(ProfilerEvent evt, bool last) { { ListViewItem current = (lvEvents.SelectedIndices.Count > 0) ? m_Cached[lvEvents.SelectedIndices[0]] : null; m_EventCount++; string caption = GetEventCaption(evt); ListViewItem lvi = new ListViewItem(caption); string[] items = new string[m_columns.Count]; for (int i = 1; i < m_columns.Count; i++) { PerfColumn pc = m_columns[i]; items[i - 1] = pc.Column == -1 ? m_EventCount.ToString("#,0") : GetFormattedValue(evt, pc.Column, pc.Format) ?? ""; } lvi.SubItems.AddRange(items); lvi.Tag = evt; m_Cached.Add(lvi); if (last) { lvEvents.VirtualListSize = m_Cached.Count; lvEvents.SelectedIndices.Clear(); FocusLVI(tbScroll.Checked ? lvEvents.Items[m_Cached.Count - 1] : current, tbScroll.Checked); lvEvents.Invalidate(lvi.Bounds); } } }
public ProfilerEvent Next() { if (!TraceIsActive) return null; int columnid = (int)m_Reader[0]; //skip to begin of new event while (columnid != 65526 && Read() && TraceIsActive) { columnid = (int)m_Reader[0]; } //start of new event if (columnid != 65526) return null; if (!TraceIsActive) return null; //get potential event class m_Reader.GetBytes(2, 0, m_B2, 0, 2); int eventClass = ToInt16(m_B2); //we got new event if (eventClass >= 0 && eventClass < 255) { ProfilerEvent evt = new ProfilerEvent(); evt.m_Events[27] = eventClass; evt.m_ColumnMask |= 1 << 27; while (Read()) { columnid = (int)m_Reader[0]; if (columnid > 64) return evt; m_Delegates[columnid](evt, columnid); } } Read(); return null; }