Skip to content

Instantly share code, notes, and snippets.

@ibnuh
Created March 12, 2019 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibnuh/5838b508d487e91b6b1430b115d0b3bd to your computer and use it in GitHub Desktop.
Save ibnuh/5838b508d487e91b6b1430b115d0b3bd to your computer and use it in GitHub Desktop.
Setup MiniProfiler for storing its data to database
CREATE TABLE MiniProfilers
(
RowId integer not null identity constraint PK_MiniProfilers primary key clustered, -- Need a clustered primary key for SQL Azure
Id uniqueidentifier not null, -- don't cluster on a guid
RootTimingId uniqueidentifier null,
Name nvarchar(200) null,
Started datetime not null,
DurationMilliseconds decimal(15,1) not null,
[User] nvarchar(100) null,
HasUserViewed bit not null,
MachineName nvarchar(100) null,
CustomLinksJson nvarchar(max),
ClientTimingsRedirectCount int null
);
-- displaying results selects everything based on the main MiniProfilers.Id column
CREATE UNIQUE NONCLUSTERED INDEX IX_MiniProfilers_Id ON MiniProfilers (Id);
-- speeds up a query that is called on every .Stop()
CREATE NONCLUSTERED INDEX IX_MiniProfilers_User_HasUserViewed_Includes ON MiniProfilers ([User], HasUserViewed) INCLUDE (Id, [Started]);
CREATE TABLE MiniProfilerTimings
(
RowId integer not null identity constraint PK_MiniProfilerTimings primary key clustered,
Id uniqueidentifier not null,
MiniProfilerId uniqueidentifier not null,
ParentTimingId uniqueidentifier null,
Name nvarchar(200) not null,
DurationMilliseconds decimal(15,3) not null,
StartMilliseconds decimal(15,3) not null,
IsRoot bit not null,
Depth smallint not null,
CustomTimingsJson nvarchar(max) null
);
CREATE UNIQUE NONCLUSTERED INDEX IX_MiniProfilerTimings_Id ON MiniProfilerTimings (Id);
CREATE NONCLUSTERED INDEX IX_MiniProfilerTimings_MiniProfilerId ON MiniProfilerTimings (MiniProfilerId);
CREATE TABLE MiniProfilerClientTimings
(
RowId integer not null identity constraint PK_MiniProfilerClientTimings primary key clustered,
Id uniqueidentifier not null,
MiniProfilerId uniqueidentifier not null,
Name nvarchar(200) not null,
Start decimal(9, 3) not null,
Duration decimal(9, 3) not null
);
CREATE UNIQUE NONCLUSTERED INDEX IX_MiniProfilerClientTimings_Id on MiniProfilerClientTimings (Id);
CREATE NONCLUSTERED INDEX IX_MiniProfilerClientTimings_MiniProfilerId on MiniProfilerClientTimings (MiniProfilerId);
public void ConfigureServices(IServiceCollection services){
services.AddMiniProfiler(options => options.Storage = new SqlServerStorage(<your connection string>));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment