Skip to content

Commit 3b2f93c

Browse files
Added StartupPerf view
1 parent 13bfb16 commit 3b2f93c

File tree

7 files changed

+103
-20
lines changed

7 files changed

+103
-20
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using EPiServer.Cms.Shell.UI.Controllers.Internal;
4+
using EPiServer.DeveloperTools.Models;
5+
using EPiServer.Framework.Initialization;
6+
using Microsoft.AspNetCore.Mvc;
7+
8+
namespace EPiServer.DeveloperTools.Controllers;
9+
10+
public class StartupPerfController : BaseController
11+
{
12+
[HttpGet]
13+
public ActionResult Index()
14+
{
15+
var allTimers = TimeMeters.GetAllRegistered();
16+
17+
// flatten the list
18+
var result = new List<TimeMetersModel>();
19+
result.AddRange(ConvertToModel(allTimers));
20+
21+
return View("Index", result.OrderByDescending(t => t.ElapsedMilliseconds));
22+
}
23+
24+
private IEnumerable<TimeMetersModel> ConvertToModel(IEnumerable<TimeMeters> allTimers)
25+
{
26+
foreach (var timer in allTimers)
27+
{
28+
foreach (var counter in timer.Counters)
29+
{
30+
yield return new TimeMetersModel
31+
{
32+
AssemblyName = timer.Owner.Assembly.GetName().Name,
33+
TypeName = timer.Owner.Name,
34+
MethodName = counter.Key,
35+
ElapsedMilliseconds = counter.Value.ElapsedMilliseconds
36+
};
37+
}
38+
}
39+
}
40+
}

DeveloperTools/Controllers/TimeMetersController.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
Welcome to EPiServer.DeveloperTools!
2-
3-
USE AT YOUR OWN RISK!
1+
<h1>Welcome to EPiServer.DeveloperTools!</h1>
2+
<h2>USE AT YOUR OWN RISK!</h2>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@model IEnumerable<EPiServer.DeveloperTools.Models.TimeMetersModel>
2+
3+
<div class="epi-contentArea">
4+
<h1 class="EP-prefix">Startup Performance</h1>
5+
<p>Displays timing measurements from the initialization process, can be used to find modules causing slow startups.</p>
6+
<p>Number of time meters: <strong>@Model.Count()</strong>. Total time: <strong>@TimeSpan.FromMilliseconds(Model.Sum(tm => tm.ElapsedMilliseconds)).TotalSeconds.ToString("N") s</strong>.</p>
7+
</div>
8+
<div class="epi-formArea">
9+
<table cellpadding="0" cellspacing="0" border="0" class="display" id="theList">
10+
<thead>
11+
<tr>
12+
<th align="left">Assembly</th>
13+
<th align="left">Type</th>
14+
<th align="left">Action</th>
15+
<th>Time (ms)</th>
16+
</tr>
17+
</thead>
18+
<tbody>
19+
@foreach (var m in Model)
20+
{
21+
<tr>
22+
<td>@m.AssemblyName</td>
23+
<td>@m.TypeName</td>
24+
<td>@m.MethodName</td>
25+
<td>@m.ElapsedMilliseconds</td>
26+
</tr>
27+
}
28+
</tbody>
29+
</table>
30+
</div>
31+
32+
@section AdditionalScripts {
33+
<script>
34+
$(document).ready(function () {
35+
$('#theList').dataTable(
36+
{
37+
"aaSorting": [[3, "desc"]],
38+
"bPaginate": false,
39+
"bLengthChange": false,
40+
"bFilter": true,
41+
"bSort": true,
42+
"bInfo": false,
43+
"bAutoWidth": true
44+
});
45+
});
46+
</script>
47+
}

DeveloperTools/EPiServer.DeveloperTools.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
</None>
4545
</ItemGroup>
4646

47+
<ItemGroup>
48+
<Folder Include="EPiServer.DeveloperTools.Views\Views\StartupPerf\" />
49+
</ItemGroup>
50+
4751
<PropertyGroup>
4852
<PostBuildEvent>powershell.exe -noexit -file "$(ProjectDir)copy-to-sandbox.ps1"</PostBuildEvent>
4953
</PropertyGroup>

DeveloperTools/Infrastructure/MenuProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected virtual UrlMenuItem CreateUrlMenuItem(string title, string path, int i
4646
var link = new UrlMenuItem(
4747
title,
4848
MenuPaths.Global + MenuPath + "/" + path,
49-
Paths.ToResource(GetType(), "/" + path))
49+
Paths.ToResource(GetType(), path))
5050
{
5151
AuthorizationPolicy = Constants.PolicyName,
5252
SortIndex = index,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace EPiServer.DeveloperTools.Models;
2+
3+
public class TimeMetersModel
4+
{
5+
public string AssemblyName { get; set; }
6+
public string TypeName { get; set; }
7+
public string MethodName { get; set; }
8+
public long ElapsedMilliseconds { get; set; }
9+
}

0 commit comments

Comments
 (0)