SSRS report Chart

Here I come with post where I create graph that displays results from my testing lab I described in previous post. Reporting Services offers lots of possibilities of data visualisations. Graphs are basic components for scenarios you need to visualise your data.

File -> New -> Project

Project menu
Picture 1 – Project menu

Continue with Business Intelligence -> Reporting Services -> Report Server Project. At the bottom part of New Project window set Project Name and its location.

New project
Picture 2 – New project

New empty Report Server project was created.

Add New Report, right click Reports in Solution Explorer.

Solution Explorer
Picture 3 – Solution Explorer

Go to Toolbox pane and click on Chart component.

Toolbox
Picture 4 – Toolbox

Select Bar Chart type from chart palette.

Chart Type
Picture 5 – Chart Type

New Chart component is added into the Visual Studio design area.

Chart
Picture 6 – Chart

Right click on Chart to get Chart Properties dialog box. Map Chart to its dataset. Select GetData dataset from Dataset name select box.

Chart properties
Picture 7 – Chart properties
Chart properties
Picture 8 – Chart properties

Our goal is to get something similar on picture bellow. We want to get results from our tests. It will be grouped by categories represented by tested counters. Set each scenario to chart series.

Chart
Picture 9 – Chart

When you click on chart component you get Chart Data dialog box on the right side.

  • In Values section select CounterValue, results from our tests.
  • Set CounterName to Category Groups to get testing perspective of our data, counters.
  • TaskOwnerName will be set as Series Groups, scenarios we tested
Chart data
Picture 10 – Chart data

Finally, we got simple chart as on picture bellow.

 Chart
Picture 11 – Chart

Reporting Services Chart is very complex component. I didn’t show all its possibilities it has. In this post I created the simplest one Chart to represented lab data.

Get data to lab report

In this post we continue with lab series. I fill prepare structures with tested data. To collect testing results I will use Extended Events, Extended Events utility from this post.

In post we will demonstrate very simple demonstration of clustered index impact on query performance. One table will be created with clustered index and one table stay as heap. After filling tables with data, we start Extended Event Session and run two queries against created tables. When queries finish, we collect the data to lab structure we created in previous post and stop and clean sessions.

Let’s prepare lab structures first.

CREATE TABLE dbo.TestTableData
(id INT )
 
CREATE TABLE dbo.TestTableDatClustered
(id INT PRIMARY KEY CLUSTERED
)
 
INSERT INTO dbo.TestTableData
SELECT TOP 1000000 ROW_NUMBER() OVER (ORDER BY (SELECT 1)) rn 
FROM sys.objects a
JOIN sys.objects b ON 1=1
JOIN sys.objects c ON 1=1
 
INSERT INTO dbo.TestTableDatClustered
SELECT TOP 1000000 ROW_NUMBER() OVER (ORDER BY (SELECT 1)) rn 
FROM sys.objects a
JOIN sys.objects b ON 1=1
JOIN sys.objects c ON 1=1

Clean cache and get SPID.

SELECT @@SPID
DBCC FREEPROCCACHE
CHECKPOINT
DBCC DROPCLEANBUFFERS

Open new query window and start session with the utility.Extended events monitoring utility

Create and start session.

/*Lets start event session*/ EXEC mnt.MNT_SessionHandler 'CreateSession;StartSession','Test','QueryPlan;IOStat','<Predicate><DatabaseID>5</DatabaseID></Predicate>' /*Lets start events*/

Run test queries.

SELECT * FROM dbo.TestTableData WHERE Id = 1000
SELECT * FROM dbo.TestTableDatClustered WHERE Id = 1000

Get data from Session to temporary table.

EXEC mnt.MNT_SessionHandler 'GetDataFromSession' ,'Test','IOStat;QueryPlan' /*Run query you would like to analyze*/  

Let’s clean up the extended event session.

/*Stop session*/ EXEC mnt.MNT_SessionHandler 'EndSession', 'Test' /*clean session*/ EXEC mnt.MNT_SessionHandler 'CleanSession', 'Test' /*Or all in one raw*/ EXEC mnt.MNT_SessionHandler 'CleanSession;EndSession', 'Test' /*Get data to analyze,lets make your own views, predicates... */ SELECT * FROM ##Test

In the script bellow the data from extended events are stored to Lab structures.

 
INSERT INTO dbo.LabTable
( [CounterValue],[CounterName],[TaskOwnerName], [WorkoutName] )
SELECT CPUTime/ 1000,'CPUTime (sec)', SqlText,'ClusteredIndexTest'
FROM dbo.##Test WHERE SqlText = ' SELECT * FROM dbo.TestTableData WHERE Id = 1000'
AND [Type] = 'QueryPlan'
INSERT INTO dbo.LabTable
( [CounterValue],[CounterName],[TaskOwnerName], [WorkoutName] )
SELECT Duration/ 1000,'Duration (sec)', SqlText,'ClusteredIndexTest'
FROM dbo.##Test WHERE SqlText = ' SELECT * FROM dbo.TestTableData WHERE Id = 1000'
AND [Type] = 'QueryPlan'
INSERT INTO dbo.LabTable
( [CounterValue],[CounterName],[TaskOwnerName], [WorkoutName] )
SELECT PhysicalReads,'PhysicalReads (pages)', SqlText,'ClusteredIndexTest'
FROM dbo.##Test WHERE SqlText = ' SELECT * FROM dbo.TestTableData WHERE Id = 1000' AND [Type] = 'IOSql'
INSERT INTO dbo.LabTable
( [CounterValue],[CounterName],[TaskOwnerName], [WorkoutName] )
SELECT LogicalReads,'LogicalReads (pages)', SqlText,'ClusteredIndexTest'
FROM dbo.##Test WHERE SqlText = ' SELECT * FROM dbo.TestTableData WHERE Id = 1000' AND [Type] = 'IOSql'
 
INSERT INTO dbo.LabTable( [CounterValue],[CounterName],[TaskOwnerName], [WorkoutName] )
SELECT CPUTime/ 1000,'CPUTime (sec)', SqlText,'ClusteredIndexTest'
FROM dbo.##Test WHERE SqlText LIKE '%dbo.TestTableDatClustered%' AND [Type] = 'QueryPlan'
INSERT INTO dbo.LabTable ( [CounterValue],[CounterName],[TaskOwnerName], [WorkoutName] )
SELECT Duration/ 1000,'Duration (sec)', SqlText,'ClusteredIndexTest'
FROM dbo.##Test WHERE SqlText LIKE '%dbo.TestTableDatClustered%' AND [Type] = 'QueryPlan'

INSERT INTO dbo.LabTable ( [CounterValue],[CounterName],[TaskOwnerName], [WorkoutName] )
SELECT PhysicalReads,'PhysicalReads (pages)', SqlText,'ClusteredIndexTest'
FROM dbo.##Test WHERE SqlText LIKE '%dbo.TestTableDatClustered%' AND [Type] = 'IOSql'

INSERT INTO dbo.LabTable ( [CounterValue],[CounterName],[TaskOwnerName], [WorkoutName] )
SELECT LogicalReads,'LogicalReads (pages)', SqlText,'ClusteredIndexTest'
FROM dbo.##Test WHERE SqlText LIKE '%dbo.TestTableDatClustered%' AND [Type] = 'IOSql'

In next post we visualise the data in SSRS chart, so stay tuned.

Get data to lab report

I started with series of post, I would like to show how to prepare simple testing environment, you can get the data when you test or compare queries performance for example, and you would like to save results and visualise them.

In this post we create simple table structure and SQL procedure which will be used in next post as Chart dataset.

I would like to save following information’s:

  • Test identification – identification of test – for example testing clustered vs nanocluster index, sorting group vs hash group, etc.
  • Task name – identification of task we made in test – for example task1 = table with clustered index, task2 heap table
  • Counter name (for example number of reads, writes, rows, etc.)
  • Counter value – measured results of tests

As you can see the structure is very simple, I believe we could design much sophisticated solution but for our purposes will be enough. Next time we can extend our solution.

Here is the final structure:

SET
ANSI_NULLS
ON
GO
SET
QUOTED_IDENTIFIER
ON
GO
 
CREATE TABLE [dbo].[LabTable](
    [WorkoutName] [sysname] NOT NULL,
    [TaskOwnerName] [sysname] NOT NULL,
    [CounterName] [sysname] NOT NULL,
    [CounterValue] [sql_variant] NULL,
    [InsertDateTime] [datetime] NULL
)
ON [PRIMARY]
GO
 
ALTER
TABLE [dbo].[LabTable] ADD
CONSTRAINT [df_InsertDateTime] DEFAULT (getdate())
FOR [InsertDateTime]
GO

Stored procedure returning data to dataset:

SET
ANSI_NULLS
ON
GO
SET QUOTED_IDENTIFIER ON
GO
 
CREATE PROCEDURE [dbo].[SSRSGetDatset]
@WorkoutName SYSNAME
AS
BEGIN
SELECT WorkoutName,
     TaskOwnerName,
     CounterName,
     TRY_CONVERT(BIGINT,TRY_CONVERT(DATETIME, CounterValue))
AS CounterValue,
     InsertDateTime
FROM dbo.LabTable
WHERE WorkoutName = @WorkoutName
END
GO

In next post we fill structures with tested data and create graph to visualise our results. Stay tuned.