Maoni0 / realmon

A monitoring tool that tells you when GCs happen in a process and some characteristics about these GCs
MIT License
281 stars 25 forks source link

Decoupled the Console Presentation from the Core Logic into a Service #37

Open MokoSan opened 2 years ago

MokoSan commented 2 years ago

In an effort to separate out the core logic for:

1. Better testability

We moved the core logic of the GCEnd event into it's own abstraction - the GCRealTimeMonService that's accessed via the IGCRealTimeMonService interface. The contract from the client of the service is to subscribe to the GCEndObservable to obtain the GCEnd events in realtime and call dispose on the IGCRealTimeMonResult once the program is to exit.

Usage:

      IGCRealTimeMonResult result = GCRealTimeMonService.Instance.Value.Initialize(pid: pid, configuration: configuration);

      IDisposable subscriptionHandle = result.GCEndObservable.Subscribe(gc =>
      {
          lock (writerLock)
          {
              Console.WriteLine(PrintUtilities.GetRowDetails(gc, configuration));
          }
      });

      result.Source.Process();

When the process needs to exit:

result.Dispose();
Maoni0 commented 2 years ago

LGTM - if you could resolve conflicts we can merge :)