Skip to content

Commit 16b87dc

Browse files
committed
Merge branch 'master' of https://github.com/microsoft/SqlNexus
2 parents 8ec6206 + 4fd9e3e commit 16b87dc

File tree

15 files changed

+1685
-1526
lines changed

15 files changed

+1685
-1526
lines changed

NexusInterfaces/csql.cs

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ public void ExecuteSqlScript(String script)
4848
}
4949
private String[] ParseBatches(string scriptText)
5050
{
51-
Regex blank = new Regex("\r\n\\s+\rn");
52-
scriptText = blank.Replace(scriptText, "");
5351
Regex reg1 = new Regex("\r\n\\s*go\\s*\r\n*", RegexOptions.IgnoreCase);
54-
5552
return reg1.Split(scriptText);
5653

5754
}
@@ -81,16 +78,17 @@ public DataTable GetDataTable (string sql)
8178
return dt;
8279

8380
}
84-
private void ExecuteBatches(string[] batches)
81+
private void ExecuteBatches(string[] batches)
8582
{
8683
string batchText;
8784
string upperBatchText;
88-
SqlConnection conn = new SqlConnection(m_ConnStringBuilder.ConnectionString);
89-
conn.InfoMessage += new SqlInfoMessageEventHandler(OnInfoMessage);
90-
conn.Open(); //we want this exception to pop up when we can't make a connection
9185
Int32 BatchesExecuted = 0;
92-
try
86+
87+
using (SqlConnection conn = new SqlConnection(m_ConnStringBuilder.ConnectionString))
9388
{
89+
conn.InfoMessage += new SqlInfoMessageEventHandler(OnInfoMessage);
90+
conn.Open(); //we want this exception to pop up when we can't make a connection
91+
9492

9593
foreach (String bat in batches)
9694
{
@@ -99,67 +97,72 @@ private void ExecuteBatches(string[] batches)
9997
try
10098
{
10199
BatchesExecuted++;
102-
SqlCommand cmd = new SqlCommand();
103-
cmd.CommandText = bat;
104-
cmd.Connection = conn;
105-
cmd.CommandTimeout = 0;
106-
107-
//printing the fact that batch is being executed
108-
if (String.IsNullOrEmpty(bat))
109-
batchText = "Empty Batch";
110-
else if (bat.Length <= 100)
111-
batchText = bat;
112-
else
113-
batchText = bat.Substring(0, 100);
114-
115-
batchText = batchText.Replace("\r\n", " ");
116-
batchText = batchText.Replace("*****", "*");
117-
batchText = batchText.Replace(" ", " ");
118-
119-
upperBatchText = batchText.ToUpper();
120-
121-
int position = upperBatchText.IndexOf("OWNER:");
122-
if (position > -1)
123-
{
124-
batchText = "'Script owner found in a comment here'";
125-
}
126-
m_ErrorMessages.AppendFormat("Starting execution of {0} \r\n", batchText);
127100

128-
SqlDataReader dr = cmd.ExecuteReader();
129-
while (dr.NextResult())
101+
using (SqlCommand cmd = new SqlCommand())
130102
{
131-
m_ErrorMessages.AppendFormat("{0} \r\n", GetStringFromReader(dr));
132-
}
133-
134-
135-
if (!dr.IsClosed)
136-
dr.Close();
137-
//m_Success=true;
103+
cmd.CommandText = bat;
104+
cmd.Connection = conn;
105+
cmd.CommandTimeout = 0;
106+
107+
//printing the fact that batch is being executed
108+
if (String.IsNullOrEmpty(bat))
109+
batchText = "Empty Batch";
110+
else if (bat.Length <= 100)
111+
batchText = bat;
112+
else
113+
batchText = bat.Substring(0, 100);
114+
115+
batchText = batchText.Replace("\r\n", " ");
116+
batchText = batchText.Replace("*****", "*");
117+
batchText = batchText.Replace(" ", " ");
118+
119+
upperBatchText = batchText.ToUpper();
120+
121+
int position = upperBatchText.IndexOf("OWNER:");
122+
if (position > -1)
123+
{
124+
batchText = "'Script owner found in a comment here'";
125+
}
126+
127+
m_ErrorMessages.AppendFormat("Starting execution of {0} \r\n", batchText);
128+
129+
130+
131+
using (SqlDataReader dataReader = cmd.ExecuteReader())
132+
{
133+
while (dataReader.NextResult())
134+
{
135+
m_ErrorMessages.AppendFormat("{0} \r\n", GetStringFromReader(dataReader));
136+
}
137+
}//automatically calls Dispose method SqlDataReader
138+
139+
}//automatically calls Dispose method on SqlCommand
138140
}
141+
//m_Success=true;
142+
139143
catch (SqlException sqlex)
140144
{
141145
m_Success = false;
142146
m_ErrorMessages.AppendFormat("{0} \r\n", sqlex.ToString());
143147
}
144-
catch (Exception ex)
148+
catch (Exception ex)
145149
{
146150
m_Success = false;
147151
m_ErrorMessages.AppendFormat("{0} \r\n", ex.ToString());
148152
throw ex;
149153
}
150-
}
151154

152-
}
153-
finally
154-
{
155-
conn.Close();
156-
m_ErrorMessages.AppendLine("Batches Executed " + BatchesExecuted);
157-
}
158155

156+
}//foreach loop
159157

158+
}//automatically calls Dispose method on SqlConnection
160159

160+
m_ErrorMessages.AppendLine("Batches Executed " + BatchesExecuted);
161161
}
162162

163+
164+
165+
163166
void OnInfoMessage(object sender, SqlInfoMessageEventArgs args)
164167
{
165168
foreach (SqlError err in args.Errors)

ReadTraceNexusImporter/ReadTraceNexusImporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ public void OnStatusChanged(EventArgs e)
599599
/// <summary>Filemask (e.g. "*.trc") used to advertise the set of files that a given importer knows how to process</summary>
600600
public string[] SupportedMasks
601601
{
602-
get { return new string[] { "*.TRC", "*pssdiag*.xel" }; }
602+
get { return new string[] { "*.TRC", "*pssdiag*.xel", "*LogScout*.xel" }; }
603603
}
604604

605605
/// <summary>Number of rows/lines/events processed from source file. Used to communicate progress back to host.</summary>

RowsetImportEngine/TextRowset.cs

4 Bytes
Binary file not shown.

RowsetImportEngine/TextRowsetImporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ private bool CheckForRowsetStart (string ColumnLines, string ColumnNames, string
798798
// Create table in SQL if this is the first time we've run into it.
799799
if (!this.CurrentRowset.HasBeenEncountered)
800800
{
801-
logger.LogMessage("First time encoutering row identifier" + RowsetIdentifier);
801+
logger.LogMessage("First time encoutering row identifier '" + RowsetIdentifier + "'");
802802
CreateTable();
803803
}
804804
// If we don't have an in-progress bulk load for the rowset, start one.

RowsetImportEngine/TextRowsets.xml

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,64 @@
330330
<Column name="waiter_count" type="RowsetImportEngine.IntColumn" />
331331
<Column name="timeout_error_count" type="RowsetImportEngine.IntColumn" />
332332
<Column name="forced_grant_count" type="RowsetImportEngine.IntColumn" />
333-
<Column name="Object_Name" type="RowsetImportEngine.VarCharColumn" length="128" />
334333
</Rowset>
335334

336335

336+
<Rowset name="tbl_Query_Execution_Memory_MemScript" enabled="true" identifier="-- query execution memory mem_script--" type="RowsetImportEngine.TextRowset">
337+
<Column name="runtime" type="RowsetImportEngine.DateTimeColumn"/>
338+
<Column name="session_id" type="RowsetImportEngine.BigIntColumn" />
339+
<Column name="blocking_session_id" type="RowsetImportEngine.BigIntColumn" />
340+
<Column name="cpu_time" type="RowsetImportEngine.BigIntColumn" />
341+
<Column name="total_elapsed_time" type="RowsetImportEngine.BigIntColumn" />
342+
<Column name="reads" type="RowsetImportEngine.BigIntColumn" />
343+
<Column name="writes" type="RowsetImportEngine.BigIntColumn" />
344+
<Column name="logical_reads" type="RowsetImportEngine.BigIntColumn" />
345+
<Column name="row_count" type="RowsetImportEngine.BigIntColumn" />
346+
<Column name="wait_time" type="RowsetImportEngine.BigIntColumn" />
347+
<Column name="wait_type" type="RowsetImportEngine.NVarCharColumn" length="64" />
348+
<Column name="command" type="RowsetImportEngine.NVarCharColumn" length="64" />
349+
<Column name="text" type="RowsetImportEngine.NVarCharColumn" length="2000" />
350+
<Column name="login_time" type="RowsetImportEngine.DateTimeColumn"/>
351+
<Column name="name" type="RowsetImportEngine.NVarCharColumn" length="128" />
352+
<Column name="login_name" type="RowsetImportEngine.NVarCharColumn" length="128" />
353+
<Column name="host_name" type="RowsetImportEngine.NVarCharColumn" length="128" />
354+
<Column name="nt_domain" type="RowsetImportEngine.NVarCharColumn" length="128" />
355+
<Column name="nt_user_name" type="RowsetImportEngine.NVarCharColumn" length="128" />
356+
<Column name="status" type="RowsetImportEngine.VarCharColumn" length="30" />
357+
<Column name="client_net_address" type="RowsetImportEngine.VarCharColumn" length="30" />
358+
<Column name="program_name" type="RowsetImportEngine.NVarCharColumn" length="128" />
359+
<Column name="client_interface_name" type="RowsetImportEngine.VarCharColumn" length="32" />
360+
<Column name="last_request_start_time" type="RowsetImportEngine.DateTimeColumn"/>
361+
<Column name="last_request_end_time" type="RowsetImportEngine.DateTimeColumn"/>
362+
<Column name="connect_time" type="RowsetImportEngine.DateTimeColumn"/>
363+
<Column name="last_read" type="RowsetImportEngine.DateTimeColumn"/>
364+
<Column name="last_write" type="RowsetImportEngine.DateTimeColumn"/>
365+
<Column name="dop" type="RowsetImportEngine.IntColumn" />
366+
<Column name="request_time" type="RowsetImportEngine.DateTimeColumn"/>
367+
<Column name="grant_time" type="RowsetImportEngine.DateTimeColumn"/>
368+
<Column name="requested_memory_mb" type="RowsetImportEngine.FloatColumn" />
369+
<Column name="granted_memory_mb" type="RowsetImportEngine.FloatColumn" />
370+
<Column name="required_memory_mb" type="RowsetImportEngine.FloatColumn" />
371+
<Column name="max_used_memory_mb" type="RowsetImportEngine.FloatColumn" />
372+
<Column name="query_cost" type="RowsetImportEngine.FloatColumn" />
373+
<Column name="timeout_sec" type="RowsetImportEngine.IntColumn" />
374+
<Column name="resource_semaphore_id" type="RowsetImportEngine.IntColumn" />
375+
<Column name="wait_time_ms" type="RowsetImportEngine.BigIntColumn" />
376+
<Column name="Next Candidate for Memory Grant" type="RowsetImportEngine.NVarCharColumn" length="2000" />
377+
<Column name="server_target_memory_mb" type="RowsetImportEngine.IntColumn" />
378+
<Column name="server_max_target_memory_mb" type="RowsetImportEngine.IntColumn" />
379+
<Column name="server_total_memory_mb" type="RowsetImportEngine.IntColumn" />
380+
<Column name="server_available_memory_mb" type="RowsetImportEngine.IntColumn" />
381+
<Column name="server_granted_memory_mb" type="RowsetImportEngine.IntColumn" />
382+
<Column name="server_used_memory_mb" type="RowsetImportEngine.IntColumn" />
383+
<Column name="grantee_count" type="RowsetImportEngine.IntColumn" />
384+
<Column name="waiter_count" type="RowsetImportEngine.IntColumn" />
385+
<Column name="timeout_error_count" type="RowsetImportEngine.IntColumn" />
386+
<Column name="forced_grant_count" type="RowsetImportEngine.IntColumn" />
387+
<Column name="Object_Name" type="RowsetImportEngine.VarCharColumn" length="128" />
388+
</Rowset>
389+
390+
337391
<Rowset name="tbl_dm_os_ring_buffers_mem" enabled="true" identifier="-- sys.dm_os_ring_buffers (RING_BUFFER_RESOURCE_MONITOR and RING_BUFFER_MEMORY_BROKER)" type="RowsetImportEngine.TextRowset">
338392
<Column name="runtime" type="RowsetImportEngine.DateTimeColumn"/>
339393
<Column name="record_time" type="RowsetImportEngine.DateTimeColumn"/>
@@ -460,16 +514,19 @@
460514

461515
</Rowset>
462516

463-
<Rowset name="tbl_HEADBLOCKERSUMMARY" enabled="true" identifier="-- headblockersummary" type="RowsetImportEngine.TextRowset">
517+
<Rowset name="tbl_HEADBLOCKERSUMMARY" enabled="true" identifier="-- headblockersummary --" type="RowsetImportEngine.TextRowset">
464518
<Column name="rownum" type="RowsetImportEngine.BigIntColumn" length="24" valuetoken="ROWNUMBER" />
465519
<Column name="runtime" type="RowsetImportEngine.DateTimeColumn" />
466520
<Column name="head_blocker_session_id" type="RowsetImportEngine.IntColumn" />
467521
<Column name="blocked_task_count" type="RowsetImportEngine.IntColumn" />
468522
<Column name="tot_wait_duration_ms" type="RowsetImportEngine.BigIntColumn" />
523+
<Column name="blocking_resource_wait_type" type="RowsetImportEngine.VarCharColumn" length="40"/>
469524
<Column name="avg_wait_duration_ms" type="RowsetImportEngine.BigIntColumn" />
470525
<Column name="max_wait_duration_ms" type="RowsetImportEngine.BigIntColumn" />
471526
<Column name="max_blocking_chain_depth" type="RowsetImportEngine.IntColumn" />
527+
<Column name="head_blocker_proc_name" type="RowsetImportEngine.VarCharColumn" length="64"/>
472528
<Column name="head_blocker_proc_objid" type="RowsetImportEngine.IntColumn" />
529+
<Column name="stmt_text" type="RowsetImportEngine.VarCharColumn" length="1024"/>
473530
<Column name="head_blocker_plan_handle" type="RowsetImportEngine.VarBinaryColumn" />
474531
</Rowset>
475532

@@ -532,8 +589,7 @@
532589
<Column name="type" type="RowsetImportEngine.VarCharColumn" />
533590
<Column name="name" type="RowsetImportEngine.VarCharColumn" />
534591
<Column name="memory_node_id" type="RowsetImportEngine.IntColumn" />
535-
<Column name="single_pages_kb" type="RowsetImportEngine.BigIntColumn" />
536-
<Column name="multi_pages_kb" type="RowsetImportEngine.BigIntColumn" />
592+
<Column name="pages_kb" type="RowsetImportEngine.BigIntColumn" />
537593
<Column name="virtual_memory_reserved_kb" type="RowsetImportEngine.BigIntColumn" />
538594
<Column name="virtual_memory_committed_kb" type="RowsetImportEngine.BigIntColumn" />
539595
<Column name="awe_allocated_kb" type="RowsetImportEngine.BigIntColumn" />
@@ -2093,6 +2149,14 @@
20932149
<Column name="active_statement_text" type="RowsetImportEngine.VarCharColumn" />
20942150
</Rowset>
20952151

2152+
<Rowset name="tbl_server_times" enabled="true" identifier="-- server_times --" type="RowsetImportEngine.InputbuffersRowset">
2153+
<KnownColumns>
2154+
<Column name="server_time" type="RowsetImportEngine.DateTimeColumn" />
2155+
<Column name="utc_time" type="RowsetImportEngine.DateTimeColumn" />
2156+
<Column name="time_delta_hours" type="RowsetImportEngine.IntColumn" />
2157+
</KnownColumns>
2158+
</Rowset>
2159+
20962160
</KnownRowsets>
20972161
</TextImport>
20982162

Setup-Related/SetupSQLNexusPrereq.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ elseif
119119
Add-Type -AssemblyName System.Windows.Forms
120120
$result = [System.Windows.Forms.MessageBox]::Show("Continue with uninstallation of RML Utils version: " + $RMLsw_found64bit.DisplayVersion + "?","Uninstall", "YesNo" , "Information" , "Button1")
121121

122+
122123
if($result -ne $null)
123124
{
124125
if ($result.ToString() -eq 'Yes')

sqlnexus/PerfStatsAnalysis.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2958,7 +2958,7 @@ begin
29582958
IF EXISTS ( SELECT * FROM sysobjects WHERE name = ltrim(rtrim('CounterData')))
29592959
begin
29602960
--Fix: Issue #37, fixed negative number of CPUs
2961-
select @SQLcpuCount = Count(distinct scheduler_id) from tbl_dm_OS_Schedulers
2961+
select @SQLcpuCount = Count(distinct scheduler_id) from tbl_dm_os_schedulers_snapshot
29622962
where status = 'VISIBLE ONLINE'
29632963
End
29642964
IF EXISTS ( SELECT * FROM sysobjects WHERE name = ltrim(rtrim('CounterData')))

sqlnexus/Program.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ static class Program
8181
public static void ShowUsage()
8282
{
8383
// logger isn't hooked up to log file at this point and we're definitely running from the command line...
84-
Console.WriteLine(Util.ExpandEscapeStrings(sqlnexus.Properties.Resources.Msg_Nexus));
84+
//Console.WriteLine(Util.ExpandEscapeStrings(sqlnexus.Properties.Resources.Msg_Nexus));
8585
Console.WriteLine(Util.ExpandEscapeStrings(sqlnexus.Properties.Resources.Usage_Summary));
86+
Console.WriteLine("");
8687
Console.WriteLine(Util.ExpandEscapeStrings(sqlnexus.Properties.Resources.Usage_Server));
8788
Console.WriteLine(Util.ExpandEscapeStrings(sqlnexus.Properties.Resources.Usage_Database));
8889
Console.WriteLine(Util.ExpandEscapeStrings(sqlnexus.Properties.Resources.Usage_WindowsAuth));
@@ -143,6 +144,15 @@ private static bool ProcessCmdLine(string[] args, ILogger logger)
143144
}
144145
}
145146

147+
string arg_slash_validation = arg.Replace("/","");
148+
149+
if (arg.Length - arg_slash_validation.Length > 1)
150+
{
151+
Console.WriteLine(sqlnexus.Properties.Resources.Msg_InvalidSwitch + arg.Substring(0,2));
152+
Console.WriteLine("Possible reason: An extra backslash exists at the end of " + arg.Substring(0, 2) + " parameter in your command");
153+
return false;
154+
}
155+
146156
switch (switchChar)
147157
{
148158
case 'C':
@@ -212,8 +222,11 @@ private static bool ProcessCmdLine(string[] args, ILogger logger)
212222
case 'I':
213223
{
214224
Console.WriteLine(@"Command Line Arg (/I): InputPath=" + arg.Substring(2));
215-
//fixing 2256
216-
String ipath = arg.Substring(2).Replace("\"", "");
225+
226+
String ipath = arg.Substring(2).Replace("\"", "").Trim();
227+
if (ipath.EndsWith(@"\"))
228+
ipath = ipath.Substring(0, ipath.Length-1);
229+
217230
Globals.PathsToImport.Enqueue(ipath);
218231
Globals.QuietNonInteractiveMode = true;
219232
break;
@@ -246,18 +259,23 @@ private static bool ProcessCmdLine(string[] args, ILogger logger)
246259

247260
if (!string.IsNullOrEmpty(Globals.credentialMgr.Database))
248261
{
262+
String currentDb = Globals.credentialMgr.Database;
249263
String CreateDB = string.Format(SQLScripts.CreateDB, Globals.credentialMgr.Database);
250264
Console.WriteLine("Creating Database" + CreateDB);
251265
//String connstring = string.Format("Data Source={0};Initial Catalog=master;Integrated Security=SSPI", Globals.credentialMgr.Server);
252266
//SqlConnection conn = new SqlConnection(connstring);
267+
268+
//set the db to 'master' to be able to create a new Nexus db
269+
Globals.credentialMgr.Database = "master";
253270
SqlConnection conn = new SqlConnection(Globals.credentialMgr.ConnectionString);
254271
conn.Open();
255272
SqlCommand cmd = conn.CreateCommand();
256273
cmd.CommandText = CreateDB;
257274

258275
cmd.ExecuteNonQuery();
259276

260-
277+
//reset the Nexus db name that the user selected
278+
Globals.credentialMgr.Database = currentDb;
261279
}
262280

263281
return true;

sqlnexus/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
// Build Number
3030
// Revision
3131
//
32-
[assembly: AssemblyVersion("7.21.03.26")]
33-
[assembly: AssemblyFileVersion("7.21.03.26")]
32+
[assembly: AssemblyVersion("7.21.05.17")]
33+
[assembly: AssemblyFileVersion("7.21.05.17")]

0 commit comments

Comments
 (0)