Skip to content

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

@clane2812

Description

@clane2812

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions