Skip to content

A Real-Time Per-Thread/Task Perf Stats Tracker #43610

Closed

Description

@benmwatson

AB#1244363

Background and Motivation

In Bing, we want to track performance of dynamically loaded plugin code very closely so that we can figure out whether the code is staying within the bounds of good performance and behavior. A plugin that gets too far out of bounds can be disabled or run at a lower priority, for example.

Currently, we can track the following in real-time:

  • Wall-time (Stopwatch)
  • CPU-time (Win32 API GetThreadTimes)
  • Unhandled exceptions

In addition, we can track the following with ETW events, but only after the fact, or in limited-time profiles.

  • Memory allocation (especially LOH allocations)
  • First-chance exceptions
  • JITted methods

We'd like to be able to get these stats via API, in order of importance:

  1. GC - Bytes Allocated (GC.GetAllocatedBytesForCurrentThread appears to satisfy this)
  2. JIT stats - % time (CPU time? wall time?)
    a. Jitted bytes would be nice to have here, but time is more important.
  3. Locks taken, # of times thread was blocked
  4. Exceptions thrown - aware that we can listen to FirstChanceException handler, but this process-global, as far as I know, so messier to deal with.

Proposed API and Example

We could wrap the stats in a Stopwatch like class that gets a lot more than time:

var mon = new ThreadStatsMonitor();
mon.Start()

thirdPartyCode.Execute();

mon.Stop();

Logger.Log(
  mon.BytesAllocated, // I'm aware of GC.GetAllocatedBytesForCurrentThread
  mon.JITCPUTime,
  mon.MethodsJitted,
  mon.ILBytesJited, 
  mon.nativeBytesGenerated,
  mon.ExceptionsThrown, //i.e., first-chance exceptions
  mon.LockSynchronizations, 
  mon.CPUTime, 
  mon.WallTime,
);

// This is simplistic logic, but conveys the point
if (mon.BytesAllocated > MaxBytesPerPlugin)
{
  thirdPartyCode.Disable();  
}

Risks

Pay-for-play. Not everybody wants all the stats. Some of the stats could be expensive to generate.

Activity

  1. added
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Oct 19, 2020
  2. removed
    untriagedNew issue has not been triaged by the area owner
    on Jan 21, 2021
  3. added this to the 6.0.0 milestone on Jan 21, 2021
  4. krwq commented on Jul 8, 2021

    @krwq
    Member

    Hey @StephenBonikowsky is this still needed for 6.0? Is anyone working on this?

  5. StephenBonikowsky commented on Jul 8, 2021

    @StephenBonikowsky
    Contributor

    @tommcdon I believe your team owns this, I know there was a question on whether this issue would be resolved as part of #45590?

  6. danmoseley commented on Jul 21, 2021

    @danmoseley
    Contributor

    Correcting label. @tommcdon a suggestion from Bing.

  7. josalem commented on Jul 21, 2021

    @josalem
    Contributor

    This was implemented in #55046

  8. ghost locked as resolved and limited conversation to collaborators on Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions