Skip to content

Commit

Permalink
Add "GetCustomData" method into "PerformanceMeter" and "PerformanceIn…
Browse files Browse the repository at this point in the history
…foStep" classes.
  • Loading branch information
unchase committed Jan 11, 2020
1 parent 25a0180 commit b3ca922
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

These are the changes to each version that has been released on the official [NuGet Gallery](https://www.nuget.org/Unchase.FluentPerformanceMeter).

## v1.1.2 `(2020-01-11)`

- [x] Add "GetCustomData" method into "PerformanceMeter" and "PerformanceInfoStep" classes

## v1.1.0 `(2020-01-06)`

[x] Add [`Unchase.FluentPerformanceMeter.AspNetCore.Mvc`](https://www.nuget.org/Unchase.FluentPerformanceMeter.AspNetCore.Mvc) project that allows to observe method's performance measurement with `DiagnosticSource` in *AspNetCore* project
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,9 @@ public ActionResult SimpleStartWatchingWithSteps()

// get and remove custom data from "Step 2"
var customData = pmStep.GetAndRemoveCustomData<string>("step2 custom data");

// get custom data from "Step 2" (without removing)
var anotherCustomData = pmStep.GetCustomData<string>("step2 another custom data");

// ...
}
Expand Down Expand Up @@ -977,7 +980,7 @@ using (var pm = PerformanceMeter<PerformanceMeterController>.WatchingMethod().St
// sleep 1 sec
Thread.Sleep(1000);

// ignore this block in performance watching
// ignore this block in performance watching
using (pm.Ignore())
{
Thread.Sleep(5000);
Expand Down
5 changes: 4 additions & 1 deletion README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,9 @@ public ActionResult SimpleStartWatchingWithSteps()
// get and remove custom data from "Step 2"
var customData = pmStep.GetAndRemoveCustomData<string>("step2 custom data");

// get custom data from "Step 2" (without removing)
var anotherCustomData = pmStep.GetCustomData<string>("step2 another custom data");

// ...
}
}
Expand Down Expand Up @@ -986,7 +989,7 @@ using (var pm = PerformanceMeter<PerformanceMeterController>.WatchingMethod().St
// sleep 1 sec
Thread.Sleep(1000);

// ignore this block in performance watching
// ignore this block in performance watching
using (pm.Ignore())
{
Thread.Sleep(5000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.1.0</Version>
<Version>1.1.2</Version>
<Authors>Unchase</Authors>
<Company>Unchase</Company>
<Description>Unchase Fluent Performance Meter is an open-source and cross-platform .Net Standart 2.0 library is designed for the method’s performance measurement.</Description>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ public ActionResult SimpleStartWatchingWithSteps()
// get and remove custom data from "Step 2"
var customData = pmStep.GetAndRemoveCustomData<string>("step2 custom data");
Debug.WriteLine($"{customData}!!!");

// get custom data from "Step 2" (without removing)
var anotherCustomData = pmStep.GetCustomData<string>("step2 another custom data");
}

return Ok();
Expand Down
21 changes: 21 additions & 0 deletions Unchase.FluentPerformanceMeter/PerformanceInfoStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ public TResult GetAndRemoveCustomData<TResult>(string key)
return default;
}

/// <summary>
/// Get custom data from performance meter step information.
/// </summary>
/// <typeparam name="TResult">Type of custom data result.</typeparam>
/// <param name="key">Key.</param>
/// <returns>
/// Returns typed result.
/// </returns>
public TResult GetCustomData<TResult>(string key)
{
if (this._customData.ContainsKey(key))
{
if (this._customData.TryRemove(key, out var result) && result is TResult typedResult)
{
this._customData.TryAdd(key, typedResult);
return typedResult;
}
}
return default;
}

/// <summary>
/// Clear custom data to performance meter step information.
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions Unchase.FluentPerformanceMeter/PerformanceMeter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,27 @@ public TResult GetAndRemoveCustomData<TResult>(string key)
return default;
}

/// <summary>
/// Get custom data from performance meter information.
/// </summary>
/// <typeparam name="TResult">Type of custom data result.</typeparam>
/// <param name="key">Key.</param>
/// <returns>
/// Returns typed result.
/// </returns>
public TResult GetCustomData<TResult>(string key)
{
if (this.CustomData.ContainsKey(key))
{
if (this.CustomData.TryRemove(key, out var result) && result is TResult typedResult)
{
this.CustomData.TryAdd(key, typedResult);
return typedResult;
}
}
return default;
}

/// <summary>
/// Remove common custom data of the class.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<PackageIcon>icon.png</PackageIcon>
<PackageIconUrl />
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>1.1.0.0</FileVersion>
<Version>1.1.0</Version>
<AssemblyVersion>1.1.2.0</AssemblyVersion>
<FileVersion>1.1.2.0</FileVersion>
<Version>1.1.2</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
25 changes: 20 additions & 5 deletions Unchase.FluentPerformanceMeter/Unchase.FluentPerformanceMeter.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b3ca922

Please sign in to comment.