Skip to content

Commit

Permalink
1) Add "TryAddCustomData" method into "PerformanceMeter" class;
Browse files Browse the repository at this point in the history
2 Add "AddMethodArgumentsToCustomDataAttribute" attribute for adding arguments to measurement custom data with "DiagnosticSource"
  • Loading branch information
unchase committed Jan 18, 2020
1 parent b3ca922 commit 611f9af
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 10 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@

# Change log

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

## v1.2.0 `(2020-01-18)`

- [x] Add `TryAddCustomData` method into `PerformanceMeter` class
- [x] Add `AddMethodArgumentsToCustomDataAttribute` attribute for adding arguments to measurement custom data with `DiagnosticSource`

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

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

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

Expand All @@ -21,4 +26,4 @@ These are the changes to each version that has been released on the official [Nu

## v1.0.0 `(2019-12-11)`

- [x] Release version of `Unchase Fluent Performance Meter` *NuGet* package on the official [NuGet Gallery](https://www.nuget.org/Unchase.FluentPerformanceMeter)
- [x] Release version of `Unchase Fluent Performance Meter` *NuGet* package on the official [NuGet Gallery](https://www.nuget.org/Unchase.FluentPerformanceMeter)
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ After calling the method `SimpleWatchingMethodStart` and calling `GetPerformance

### <a name="DiagnosticSourceSample"></a> Method's performance measurement with `DiagnosticSource`

Starting with *v1.1.0*, it became possible to measure the performance of methods in an *AspNetCore* application using the `DiagnosticSource` and the special `WatchingWithDiagnosticSourceAttribute` attribute. To do this, add the *NuGet* package [`Unchase.FluentPerformanceMeter.AspNetCore.Mvc`](https://www.nuget.org/Unchase.FluentPerformanceMeter.AspNetCore.Mvc) to the project and add the following code to `Startap.cs`:
Starting with *v1.1.0*, it became possible to measure the performance of methods in an *AspNetCore MVC* application using the `DiagnosticSource` and the special `WatchingWithDiagnosticSourceAttribute` attribute. To do this, add the *NuGet* package [`Unchase.FluentPerformanceMeter.AspNetCore.Mvc`](https://www.nuget.org/Unchase.FluentPerformanceMeter.AspNetCore.Mvc) to the project and add the following code to `Startap.cs`:

```csharp
public void ConfigureServices(IServiceCollection services)
Expand Down Expand Up @@ -221,6 +221,61 @@ public class PerformanceMeterController : ControllerBase
}
```

Starting with version *v1.2.0*, it became possible to add invocation arguments to custom method performance measurement data in an *AspNetCore MVC* application using the special `AddMethodArgumentsToCustomDataAttribute` attribute in conjunction with the `WatchingWithDiagnosticSourceAttribute` attribute:

```csharp
[HttpPost("SimpleWatchingMethodStartWithArgs")]
[WatchingWithDiagnosticSource]
[AddMethodArgumentsToCustomData("actionArguments")]
public ActionResult SimpleWatchingMethodStartWithArgs(DTOArgument arg)
{
return Ok();
}
```

After calling the method `SimpleWatchingMethodStartWithArgs` and calling `GetPerformanceInfo` we receive:

```json
{
"methodCalls": [
{
"methodName": "SimpleWatchingMethodStartWithArgs",
"elapsed": "00:00:00.0016350",
"caller": "unknown",
"startTime": "2019-12-06T10:27:27.3385385Z",
"endTime": "2019-12-06T10:27:27.3401735Z",
"customData": {
"actionArguments": {
"arg": {
"data": "<string_in_DTOArgument>"
}
}
},
"steps": []
}
],
"totalActivity": [
{
"methodName": "SimpleWatchingMethodStartWithArgs",
"callsCount": 1
}
],
"currentActivity": [
{
"methodName": "SimpleWatchingMethodStartWithArgs",
"callsCount": 0
}
],
"uptimeSince": "2019-12-06T10:27:27.3370183Z",
"className": "Unchase.FluentPerformanceMeter.TestWebAPI.Controllers.PerformanceMeterController",
"methodNames": [
"SimpleWatchingMethodStartWithArgs"
],
"customData": {},
"timerFrequency": 10000000
}
```

### <a name="SampleExternal"></a> Measuring the performance of an external library method

To measure the performance of a *public* method of a *public* class of a third-party library, you should explicitly specify the class itself and the name of its method:
Expand Down
57 changes: 56 additions & 1 deletion README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public ActionResult<IPerformanceInfo> GetPerformanceInfo()

### <a name="DiagnosticSourceSample"></a> Измерение производительности метода с помощью `DiagnosticSource`

Начиная с версии *v1.1.0* появилась возможность мерять производительность методов в *AspNetCore* приложении с помощью `DiagnosticSource` и специального атрибута `WatchingWithDiagnosticSourceAttribute`.
Начиная с версии *v1.1.0* появилась возможность мерять производительность методов в *AspNetCore MVC* приложении с помощью `DiagnosticSource` и специального атрибута `WatchingWithDiagnosticSourceAttribute`.
Для этого необходимо добавить в проект *NuGet* пакет [`Unchase.FluentPerformanceMeter.AspNetCore.Mvc`](https://www.nuget.org/Unchase.FluentPerformanceMeter.AspNetCore.Mvc), и добавить в `Startap.cs` следующий код:

```csharp
Expand Down Expand Up @@ -228,6 +228,61 @@ public class PerformanceMeterController : ControllerBase
}
```

Начиная с версии *v1.2.0* появилась возможность добавлять аргументы вызова к пользовательским данным замера производительности методов в *AspNetCore MVC* приложении с помощью специального атрибута `AddMethodArgumentsToCustomDataAttribute` в связке с атрибутом `WatchingWithDiagnosticSourceAttribute`:

```csharp
[HttpPost("SimpleWatchingMethodStartWithArgs")]
[WatchingWithDiagnosticSource]
[AddMethodArgumentsToCustomData("actionArguments")]
public ActionResult SimpleWatchingMethodStartWithArgs(DTOArgument arg)
{
return Ok();
}
```

После вызова метода `SimpleWatchingMethodStartWithArgs` при вызове `GetPerformanceInfo` получим:

```json
{
"methodCalls": [
{
"methodName": "SimpleWatchingMethodStartWithArgs",
"elapsed": "00:00:00.0016350",
"caller": "unknown",
"startTime": "2019-12-06T10:27:27.3385385Z",
"endTime": "2019-12-06T10:27:27.3401735Z",
"customData": {
"actionArguments": {
"arg": {
"data": "<string_in_DTOArgument>"
}
}
},
"steps": []
}
],
"totalActivity": [
{
"methodName": "SimpleWatchingMethodStartWithArgs",
"callsCount": 1
}
],
"currentActivity": [
{
"methodName": "SimpleWatchingMethodStartWithArgs",
"callsCount": 0
}
],
"uptimeSince": "2019-12-06T10:27:27.3370183Z",
"className": "Unchase.FluentPerformanceMeter.TestWebAPI.Controllers.PerformanceMeterController",
"methodNames": [
"SimpleWatchingMethodStartWithArgs"
],
"customData": {},
"timerFrequency": 10000000
}
```

### <a name="SampleExternal"></a> Измерение производительности метода используемой библиотеки

Чтобы замерить производительность *public* метода *public* класса сторонней используемой библиотеки, необходимо явно задать сам класс и имя его метода:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Microsoft.AspNetCore.Mvc.Filters;
using System;

namespace Unchase.FluentPerformanceMeter.AspNetCore.Mvc.Attributes
{
/// <summary>
/// Attribute to adding action arguments to the measurement custom data with <see cref="WatchingWithDiagnosticSourceAttribute"/>.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class AddMethodArgumentsToCustomDataAttribute : ActionFilterAttribute
{
#region Fileds

private string _argumentsKey;

#endregion

#region Constructors

/// <summary>
/// Constructor for <see cref="AddMethodArgumentsToCustomDataAttribute"/>.
/// </summary>
/// <param name="argumentsKey">Key for arguments in custom data storage.</param>
public AddMethodArgumentsToCustomDataAttribute(string argumentsKey = "arguments")
{
this._argumentsKey = argumentsKey;
}

#endregion

#region Methods

/// <summary>
/// Call before the action executes, after model binding is complete.
/// </summary>
/// <param name="context"><see cref="ActionExecutingContext"/>.</param>
public override void OnActionExecuting(ActionExecutingContext context)
{
if (context.HttpContext.Items.TryGetValue("PerformanceMeter", out object performanceMeter))
{
var tryAddCustomDataMethod = performanceMeter.GetType().GetMethod("TryAddCustomData");
tryAddCustomDataMethod.Invoke(performanceMeter, new object[] { this._argumentsKey, context.ActionArguments });
}

base.OnActionExecuting(context);
}

#endregion
}
}
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.2</Version>
<Version>1.2.0</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 All @@ -16,6 +16,8 @@
<RepositoryType>Github</RepositoryType>
<PackageTags>performance benchmark benchmarking csharp dot-net</PackageTags>
<NeutralLanguage>en</NeutralLanguage>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
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 @@ -605,6 +605,31 @@ public ActionResult StartWatchingWithDiagnosticSource(string s)
return Ok();
}

/// <summary>
/// Test DTO for POST method.
/// </summary>
public class DTOArgument
{
/// <summary>
/// Test Data.
/// </summary>
public string Data { get; set; }
}

/// <summary>
/// Test POST method watching with diagnostic source (add arguments to custom data).
/// </summary>
/// <param name="arg">Input DTO.</param>
[HttpPost("StartWatchingWithDiagnosticSourceAndArguments")]
[MethodCaller("dsCaller2")]
[MethodCustomData("customData!", "diagnosticSourcePOST")]
[WatchingWithDiagnosticSource]
[AddMethodArgumentsToCustomData]
public ActionResult StartWatchingWithDiagnosticSourceAndArguments(DTOArgument arg)
{
return Ok();
}

#endregion

#endregion
Expand Down

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

13 changes: 13 additions & 0 deletions Unchase.FluentPerformanceMeter/PerformanceMeter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,19 @@ public static void SetMethodCallsCacheTime(int minutes)

#region Main

/// <summary>
/// Attempts to add the specified key and value to the custom data.
/// </summary>
/// <param name="key">Key.</param>
/// <param name="value">Value.</param>
/// <returns>
/// Returns true if custom data was added.
/// </returns>
public bool TryAddCustomData(string key, object value)
{
return this.CustomData.TryAdd(key, value);
}

/// <summary>
/// Print performance information for this 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.2.0</AssemblyVersion>
<FileVersion>1.1.2.0</FileVersion>
<Version>1.1.2</Version>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<Version>1.2.0</Version>
</PropertyGroup>

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

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

2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1.1.{build}
version: 1.2.{build}
pull_requests:
do_not_increment_build_number: true
skip_tags: true
Expand Down

0 comments on commit 611f9af

Please sign in to comment.