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

dotnet-counters: Missing System.Runtime-Counters when publishing a trimmed app #79648

Closed
clane2812 opened this issue Dec 14, 2022 · 10 comments
Closed
Assignees
Milestone

Comments

@clane2812
Copy link

Description

When a net6-application is published 'trimmed', the System.Runtime-Counters collected with dotnet-counters are not available.

Reproduction Steps

  • Create and run a simple console-application

  • dotnet-counters monitor --process-id --refresh-interval 3 --counters System.Runtime

  • All counters are collected

  • Publish the app with 'trimmed' mode and run it

  • dotnet-counters monitor --process-id --refresh-interval 3 --counters System.Runtime

  • No counters are collected

The behaviour is described in the (closed) issue #44910 as well.

Expected behavior

System.Runtime counters give essential first-level informations when you search for example memory-leaks in a running docker-container. I would expect to get these important informations independent of the publish-mode.

Actual behavior

A docker-container which is published trimmed cannot be profiled with dotnet-counters (concerning the System.Runtime-Counters)

Regression?

No response

Known Workarounds

The workaround described in #44910 works: if you manually initialize the event-source, the counters are available in the trimmed container-image as well:

var corelib = typeof(EventSource).Assembly;
var runtimeEventSource = corelib.GetType("System.Diagnostics.Tracing.RuntimeEventSource");
var initialize = runtimeEventSource.GetMethod("Initialize");
initialize.Invoke(null, null);

I run the above snippet in the startup of the app, depending of an env-var, so you can turn on/off the profiling in a container

Configuration

No response

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 14, 2022
@ghost
Copy link

ghost commented Dec 14, 2022

Tagging subscribers to this area: @tommcdon
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

When a net6-application is published 'trimmed', the System.Runtime-Counters collected with dotnet-counters are not available.

Reproduction Steps

  • Create and run a simple console-application

  • dotnet-counters monitor --process-id --refresh-interval 3 --counters System.Runtime

  • All counters are collected

  • Publish the app with 'trimmed' mode and run it

  • dotnet-counters monitor --process-id --refresh-interval 3 --counters System.Runtime

  • No counters are collected

The behaviour is described in the (closed) issue #44910 as well.

Expected behavior

System.Runtime counters give essential first-level informations when you search for example memory-leaks in a running docker-container. I would expect to get these important informations independent of the publish-mode.

Actual behavior

A docker-container which is published trimmed cannot be profiled with dotnet-counters (concerning the System.Runtime-Counters)

Regression?

No response

Known Workarounds

The workaround described in #44910 works: if you manually initialize the event-source, the counters are available in the trimmed container-image as well:

var corelib = typeof(EventSource).Assembly;
var runtimeEventSource = corelib.GetType("System.Diagnostics.Tracing.RuntimeEventSource");
var initialize = runtimeEventSource.GetMethod("Initialize");
initialize.Invoke(null, null);

I run the above snippet in the startup of the app, depending of an env-var, so you can turn on/off the profiling in a container

Configuration

No response

Other information

No response

Author: clane2812
Assignees: -
Labels:

area-Diagnostics-coreclr, untriaged

Milestone: -

@tommcdon
Copy link
Member

@clane2812 Thanks for reporting this issue! Does this issue reproduce on .net 7?
cc @LakshanF @eerhardt

@clane2812
Copy link
Author

@tommcdon - yes, the issue is the same with .net7. Tried debug/release publish as well, but this makes no difference:
publish trimmed -> no counters available
publish normal -> all counters available

@tommcdon
Copy link
Member

@LakshanF @eerhardt @tarekgh please take a look

@tommcdon tommcdon added this to the 8.0.0 milestone Dec 16, 2022
@tommcdon tommcdon removed the untriaged New issue has not been triaged by the area owner label Dec 16, 2022
@davmason
Copy link
Member

@LakshanF, would we be able to get EventSource whitelisted so it is not trimmed? I am not sure what our policy is around that. It would be great if we could support diagnostic scenarios like counters out of the box instead of having users debug/fix it on their own.

@MichalStrehovsky
Copy link
Member

@davmason what is the thing that is getting trimmed here and shouldn't?

I see there's descriptors that say not to trim the Initialize method mentioned in this issue:

What else is needed?

@davmason
Copy link
Member

Sorry for the delay here, we have had an influx of issues. I have asked @dramos020 to take a look

@dramos020 dramos020 self-assigned this Jan 18, 2023
@davmason davmason removed their assignment Jan 20, 2023
@dramos020
Copy link
Contributor

After some investigation, I believe that it is not Initialize() that is getting trimmed, but instead ProcessStartupHooks(), which calls Initialize(), that is getting trimmed. It seems that the trimming is happening because StartupHookSupport is disabled by default. Not sure what the solution/next steps to this would be.

@jkotas
Copy link
Member

jkotas commented Jan 23, 2023

This was fixed for .NET 8 by #80391

@ghost ghost locked as resolved and limited conversation to collaborators Feb 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants