-
Notifications
You must be signed in to change notification settings - Fork 0
/
perf_export.sql
112 lines (105 loc) · 4.81 KB
/
perf_export.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
-- To obtain Performance Counters to view within Perfmon
-- From http://blogs.msdn.com/b/geoffgr/archive/2013/09/09/how-to-export-perfmon-counter-values-from-the-visual-studio-load-test-results-database.aspx
--START CODE--
CREATE PROCEDURE TSL_prc_PerfCounterCollectionInCsvFormat
@RunId nvarchar(10),
@InstanceName nvarchar(1024)
AS
DECLARE @CounterName nvarchar(max), @CounterNameColumns nvarchar(max)
--Get List of columns to use in query. Shove them into a single long XML string
SELECT @CounterNameColumns = (
SELECT ', [' + REPLACE(InstanceName, ']', ']]') + ']' FROM MTSL_View_PerfmonInstanceNamesAndIds
WHERE LoadTestRunId = @RunId
AND InstanceName LIKE @InstanceName
FOR XML PATH(''))
--Make a copy of the list WITHOUT the comma at the very beginning of the string
SELECT @CounterName = RIGHT(@CounterNameColumns, LEN(@CounterNameColumns) - 1)
-- Use the previous strings to build the query string that can be pivoted
DECLARE @SQL nvarchar(max)
SELECT @SQL = N'
select
IntervalStartTime AS [(PDH-CSV 4.0) (Eastern Daylight Time)(240)]' +
--IntervalStartTime' +
@CounterNameColumns + '
from (
select
interval.IntervalStartTime,
MTSL_View_PerfmonInstanceNamesAndIds.InstanceName,
countersample.ComputedValue
FROM
MTSL_View_PerfmonInstanceNamesAndIds
INNER JOIN LoadTestPerformanceCounterSample AS countersample
ON countersample.InstanceId = MTSL_View_PerfmonInstanceNamesAndIds.InstanceId
AND countersample.LoadTestRunId = MTSL_View_PerfmonInstanceNamesAndIds.LoadTestRunId
INNER JOIN LoadTestRunInterval AS interval
ON interval.LoadTestRunId = countersample.LoadTestRunId
AND interval.TestRunIntervalId = countersample.TestRunIntervalId
WHERE
MTSL_View_PerfmonInstanceNamesAndIds.LoadTestRunId = ' + @RunId + '
AND
MTSL_View_PerfmonInstanceNamesAndIds.InstanceName LIKE '''+@InstanceName+'''
) Data
PIVOT (
SUM(ComputedValue)
FOR InstanceName
IN (
' + @CounterName + '
)
) PivotTable
ORDER BY IntervalStartTime ASC
'
-- print @SQL
-- Execute the generated query
exec sp_executesql @SQL
GO
--START CODE--
GRANT EXECUTE ON TSL_prc_PerfCounterCollectionInCsvFormat TO PUBLIC
GO
/*===============================================================================
MTSL_View_PerfmonInstanceNamesAndIds
===============================================================================*/
CREATE VIEW MTSL_View_PerfmonInstanceNamesAndIds AS
SELECT
instance.LoadTestRunId
,instance.InstanceId
,(
'\\' + RIGHT(category.MachineName,6)
+ '\' + category.CategoryName
+ case instance.InstanceName when 'systemdiagnosticsperfcounterlibsingleinstance'
then ''
else '(' + instance.InstanceName + ')'
end
+ '\' + counter.CounterName
) AS InstanceName
FROM LoadTestPerformanceCounterCategory AS category
INNER JOIN LoadTestPerformanceCounter AS counter
ON category.LoadTestRunId = counter.LoadTestRunId
AND category.CounterCategoryId = counter.CounterCategoryId
INNER JOIN LoadTestPerformanceCounterInstance AS instance
ON counter.CounterId = instance.CounterId
AND counter.LoadTestRunId = instance.LoadTestRunId
GO
/*===============================================================================
LoadTestRuns
Describe: Returns LoadTestRuns stored in the database
Example: SELECT * FROM LoadTestRuns ORDER BY LoadTestRunId DESC
===============================================================================*/
IF OBJECT_ID ('LoadTestRuns', 'V') IS NOT NULL
DROP VIEW LoadTestRuns
GO
CREATE VIEW LoadTestRuns
AS
SELECT LoadTestRunId,
LoadTestName
,StartTime
,EndTime
,RunDuration
,Outcome
FROM LoadTestRun LTR
GROUP BY LoadTestRunId,
LoadTestName
,StartTime
,EndTime
,RunDuration
,Outcome
--ORDER BY StartTime DESC