-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[System.Diagnostics.DiagnosticSource] Implement metrics advice API #102524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bed3ff7
Prototype HistogramAdvice API.
CodeBlanch c9d0648
Merge remote-tracking branch 'upstream/main' into metrics-histogramad…
CodeBlanch 0aa4c72
Updates.
CodeBlanch 94958bc
Add tests.
CodeBlanch 8d65122
Code review.
CodeBlanch 922abfc
Code review.
CodeBlanch 3f0fbcc
Tweaks.
CodeBlanch ea17f17
Code review.
CodeBlanch afc3fac
Revisions.
CodeBlanch 6f56072
Tweaks.
CodeBlanch 8e76e81
Code review.
CodeBlanch 7586849
Add InstrumentAdvice ctor to ref.
CodeBlanch 3d22188
Merge from main.
CodeBlanch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ies/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/HistogramAdvice.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace System.Diagnostics.Metrics | ||
| { | ||
| /// <summary> | ||
| /// Contains settings used to advise metrics consumers how to construct storage for <see cref="Histogram{T}"/> instruments. | ||
| /// </summary> | ||
| /// <typeparam name="T">Histogram value type.</typeparam> | ||
| public sealed class HistogramAdvice<T> where T : struct | ||
CodeBlanch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| /// <summary> | ||
| /// Constructs a new instance of <see cref="HistogramAdvice{T}"/>. | ||
| /// </summary> | ||
| /// <param name="explicitBucketBoundaries"> | ||
| /// <para>Explicit bucket boundaries advised to be used with the histogram.</para> | ||
| /// <para>Notes: | ||
tarekgh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// <list type="bullet"> | ||
| /// <item>Bucket boundaries MUST be specified in ascending order and CANNOT contain duplicate values.</item> | ||
| /// <item>An empty set of bucket boundaries hints that the histogram should NOT contain buckets and should only track count and sum values.</item> | ||
| /// </list> | ||
| /// </para> | ||
| /// </param> | ||
| public HistogramAdvice(IEnumerable<T> explicitBucketBoundaries) | ||
CodeBlanch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (explicitBucketBoundaries is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(explicitBucketBoundaries)); | ||
| } | ||
|
|
||
| List<T> explicitBucketBoundariesCopy = [.. explicitBucketBoundaries]; | ||
CodeBlanch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!IsSortedAndDistinct(explicitBucketBoundariesCopy)) | ||
CodeBlanch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| throw new ArgumentException(SR.InvalidHistogramExplicitBucketBoundaries, nameof(explicitBucketBoundaries)); | ||
| } | ||
|
|
||
| ExplicitBucketBoundaries = explicitBucketBoundariesCopy; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the explicit bucket boundaries advised to be used with the histogram. | ||
| /// </summary> | ||
| public IReadOnlyList<T>? ExplicitBucketBoundaries { get; } | ||
|
|
||
| private static bool IsSortedAndDistinct(List<T> values) | ||
| { | ||
| Comparer<T> comparer = Comparer<T>.Default; | ||
|
|
||
| for (int i = 1; i < values.Count; i++) | ||
| { | ||
| if (comparer.Compare(values[i - 1], values[i]) >= 0) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.