Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation')
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/Counter.cs52
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationConsumer.cs (renamed from main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/IInstrumentationConsumer.cs)14
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationService.cs98
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimeCounter.cs21
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimerCounter.cs11
5 files changed, 129 insertions, 67 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/Counter.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/Counter.cs
index 11ce9e69ad..5036c77e7a 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/Counter.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/Counter.cs
@@ -35,6 +35,7 @@ namespace MonoDevelop.Core.Instrumentation
{
internal int count;
int totalCount;
+ int lastStoredCount;
string name;
bool logMessages;
CounterCategory category;
@@ -45,8 +46,9 @@ namespace MonoDevelop.Core.Instrumentation
bool disposed;
bool storeValues;
bool enabled;
+ string id;
- List<IInstrumentationConsumer> handlers = new List<IInstrumentationConsumer> ();
+ List<InstrumentationConsumer> handlers = new List<InstrumentationConsumer> ();
public bool StoreValues {
get {
@@ -56,14 +58,22 @@ namespace MonoDevelop.Core.Instrumentation
storeValues = value;
}
}
+
+ public bool Enabled {
+ get { return enabled; }
+ }
- internal List<IInstrumentationConsumer> Handlers {
- get { return handlers; }
+ internal List<InstrumentationConsumer> Handlers {
+ get {
+ InstrumentationService.InitializeHandlers ();
+ return handlers;
+ }
}
internal void UpdateStatus ()
{
- enabled = InstrumentationService.Enabled || handlers.Count > 0;
+ InstrumentationService.InitializeHandlers ();
+ enabled = InstrumentationService.Enabled || Handlers.Count > 0;
storeValues = InstrumentationService.Enabled;
}
@@ -76,6 +86,11 @@ namespace MonoDevelop.Core.Instrumentation
public string Name {
get { return name; }
}
+
+ public string Id {
+ get { return id ?? Name; }
+ internal set { id = value; }
+ }
public CounterCategory Category {
get { return category; }
@@ -182,19 +197,29 @@ namespace MonoDevelop.Core.Instrumentation
}
}
- internal int StoreValue (string message, TimerTraceList traces)
+ internal int StoreValue (string message, TimeCounter timer)
{
DateTime now = DateTime.Now;
if (resolution.Ticks != 0) {
if (now - lastValueTime < resolution)
return -1;
}
- var val = new CounterValue (count, totalCount, now, message, traces);
+ var val = new CounterValue (count, totalCount, count - lastStoredCount, now, message, timer != null ? timer.TraceList : null);
+ lastStoredCount = count;
+
if (storeValues)
values.Add (val);
- if (handlers.Count > 0) {
- foreach (var h in handlers)
- h.ConsumeValue (this, val);
+ if (Handlers.Count > 0) {
+ if (timer != null) {
+ foreach (var h in handlers) {
+ var t = h.BeginTimer ((TimerCounter)this, val);
+ if (t != null)
+ timer.AddHandlerTracker (t);
+ }
+ } else {
+ foreach (var h in handlers)
+ h.ConsumeValue (this, val);
+ }
}
return values.Count - 1;
}
@@ -322,6 +347,7 @@ namespace MonoDevelop.Core.Instrumentation
{
int value;
int totalCount;
+ int change;
DateTime timestamp;
string message;
TimerTraceList traces;
@@ -335,15 +361,17 @@ namespace MonoDevelop.Core.Instrumentation
this.message = null;
traces = null;
threadId = 0;
+ change = 0;
}
- internal CounterValue (int value, int totalCount, DateTime timestamp, string message, TimerTraceList traces)
+ internal CounterValue (int value, int totalCount, int change, DateTime timestamp, string message, TimerTraceList traces)
{
this.value = value;
this.timestamp = timestamp;
this.totalCount = totalCount;
this.message = message;
this.traces = traces;
+ this.change = change;
this.threadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
}
@@ -358,6 +386,10 @@ namespace MonoDevelop.Core.Instrumentation
public int TotalCount {
get { return totalCount; }
}
+
+ public int ValueChange {
+ get { return change; }
+ }
public int ThreadId {
get { return this.threadId; }
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/IInstrumentationConsumer.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationConsumer.cs
index 9f6af53387..8e0574fe64 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/IInstrumentationConsumer.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationConsumer.cs
@@ -28,10 +28,18 @@ using System;
namespace MonoDevelop.Core.Instrumentation
{
[Mono.Addins.TypeExtensionPoint]
- public interface IInstrumentationConsumer
+ public abstract class InstrumentationConsumer
{
- bool SupportsCounter (Counter counter);
- void ConsumeValue (Counter counter, CounterValue value);
+ public abstract bool SupportsCounter (Counter counter);
+
+ public virtual void ConsumeValue (Counter counter, CounterValue value)
+ {
+ }
+
+ public virtual IDisposable BeginTimer (TimerCounter counter, CounterValue value)
+ {
+ return null;
+ }
}
}
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationService.cs
index 0cbe2dccbb..bd9358bbac 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationService.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationService.cs
@@ -54,7 +54,7 @@ namespace MonoDevelop.Core.Instrumentation
static Thread autoSaveThread;
static bool stopping;
static int autoSaveInterval;
- static List<IInstrumentationConsumer> handlers = new List<IInstrumentationConsumer> ();
+ static List<InstrumentationConsumer> handlers = new List<InstrumentationConsumer> ();
static bool handlersLoaded;
static InstrumentationService ()
@@ -64,12 +64,12 @@ namespace MonoDevelop.Core.Instrumentation
startTime = DateTime.Now;
}
- static void InitializeHandlers ()
+ internal static void InitializeHandlers ()
{
if (!handlersLoaded && AddinManager.IsInitialized) {
lock (counters) {
handlersLoaded = true;
- AddinManager.AddExtensionNodeHandler (typeof(IInstrumentationConsumer), HandleInstrumentationHandlerExtension);
+ AddinManager.AddExtensionNodeHandler (typeof(InstrumentationConsumer), HandleInstrumentationHandlerExtension);
}
}
}
@@ -84,26 +84,37 @@ namespace MonoDevelop.Core.Instrumentation
static void HandleInstrumentationHandlerExtension (object sender, ExtensionNodeEventArgs args)
{
- var handler = (IInstrumentationConsumer)args.ExtensionObject;
+ var handler = (InstrumentationConsumer)args.ExtensionObject;
if (args.Change == ExtensionChange.Add) {
- handlers.Add (handler);
- lock (counters) {
- foreach (var c in counters.Values) {
- if (handler.SupportsCounter (c))
- c.Handlers.Add (handler);
- }
- }
+ RegisterInstrumentationConsumer (handler);
}
else {
- handlers.Remove (handler);
- lock (counters) {
- foreach (var c in counters.Values)
- c.Handlers.Remove (handler);
+ UnregisterInstrumentationConsumer (handler);
+ }
+ }
+
+ public static void RegisterInstrumentationConsumer (InstrumentationConsumer consumer)
+ {
+ lock (counters) {
+ handlers.Add (consumer);
+ foreach (var c in counters.Values) {
+ if (consumer.SupportsCounter (c))
+ c.Handlers.Add (consumer);
}
}
UpdateCounterStatus ();
}
+ public static void UnregisterInstrumentationConsumer (InstrumentationConsumer consumer)
+ {
+ lock (counters) {
+ handlers.Remove (consumer);
+ foreach (var c in counters.Values)
+ c.Handlers.Remove (consumer);
+ }
+ UpdateCounterStatus ();
+ }
+
public static int PublishService ()
{
RemotingService.RegisterRemotingChannel ();
@@ -123,7 +134,7 @@ namespace MonoDevelop.Core.Instrumentation
throw new InvalidOperationException ("Service not published");
if (Platform.IsMac) {
- var macOSDir = PropertyService.EntryAssemblyPath.ParentDirectory.ParentDirectory.ParentDirectory;
+ var macOSDir = PropertyService.EntryAssemblyPath.ParentDirectory.ParentDirectory.ParentDirectory.ParentDirectory.Combine ("MacOS");
var app = macOSDir.Combine ("MDMonitor.app");
if (Directory.Exists (app)) {
var psi = new ProcessStartInfo ("open", string.Format ("-n '{0}' --args -c localhost:{1} ", app, publicPort)) {
@@ -223,10 +234,15 @@ namespace MonoDevelop.Core.Instrumentation
public static Counter CreateCounter (string name, string category, bool logMessages)
{
- return CreateCounter (name, category, logMessages, false);
+ return CreateCounter (name, category, logMessages, null, false);
}
- static Counter CreateCounter (string name, string category, bool logMessages, bool isTimer)
+ public static Counter CreateCounter (string name, string category = null, bool logMessages = false, string id = null)
+ {
+ return CreateCounter (name, category, logMessages, id, false);
+ }
+
+ static Counter CreateCounter (string name, string category, bool logMessages, string id, bool isTimer)
{
InitializeHandlers ();
@@ -241,6 +257,7 @@ namespace MonoDevelop.Core.Instrumentation
}
Counter c = isTimer ? new TimerCounter (name, cat) : new Counter (name, cat);
+ c.Id = id;
c.LogMessages = logMessages;
cat.AddCounter (c);
@@ -289,7 +306,12 @@ namespace MonoDevelop.Core.Instrumentation
public static TimerCounter CreateTimerCounter (string name, string category, double minSeconds, bool logMessages)
{
- TimerCounter c = (TimerCounter) CreateCounter (name, category, logMessages, true);
+ return CreateTimerCounter (name, category, minSeconds, logMessages, null);
+ }
+
+ public static TimerCounter CreateTimerCounter (string name, string category = null, double minSeconds = 0, bool logMessages = false, string id = null)
+ {
+ TimerCounter c = (TimerCounter) CreateCounter (name, category, logMessages, id, true);
c.DisplayMode = CounterDisplayMode.Line;
c.LogMessages = logMessages;
c.MinSeconds = minSeconds;
@@ -357,7 +379,7 @@ namespace MonoDevelop.Core.Instrumentation
}
}
- public static IProgressMonitor GetInstrumentedMonitor (IProgressMonitor monitor, TimerCounter counter)
+ public static ProgressMonitor GetInstrumentedMonitor (ProgressMonitor monitor, TimerCounter counter)
{
if (enabled) {
AggregatedProgressMonitor mon = new AggregatedProgressMonitor (monitor);
@@ -368,37 +390,23 @@ namespace MonoDevelop.Core.Instrumentation
}
}
- class IntrumentationMonitor: NullProgressMonitor
+ class IntrumentationMonitor: ProgressMonitor
{
TimerCounter counter;
Stack<ITimeTracker> timers = new Stack<ITimeTracker> ();
- LogTextWriter logger = new LogTextWriter ();
-
+
public IntrumentationMonitor (TimerCounter counter)
{
this.counter = counter;
- logger.TextWritten += HandleLoggerTextWritten;
}
- void HandleLoggerTextWritten (string writtenText)
+ protected override void OnWriteLog (string message)
{
if (timers.Count > 0)
- timers.Peek ().Trace (writtenText);
- }
-
- public override void BeginTask (string name, int totalWork)
- {
- if (!string.IsNullOrEmpty (name)) {
- ITimeTracker c = counter.BeginTiming (name);
- c.Trace (name);
- timers.Push (c);
- } else {
- timers.Push (null);
- }
- base.BeginTask (name, totalWork);
+ timers.Peek ().Trace (message);
}
-
- public override void BeginStepTask (string name, int totalWork, int stepSize)
+
+ protected override void OnBeginTask (string name, int totalWork, int stepWork)
{
if (!string.IsNullOrEmpty (name)) {
ITimeTracker c = counter.BeginTiming (name);
@@ -407,23 +415,15 @@ namespace MonoDevelop.Core.Instrumentation
} else {
timers.Push (null);
}
- base.BeginStepTask (name, totalWork, stepSize);
}
- public override void EndTask ()
+ protected override void OnEndTask (string name, int totalWork, int stepWork)
{
if (timers.Count > 0) {
ITimeTracker c = timers.Pop ();
if (c != null)
c.End ();
}
- base.EndTask ();
- }
-
- public override System.IO.TextWriter Log {
- get {
- return logger;
- }
}
}
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimeCounter.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimeCounter.cs
index 140f84f899..55227a859f 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimeCounter.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimeCounter.cs
@@ -25,6 +25,7 @@
// THE SOFTWARE.
using System;
+using System.Collections.Generic;
namespace MonoDevelop.Core.Instrumentation
{
@@ -55,6 +56,7 @@ namespace MonoDevelop.Core.Instrumentation
TimerTraceList traceList;
TimerTrace lastTrace;
TimerCounter counter;
+ object linkedTrackers;
internal TimeCounter (TimerCounter counter)
{
@@ -62,6 +64,18 @@ namespace MonoDevelop.Core.Instrumentation
traceList = new TimerTraceList ();
Begin ();
}
+
+ public void AddHandlerTracker (IDisposable t)
+ {
+ if (linkedTrackers == null)
+ linkedTrackers = t;
+ else if (!(linkedTrackers is List<IDisposable>)) {
+ var list = new List<IDisposable> ();
+ list.Add ((IDisposable)linkedTrackers);
+ list.Add (t);
+ } else
+ ((List<IDisposable>)linkedTrackers).Add (t);
+ }
internal TimerTraceList TraceList {
get { return this.traceList; }
@@ -98,6 +112,13 @@ namespace MonoDevelop.Core.Instrumentation
else
counter.AddTime (traceList.TotalTime);
counter = null;
+
+ if (linkedTrackers is List<IDisposable>) {
+ foreach (var t in (List<IDisposable>)linkedTrackers)
+ t.Dispose ();
+ } else if (linkedTrackers != null)
+ ((IDisposable)linkedTrackers).Dispose ();
+
}
void IDisposable.Dispose ()
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimerCounter.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimerCounter.cs
index ed2f54cd46..316d54f87e 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimerCounter.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimerCounter.cs
@@ -82,7 +82,7 @@ namespace MonoDevelop.Core.Instrumentation
public override void Trace (string message)
{
- if (InstrumentationService.Enabled) {
+ if (Enabled) {
if (lastTimer != null)
lastTimer.Trace (message);
else {
@@ -103,13 +103,14 @@ namespace MonoDevelop.Core.Instrumentation
public ITimeTracker BeginTiming (string message)
{
ITimeTracker timer;
- if (!InstrumentationService.Enabled) {
+ if (!Enabled) {
timer = dummyTimer;
} else {
+ var c = new TimeCounter (this);
lock (values) {
- timer = lastTimer = new TimeCounter (this);
+ timer = lastTimer = c;
count++;
- int i = StoreValue (message, lastTimer.TraceList);
+ int i = StoreValue (message, lastTimer);
lastTimer.TraceList.ValueIndex = i;
}
}
@@ -120,7 +121,7 @@ namespace MonoDevelop.Core.Instrumentation
public void EndTiming ()
{
- if (InstrumentationService.Enabled && lastTimer != null)
+ if (Enabled && lastTimer != null)
lastTimer.End ();
}