背景
在开发一个webapi项目,使用了Swagger首页展示Http接口。为了测试、提升接口性能,现在对接口加入分析工具。
MiniProfiler是一款很好的轻量级性能分析工具,提供库和UI。通过它可以查看程序的时间消耗,提供程序调试和性能优化帮助。
MiniProfiler is a library and UI for profiling your application. By letting you see where your time is spent, which queries are run, and any other custom timings you want to add, MiniProfiler helps you debug issues and optimize performance.
1、安装Nuget包
Install-Package MiniProfiler.AspNetCore.Mvc
2、注册和启用MiniProfiler
public void ConfigureServices(IServiceCollection services)
{
/*
* 其他代码
*/
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1.0",
Title = "GDWC.Core.API",
Description = "说明文档",
TermsOfService = null,
Contact = new OpenApiContact
{
Name = "GDWC.Core",
Email = "",
Url = new Uri("http://www.whfhjc.com.cn/"),
}
});
services.AddMiniProfiler(option =>
{
option.RouteBasePath = "/profiler";
//(option.Storage as MemoryCacheStorage).CacheDuration = TimeSpan.FromMinutes(10);
});
/*
* 其他代码