Skip to content
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

[Instrumentation.Process] Added Cpu related metrics and addressed comments. #612

Closed
wants to merge 40 commits into from

Conversation

Yun-Ting
Copy link
Contributor

@Yun-Ting Yun-Ting commented Aug 26, 2022

Changes

Working towards: #447
Background: #335

Following OTel spec:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/process-metrics.md#metric-instruments

  1. Addressed some comments:
    [Instrumentation.Process] Added memory related metrics. #595 (review)
    [Instrumentation.Process] Added memory related metrics. #595 (comment)

  2. Added CPU time and CPU utilization metrics. It is not clear from the spec that whether breakdown by CPU states (System, User, Wait) option should be implemented. Currently, this PR is not providing an option to specify that and uses no-breakdown gauge and counter by default.

@@ -21,4 +21,5 @@ namespace OpenTelemetry.Instrumentation.Process;
/// </summary>
public class ProcessInstrumentationOptions
{
public bool? ExpandOnCpuStates { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly suggest to use a different name, and also strongly suggest to not ask me to provide one 🏃 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would CpuStatesEnabled be better? 😁

Copy link
Member

@reyang reyang Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would vote for not having the option at all (and later if folks really need that, we can add it in a non-breaking way).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what should we have as the default behavior?
Breaking down by the states or not?
The spec is not very clear about this currently.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think? (I'll hold my answer for now 😄)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe default to not having the breakdown unless people really want it.

var priviledgedCpuTime = CurrentProcess.PrivilegedProcessorTime.Seconds;
var userCpuTime = CurrentProcess.PrivilegedProcessorTime.Seconds;

measurements[(int)CPUState.System] = new(priviledgedCpuTime, new KeyValuePair<string, object>("state", CPUState.System.ToString()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we allocate a new string each time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah... that's the issue; maybe hardcoding the indices here is not that of a bad choice?

@Yun-Ting Yun-Ting marked this pull request as ready for review August 26, 2022 21:27
@Yun-Ting Yun-Ting requested a review from a team August 26, 2022 21:27
{
Measurement<long>[] measurements = new Measurement<long>[Enum.GetNames(typeof(CpuState)).Length];
var priviledgedCpuTime = this.currentProcess.PrivilegedProcessorTime.Seconds;
var userCpuTime = this.currentProcess.UserProcessorTime.Seconds;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want integer or double?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use int.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why int?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, because the .Seconds from the Timespan struct returns int?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, because the .Seconds from the Timespan struct returns int?

How is this related?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be .TotalSeconds?


measurements[(int)CpuState.System] = new(priviledgedCpuTime, new KeyValuePair<string, object>("state", CpuState.System.ToString()));
measurements[(int)CpuState.User] = new(userCpuTime, new KeyValuePair<string, object>("state", CpuState.User.ToString()));
measurements[(int)CpuState.Wait] = new(this.currentProcess.TotalProcessorTime.Seconds - priviledgedCpuTime - userCpuTime, new KeyValuePair<string, object>("state", CpuState.Wait.ToString()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this give a non-zero value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The browser does not show me a very well-defined highlight for this comment. May I ask which part do you refer to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does TotalProcessorTime - PriviledgedCpuTime - UserCpuTime actually mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you read this https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.totalprocessortime?view=net-6.0#property-value:

TotalProcessorTime - PriviledgedCpuTime - UserCpuTim is always going to give zero, unless .NET or the underlying native API has bugs.

image

@Yun-Ting Yun-Ting closed this Aug 29, 2022
@Yun-Ting Yun-Ting reopened this Aug 29, 2022
@Yun-Ting Yun-Ting changed the title [Instrumentation.Process] Added Cpu time metric and addressed comments. [Instrumentation.Process] Added Cpu related metrics and addressed comments. Aug 29, 2022
Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks heading towards a wrong direction.

@utpilla utpilla added the comp:instrumentation.process Things related to OpenTelemetry.Instrumentation.Process label Aug 31, 2022
@Yun-Ting Yun-Ting closed this Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.process Things related to OpenTelemetry.Instrumentation.Process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants