mirror of https://github.com/Squidex/squidex.git
13 changed files with 116 additions and 20 deletions
@ -0,0 +1,66 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Squidex.Infrastructure.Log |
||||
|
{ |
||||
|
public sealed class ProfilerSpan : IDisposable |
||||
|
{ |
||||
|
private readonly ValueStopwatch watch = ValueStopwatch.StartNew(); |
||||
|
private readonly ProfilerSession session; |
||||
|
private readonly string key; |
||||
|
private List<IDisposable> hooks; |
||||
|
|
||||
|
public string Key |
||||
|
{ |
||||
|
get { return key; } |
||||
|
} |
||||
|
|
||||
|
public ProfilerSpan(ProfilerSession session, string key) |
||||
|
{ |
||||
|
this.session = session; |
||||
|
|
||||
|
this.key = key; |
||||
|
} |
||||
|
|
||||
|
public void Listen(IDisposable hook) |
||||
|
{ |
||||
|
Guard.NotNull(hook, nameof(hook)); |
||||
|
|
||||
|
if (hooks == null) |
||||
|
{ |
||||
|
hooks = new List<IDisposable>(1); |
||||
|
} |
||||
|
|
||||
|
hooks.Add(hook); |
||||
|
} |
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
var elapsedMs = watch.Stop(); |
||||
|
|
||||
|
session.Measured(key, elapsedMs); |
||||
|
|
||||
|
if (hooks != null) |
||||
|
{ |
||||
|
for (var i = 0; i < hooks.Count; i++) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
hooks[i].Dispose(); |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
continue; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue