本文整理汇总了C#中MiniProfiler类的典型用法代码示例。如果您正苦于以下问题:C# MiniProfiler类的具体用法?C# MiniProfiler怎么用?C# MiniProfiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MiniProfiler类属于命名空间,在下文中一共展示了MiniProfiler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestRangeQueries
public void TestRangeQueries()
{
var now = DateTime.UtcNow;
var inASec = now.AddSeconds(1);
var in2Secs = now.AddSeconds(2);
var in3Secs = now.AddSeconds(3);
var profiler = new MiniProfiler { Started = now, Id = Guid.NewGuid() };
var profiler1 = new MiniProfiler { Started = inASec, Id = Guid.NewGuid() };
var profiler2 = new MiniProfiler { Started = in2Secs, Id = Guid.NewGuid() };
var profiler3 = new MiniProfiler { Started = in3Secs, Id = Guid.NewGuid() };
var storage = new HttpRuntimeCacheStorage(new TimeSpan(1, 0, 0));
storage.Save(profiler);
storage.Save(profiler3);
storage.Save(profiler2);
storage.Save(profiler1);
var guids = storage.List(100);
Assert.AreEqual(4, guids.Count());
guids = storage.List(1);
Assert.AreEqual(1, guids.Count());
guids = storage.List(2, now, in2Secs, ListResultsOrder.Decending);
Assert.AreEqual(profiler2.Id, guids.First());
Assert.AreEqual(profiler1.Id, guids.Skip(1).First());
Assert.AreEqual(2, guids.Count());
}
开发者ID:nightbob3,项目名称:MiniProfiler,代码行数:29,代码来源:TestHttpRuntimeCacheStorage.cs
示例2: RavenTiming
public RavenTiming(RequestResultArgs request, MiniProfiler profiler)
: base(profiler, null, null)
{
if (profiler == null) throw new ArgumentNullException("profiler");
_requestUrl = request.Url;
var commandTextBuilder = new StringBuilder();
// Basic request information
// HTTP GET - 200 (Cached)
commandTextBuilder.AppendFormat("HTTP {0} - {1} ({2})\n",
request.Method,
request.HttpResult,
request.Status);
// Request URL
commandTextBuilder.AppendFormat("{0}\n\n", FormatUrl());
// Append query
var query = FormatQuery();
if (!String.IsNullOrWhiteSpace(query)) {
commandTextBuilder.AppendFormat("{0}\n\n", query);
}
// Append POSTed data, if any (multi-get, PATCH, etc.)
if (!String.IsNullOrWhiteSpace(request.PostedData))
{
commandTextBuilder.Append(request.PostedData);
}
// Set the command string to a formatted string
CommandString = commandTextBuilder.ToString();
}
开发者ID:CedarLogic,项目名称:dotnet,代码行数:34,代码来源:RavenTiming.cs
示例3: Save
public void Save(MiniProfiler profiler)
{
var context = WcfInstanceContext.Current;
// Do nothing if we are not being called inside a WCF method
// Alternatively, this could throw an Exception
if (context == null)
return;
context.Items[GetCacheKey(profiler.Id)] = profiler;
}
开发者ID:feanz,项目名称:MiniProfiler,代码行数:10,代码来源:WcfRequestInstanceStorage.cs
示例4: TestWeCanSaveTheSameProfilerTwice
public void TestWeCanSaveTheSameProfilerTwice()
{
var profiler = new MiniProfiler("/") { Started = DateTime.UtcNow, Id = Guid.NewGuid() };
var storage = new HttpRuntimeCacheStorage(new TimeSpan(1, 0, 0));
storage.Save(profiler);
storage.Save(profiler);
var guids = storage.List(100).ToArray();
Assert.AreEqual(profiler.Id, guids.First());
Assert.AreEqual(1, guids.Count());
}
开发者ID:BiYiTuan,项目名称:dotnet,代码行数:10,代码来源:TestHttpRuntimeCacheStorage.cs
示例5: Save
/// <summary>
/// Stores <paramref name="profiler"/> under its <see cref="MiniProfiler.Id"/>.
/// </summary>
/// <param name="profiler">The results of a profiling session.</param>
/// <remarks>
/// Should also ensure the profiler is stored as being un-viewed by its profiling <see cref="MiniProfiler.User"/>.
/// </remarks>
public void Save(MiniProfiler profiler)
{
// ignore browerLink URL, i.e. "/__browserLink/requestData/44067061dcd44ffcbbca1da"
if (profiler.Name == null || profiler.Name.Contains("__browserLink"))
return;
// Convert the path into something that plays better with Graphite, i.e. "Home/MinSaveMs" -> "Home.MinSaveMs"
Metrics.Timer(
profiler.Name.Replace("/", "."),
(int)profiler.DurationMilliseconds);
}
开发者ID:mattwarren,项目名称:dotnet,代码行数:18,代码来源:GraphiteStorage.cs
示例6: HandleResponse
/// <summary>
/// Handles <see cref="IElasticsearchResponse"/> and pushes <see cref="CustomTiming"/> to current <see cref="MiniProfiler"/> session.
/// </summary>
/// <param name="response"><see cref="IElasticsearchResponse"/> to be handled.</param>
/// <param name="profiler">Current <see cref="MiniProfiler"/> session instance.</param>
internal static void HandleResponse(IElasticsearchResponse response, MiniProfiler profiler)
{
if (profiler == null || profiler.Head == null || response.Metrics == null)
return;
profiler.Head.AddCustomTiming("elasticsearch", new CustomTiming(profiler, BuildCommandString(response))
{
Id = Guid.NewGuid(),
DurationMilliseconds = response.Metrics.Requests.Sum(c => c.EllapsedMilliseconds),
ExecuteType = response.RequestMethod,
});
}
开发者ID:bigerock,项目名称:MiniProfiler.Elasticsearch,代码行数:17,代码来源:MiniProfilerElasticsearch.cs
示例7: RenderIncludes
internal static HtmlString RenderIncludes(MiniProfiler profiler, RenderPosition? position = null, bool? showTrivial = null, bool? showTimeWithChildren = null, int? maxTracesToShow = null, bool xhtml = false, bool? showControls = null)
{
const string format =
@"<link rel=""stylesheet"" type=""text/css"" href=""{path}mini-profiler-includes.css?v={version}""{closeXHTML}>
<script type=""text/javascript"">
if (!window.jQuery) document.write(unescape(""%3Cscript src='{path}mini-profiler-jquery.1.6.2.js' type='text/javascript'%3E%3C/script%3E""));
if (!window.jQuery || !window.jQuery.tmpl) document.write(unescape(""%3Cscript src='{path}mini-profiler-jquery.tmpl.beta1.js' type='text/javascript'%3E%3C/script%3E""));
</script>
<script type=""text/javascript"" src=""{path}mini-profiler-includes.js?v={version}""></script>
<script type=""text/javascript"">
jQuery(function() {{
MiniProfiler.init({{
ids: {ids},
path: '{path}',
version: '{version}',
renderPosition: '{position}',
showTrivial: {showTrivial},
showChildrenTime: {showChildren},
maxTracesToShow: {maxTracesToShow},
showControls: {showControls}
}});
}});
</script>";
var result = "";
if (profiler != null)
{
// HACK: unviewed ids are added to this list during Storage.Save, but we know we haven't see the current one yet,
// so go ahead and add it to the end - it's usually the only id, but if there was a redirect somewhere, it'll be there, too
MiniProfiler.Settings.EnsureStorageStrategy();
var ids = MiniProfiler.Settings.Storage.GetUnviewedIds(profiler.User);
ids.Add(profiler.Id);
result = format.Format(new
{
//path = VirtualPathUtility.ToAbsolute(MiniProfiler.Settings.RouteBasePath).EnsureTrailingSlash(),
path = "",
version = MiniProfiler.Settings.Version,
ids = ids.ToJson(),
position = (position ?? MiniProfiler.Settings.PopupRenderPosition).ToString().ToLower(),
showTrivial = showTrivial ?? MiniProfiler.Settings.PopupShowTrivial ? "true" : "false",
showChildren = showTimeWithChildren ?? MiniProfiler.Settings.PopupShowTimeWithChildren ? "true" : "false",
maxTracesToShow = maxTracesToShow ?? MiniProfiler.Settings.PopupMaxTracesToShow,
closeXHTML = xhtml ? "/" : "",
showControls = showControls ?? MiniProfiler.Settings.ShowControls ? "true" : "false"
});
}
return new HtmlString(result);
}
开发者ID:7sharp9,项目名称:ServiceStack,代码行数:51,代码来源:MiniProfilerHandler.cs
示例8: Save
/// <summary>
/// Stores <paramref name="profiler"/> under its <see cref="MiniProfiler.Id"/> in all of the <see cref="Stores"/>.
/// </summary>
/// <param name="profiler">The results of a profiling session.</param>
/// <remarks>
/// Should also ensure the profiler is stored as being un-viewed by its profiling <see cref="MiniProfiler.User"/>.
/// </remarks>
public void Save(MiniProfiler profiler)
{
if (Stores != null)
{
if (AllowParallelOps)
{
Parallel.ForEach(Stores, x => x.Save(profiler));
}
else
{
Stores.ForEach(x => x.Save(profiler));
}
}
}
开发者ID:CurufinweU,项目名称:dotnet,代码行数:21,代码来源:MultiStorageProvider.cs
示例9: GetProfiler
public MiniProfiler GetProfiler()
{
// does a profiler already exist for this request?
var profiler = HttpContext.GetProfiler();
if (profiler != null) return profiler;
// might want to decide here (or maybe inside the action) whether you want
// to profile this request - for example, using an "IsSystemAdmin" flag against
// the user, or similar; this could also all be done in action filters, but this
// is simple and practical; just return null for most users. For our test, we'll
// profiler only for local requests (seems reasonable)
//if (Request.IsLocal)
//{
profiler = new MiniProfiler(Request.Url.OriginalString);
HttpContext.SetProfiler(profiler);
//}
return profiler;
}
开发者ID:datachomp,项目名称:StackOverFaux,代码行数:18,代码来源:BaseController.cs
示例10: MongoTiming
/// <summary>
/// Creates a new SqlTiming to profile 'command'.
/// </summary>
public MongoTiming(string collectionName, string command, ExecuteType type, MiniProfiler profiler)
{
Id = Guid.NewGuid();
CollectionName = collectionName;
CommandString = command;
ExecuteType = type;
if (!MiniProfiler.Settings.ExcludeStackTraceSnippetFromSqlTimings)
StackTraceSnippet = Helpers.StackTraceSnippet.Get();
_profiler = profiler;
if (_profiler != null)
{
_profiler.AddMongoTiming(this);
_startTicks = _profiler.ElapsedTicks;
StartMilliseconds = _profiler.GetRoundedMilliseconds(_startTicks);
}
}
开发者ID:brycekahle,项目名称:MiniProfiler,代码行数:22,代码来源:MongoTiming.cs
示例11: Start
/// <summary>
/// start the profiler.
/// </summary>
/// <param name="level">The profile level.</param>
/// <returns>the mini profiler.</returns>
public override MiniProfiler Start(ProfileLevel level, string sessionName = null)
{
var context = WcfInstanceContext.Current;
if (context == null) return null;
var operationContext = OperationContext.Current;
if (operationContext == null) return null;
var instanceContext = operationContext.InstanceContext;
if (instanceContext == null) return null;
// TODO: Include the action name here as well, and null protection
string serviceName = instanceContext.Host.Description.Name;
// BaseAddresses.FirstOrDefault();
// TODO: Ignored paths - currently solely based on servicename
// var url = context.Request.Url;
// var path = context.Request.AppRelativeCurrentExecutionFilePath.Substring(1);
// don't profile /content or /scripts, either - happens in web.dev
foreach (var ignored in MiniProfiler.Settings.IgnoredPaths ?? new string[0])
{
if (serviceName.ToUpperInvariant().Contains((ignored ?? string.Empty).ToUpperInvariant()))
return null;
}
var result = new MiniProfiler(sessionName ?? GetProfilerName(operationContext, instanceContext), level);
SetCurrentProfiler(result);
// don't really want to pass in the context to MiniProfler's constructor or access it statically in there, either
result.User = (Settings.UserProvider ?? new EmptyUserProvider()).GetUser(/*context.Request*/);
SetProfilerActive(result);
return result;
}
开发者ID:haroonxml,项目名称:dotnet,代码行数:43,代码来源:WcfRequestProfilerProvider.cs
示例12: MapTimings
/// <summary>
/// Giving freshly selected collections, this method puts them in the correct
/// hierarchy under the 'result' MiniProfiler.
/// </summary>
protected void MapTimings(MiniProfiler result, List<Timing> timings, List<SqlTiming> sqlTimings, List<SqlTimingParameter> sqlParameters)
{
var stack = new Stack<Timing>();
for (int i = 0; i < timings.Count; i++)
{
var cur = timings[i];
foreach (var sqlTiming in sqlTimings)
{
if (sqlTiming.ParentTimingId == cur.Id)
{
cur.AddSqlTiming(sqlTiming);
var parameters = sqlParameters.Where(p => p.ParentSqlTimingId == sqlTiming.Id);
if (parameters.Count() > 0)
{
sqlTiming.Parameters = parameters.ToList();
}
}
}
if (stack.Count > 0)
{
Timing head;
while ((head = stack.Peek()).Id != cur.ParentTimingId)
{
stack.Pop();
}
head.AddChild(cur);
}
stack.Push(cur);
}
// TODO: .Root does all the above work again, but it's used after [DataContract] deserialization; refactor it out somehow
result.Root = timings.First();
}
开发者ID:TheProjecter,项目名称:seanhederman-rest-wcf-support,代码行数:41,代码来源:DatabaseStorageBase.cs
示例13: ResultsFullPage
/// <summary>
/// results full page.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="profiler">The profiler.</param>
/// <returns>a string containing the results page</returns>
private static string ResultsFullPage(HttpContext context, MiniProfiler profiler)
{
context.Response.ContentType = "text/html";
var template = GetResource("share.html");
return template.Format(new
{
name = profiler.Name,
duration = profiler.DurationMilliseconds.ToString(CultureInfo.InvariantCulture),
path = VirtualPathUtility.ToAbsolute(MiniProfiler.Settings.RouteBasePath).EnsureTrailingSlash(),
json = MiniProfiler.ToJson(profiler),
includes = RenderIncludes(profiler),
version = MiniProfiler.Settings.Version
});
}
开发者ID:NGPVAN,项目名称:MiniProfiler,代码行数:21,代码来源:MiniProfilerHandler.cs
示例14: RenderIncludes
/// <summary>
/// Renders script tag found in "include.partial.html" - this is shared with all other language implementations, so if you change it, you MUST
/// provide changes for those other implementations, e.g. ruby.
/// </summary>
internal static HtmlString RenderIncludes(
MiniProfiler profiler,
RenderPosition? position = null,
bool? showTrivial = null,
bool? showTimeWithChildren = null,
int? maxTracesToShow = null,
bool? showControls = null,
bool? startHidden = null)
{
if (profiler == null) return new HtmlString("");
MiniProfiler.Settings.EnsureStorageStrategy();
var authorized = MiniProfiler.Settings.Results_Authorize == null || MiniProfiler.Settings.Results_Authorize(HttpContext.Current.Request);
// unviewed ids are added to this list during Storage.Save, but we know we haven't see the current one yet, so go ahead and add it to the end
var ids = authorized ? MiniProfiler.Settings.Storage.GetUnviewedIds(profiler.User) : new List<Guid>();
ids.Add(profiler.Id);
var format = GetResource("include.partial.html");
var result = format.Format(new
{
path = VirtualPathUtility.ToAbsolute(MiniProfiler.Settings.RouteBasePath).EnsureTrailingSlash(),
version = MiniProfiler.Settings.Version,
ids = string.Join(",", ids.Select(guid => guid.ToString())),
position = (position ?? MiniProfiler.Settings.PopupRenderPosition).ToString().ToLower(),
showTrivial = (showTrivial ?? MiniProfiler.Settings.PopupShowTrivial).ToJs(),
showChildren = (showTimeWithChildren ?? MiniProfiler.Settings.PopupShowTimeWithChildren).ToJs(),
maxTracesToShow = maxTracesToShow ?? MiniProfiler.Settings.PopupMaxTracesToShow,
showControls = (showControls ?? MiniProfiler.Settings.ShowControls).ToJs(),
currentId = profiler.Id,
authorized = authorized.ToJs(),
toggleShortcut = MiniProfiler.Settings.PopupToggleKeyboardShortcut,
startHidden = (startHidden ?? MiniProfiler.Settings.PopupStartHidden).ToJs()
});
return new HtmlString(result);
}
开发者ID:NGPVAN,项目名称:MiniProfiler,代码行数:41,代码来源:MiniProfilerHandler.cs
示例15: SetCurrentProfiler
/// <summary>
/// set the current profiler.
/// </summary>
/// <param name="profiler">The profiler.</param>
private void SetCurrentProfiler(MiniProfiler profiler)
{
var context = WcfInstanceContext.Current;
if (context == null) return;
context.Items[WcfCacheKey] = profiler;
}
开发者ID:haroonxml,项目名称:dotnet,代码行数:11,代码来源:WcfRequestProfilerProvider.cs
示例16: SaveSqlTimingParameters
/// <summary>
/// Saves parameter Timing to the sqltimingparams collection.
/// </summary>
private void SaveSqlTimingParameters(MiniProfiler profiler, SqlTiming s)
{
foreach (var p in s.Parameters)
{
var sqltimingParamPoco = new SqlTimingParameterPoco
{
MiniProfilerId = profiler.Id.ToString(),
ParentSqlTimingId = s.Id.ToString(),
Name = Truncate(p.Name, 150),
DbType = Truncate(p.DbType, 50),
Size = p.Size,
Value = p.Value
};
SqlTimingParams.Insert(sqltimingParamPoco);
}
}
开发者ID:brycekahle,项目名称:MiniProfiler,代码行数:20,代码来源:MongoDbStorage.cs
示例17: SaveClientTiming
private void SaveClientTiming(MiniProfiler profiler)
{
if (profiler.ClientTimings == null || profiler.ClientTimings.Timings == null || profiler.ClientTimings.Timings.Count == 0) return;
foreach (var ct in profiler.ClientTimings.Timings)
{
ClientTimings.Save(new ClientTimingPoco
{
Id = profiler.Id.ToString(),
Name = ct.Name,
Start = (double)ct.Start,
Duration = (double)ct.Duration
});
}
}
开发者ID:brycekahle,项目名称:MiniProfiler,代码行数:15,代码来源:MongoDbStorage.cs
示例18: Load
/// <summary>
/// Loads the MiniProfiler identifed by 'id' from the database.
/// </summary>
public override MiniProfiler Load(Guid id)
{
var query = Query.EQ("_id", id.ToString());
var profilerPoco = Profilers.FindOne(query);
if (profilerPoco != null)
{
var profiler = new MiniProfiler
{
Id = Guid.Parse(profilerPoco.Id),
Name = profilerPoco.Name,
Started = profilerPoco.Started,
MachineName = profilerPoco.MachineName,
User = profilerPoco.User,
Level = profilerPoco.Level,
HasUserViewed = profilerPoco.HasUserViewed
};
if (profiler != null) //This is very similar to the Load logic in the SqlServerStorage.
//Perhaps another abstraction layer(or moving some logic into the Base) which both Mongo and Sql inherit from would eliminate somewhat repetitive code.
{
var timings = LoadTimings(profiler.Id);
var sqlTimings = LoadSqlTimings(profiler.Id);
var mongoTimings = LoadMongoTimings(profiler.Id);
var sqlParams = LoadSqlTimingParameters(profiler.Id);
var clientTimingList = LoadClientTimings(profiler.Id);
ClientTimings clientTimings = null;
if (clientTimingList.Count > 0)
{
clientTimings = new ClientTimings();
clientTimings.Timings = clientTimingList;
}
MapTimings(profiler, timings, sqlTimings, sqlParams, clientTimings, mongoTimings);
}
profiler.OnDeserialized();
return profiler;
}
return null;
}
开发者ID:brycekahle,项目名称:MiniProfiler,代码行数:47,代码来源:MongoDbStorage.cs
示例19: AssertMiniProfilerExists
/// <summary>
/// The assert mini profiler exists.
/// </summary>
/// <param name="miniProfiler">The mini Profiler.</param>
private void AssertMiniProfilerExists(MiniProfiler miniProfiler)
{
Assert.That(_conn.Query<int>("select count(*) from MiniProfilers where Id = @Id", new { miniProfiler.Id }).Single() == 1);
}
开发者ID:BiYiTuan,项目名称:dotnet,代码行数:8,代码来源:SqlServerStorageTest.cs
示例20: ResultsJson
/// <summary>
/// set the JSON results and the content type.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="profiler">The profiler.</param>
/// <returns>a string containing the JSON results.</returns>
private static string ResultsJson(HttpContext context, MiniProfiler profiler)
{
context.Response.ContentType = "application/json";
return MiniProfiler.ToJson(profiler);
}
开发者ID:NGPVAN,项目名称:MiniProfiler,代码行数:11,代码来源:MiniProfilerHandler.cs
注:本文中的MiniProfiler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论