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
path: root/main
diff options
context:
space:
mode:
authorMarius Ungureanu <marius.ungureanu@xamarin.com>2019-09-17 16:32:48 +0300
committerGitHub <noreply@github.com>2019-09-17 16:32:48 +0300
commit6e2367739a93d0e256b0c3b3f98aa1dc72b934e8 (patch)
tree73fe8194675089a60defd184d867656754f1ef96 /main
parenteaa33dead1daa44f41ba491312470853f908e491 (diff)
parentdaa1fa5f410495008199669497e7f97c097d7f5b (diff)
Merge pull request #8695 from mono/nullability
[Core] Enable nullability analysis in MonoDevelop.Utilities
Diffstat (limited to 'main')
-rw-r--r--main/src/core/MonoDevelop.Core/CoreExtensions.EventHandlers.cs9
-rw-r--r--main/src/core/MonoDevelop.Core/CoreExtensions.ReaderWriterLockSlim.cs2
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/BucketTimings.cs3
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/Counter.cs54
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/CounterCategory.cs2
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationConsumer.cs5
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationService.cs64
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/MemoryProbe.cs4
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimeCounter.cs40
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimerCounter.cs37
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Utilities/RaceChecker.cs10
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Utilities/SampleProfiler.cs14
12 files changed, 139 insertions, 105 deletions
diff --git a/main/src/core/MonoDevelop.Core/CoreExtensions.EventHandlers.cs b/main/src/core/MonoDevelop.Core/CoreExtensions.EventHandlers.cs
index 9c526ba604..64a901b9d9 100644
--- a/main/src/core/MonoDevelop.Core/CoreExtensions.EventHandlers.cs
+++ b/main/src/core/MonoDevelop.Core/CoreExtensions.EventHandlers.cs
@@ -23,7 +23,8 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using System;
+#nullable enable
+
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -97,7 +98,7 @@ namespace System
}
}
- static void TimeInvoke (Action<Delegate, object, EventArgs> call, Delegate[] del, object sender, EventArgs args, object groupId)
+ static void TimeInvoke (Action<Delegate, object, EventArgs> call, Delegate[] del, object sender, EventArgs args, object? groupId)
{
var sw = new Diagnostics.Stopwatch ();
foreach (var ev in del) {
@@ -113,7 +114,7 @@ namespace System
}
}
- internal static void TimeInvoke<T> (this EventHandler<T> events, object sender, T args, object groupId = null) where T:EventArgs
+ internal static void TimeInvoke<T> (this EventHandler<T> events, object sender, T args, object? groupId = null) where T:EventArgs
=> TimeInvoke (
(del, s, a) => ((EventHandler<T>)del).Invoke (s, (T)a),
events.GetInvocationList (), // This can be a perf issue, do we have a different way to query it?
@@ -122,7 +123,7 @@ namespace System
groupId
);
- internal static void TimeInvoke (this EventHandler events, object sender, EventArgs args, object groupId = null)
+ internal static void TimeInvoke (this EventHandler events, object sender, EventArgs args, object? groupId = null)
=> TimeInvoke (
(del, s, a) => ((EventHandler)del).Invoke (s, a),
events.GetInvocationList (), // This can be a perf issue, do we have a different way to query it?
diff --git a/main/src/core/MonoDevelop.Core/CoreExtensions.ReaderWriterLockSlim.cs b/main/src/core/MonoDevelop.Core/CoreExtensions.ReaderWriterLockSlim.cs
index b4805ff230..68131fd8e5 100644
--- a/main/src/core/MonoDevelop.Core/CoreExtensions.ReaderWriterLockSlim.cs
+++ b/main/src/core/MonoDevelop.Core/CoreExtensions.ReaderWriterLockSlim.cs
@@ -23,7 +23,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using System;
+#nullable enable
using System.Threading;
namespace System
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/BucketTimings.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/BucketTimings.cs
index 0f5c3f16b9..7182920407 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/BucketTimings.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/BucketTimings.cs
@@ -23,6 +23,9 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+
+#nullable enable
+
using System;
using System.Collections.Immutable;
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 bcc3053bef..c383c38dde 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/Counter.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/Counter.cs
@@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+#nullable enable
+
using System;
using System.Collections.Generic;
using System.IO;
@@ -38,12 +40,12 @@ namespace MonoDevelop.Core.Instrumentation
internal int totalCount;
string name;
bool logMessages;
- CounterCategory category;
+ CounterCategory? category;
protected List<CounterValue> values = new List<CounterValue> ();
TimeSpan resolution = TimeSpan.FromMilliseconds (0);
DateTime lastValueTime = DateTime.MinValue;
bool disposed;
- string id;
+ string? id;
List<InstrumentationConsumer> handlers = new List<InstrumentationConsumer> ();
@@ -63,7 +65,7 @@ namespace MonoDevelop.Core.Instrumentation
InstrumentationService.InitializeHandlers ();
}
- internal Counter (string name, CounterCategory category)
+ internal Counter (string name, CounterCategory? category)
{
this.name = name;
this.category = category;
@@ -83,7 +85,7 @@ namespace MonoDevelop.Core.Instrumentation
internal set { id = value; }
}
- public CounterCategory Category {
+ public CounterCategory? Category {
get { return category; }
}
@@ -178,7 +180,7 @@ namespace MonoDevelop.Core.Instrumentation
}
}
- internal int StoreValue (string message, ITimeCounter timer, IDictionary<string, object> metadata)
+ internal int StoreValue (string? message, ITimeCounter? timer, IDictionary<string, object>? metadata)
{
DateTime now = DateTime.Now;
if (resolution.Ticks != 0) {
@@ -222,7 +224,7 @@ namespace MonoDevelop.Core.Instrumentation
Inc (1, null);
}
- public void Inc (string message)
+ public void Inc (string? message)
{
Inc (1, message);
}
@@ -232,24 +234,24 @@ namespace MonoDevelop.Core.Instrumentation
Inc (n, null);
}
- public void Inc (int n, string message)
+ public void Inc (int n, string? message)
{
- Inc (n, message, (IDictionary<string, object>)null);
+ Inc (n, message, (IDictionary<string, object>?)null);
}
[Obsolete ("Use Inc (int, string, IDictionary<string, object>) instead")]
- public void Inc (int n, string message, IDictionary<string, string> metadata)
+ public void Inc (int n, string? message, IDictionary<string, string>? metadata)
{
var converted = metadata.ToDictionary (k => k.Key, k => (object)k.Value);
Inc (n, message, converted);
}
- public void Inc (IDictionary<string, object> metadata)
+ public void Inc (IDictionary<string, object>? metadata)
{
Inc (1, null, metadata);
}
- public void Inc (int n, string message, IDictionary<string, object> metadata)
+ public void Inc (int n, string? message, IDictionary<string, object>? metadata)
{
if (Enabled) {
lock (values) {
@@ -277,12 +279,12 @@ namespace MonoDevelop.Core.Instrumentation
Dec (n, null);
}
- public void Dec (int n, string message)
+ public void Dec (int n, string? message)
{
- Dec (n, message, (IDictionary<string, object>)null);
+ Dec (n, message, (IDictionary<string, object>?)null);
}
- public void Dec (int n, string message, IDictionary<string, object> metadata)
+ public void Dec (int n, string? message, IDictionary<string, object>? metadata)
{
if (Enabled) {
lock (values) {
@@ -299,12 +301,12 @@ namespace MonoDevelop.Core.Instrumentation
SetValue (value, null);
}
- public void SetValue (int value, string message)
+ public void SetValue (int value, string? message)
{
- SetValue (value, message, (IDictionary<string, object>)null);
+ SetValue (value, message, null);
}
- public void SetValue (int value, string message, IDictionary<string, object> metadata)
+ public void SetValue (int value, string? message, IDictionary<string, object>? metadata)
{
if (Enabled) {
lock (values) {
@@ -339,14 +341,14 @@ namespace MonoDevelop.Core.Instrumentation
{
if (Enabled) {
lock (values) {
- StoreValue (message, null, (IDictionary<string, object>)null);
+ StoreValue (message, null, null);
}
}
if (logMessages && message != null)
InstrumentationService.LogMessage (message);
}
- public override object InitializeLifetimeService ()
+ public override object? InitializeLifetimeService ()
{
return null;
}
@@ -403,15 +405,15 @@ namespace MonoDevelop.Core.Instrumentation
[Serializable]
public readonly struct CounterValue
{
- readonly TimerTraceList traces;
- readonly IDictionary<string, object> metadata;
+ readonly TimerTraceList? traces;
+ readonly IDictionary<string, object>? metadata;
- internal CounterValue (int value, int totalCount, DateTime timestamp, IDictionary<string, object> metadata)
+ internal CounterValue (int value, int totalCount, DateTime timestamp, IDictionary<string, object>? metadata)
: this (value, totalCount, timestamp, null, null, metadata)
{
}
- internal CounterValue (int value, int totalCount, DateTime timestamp, string message, TimerTraceList traces, IDictionary<string, object> metadata)
+ internal CounterValue (int value, int totalCount, DateTime timestamp, string? message, TimerTraceList? traces, IDictionary<string, object>? metadata)
{
Value = value;
TimeStamp = timestamp;
@@ -430,11 +432,11 @@ namespace MonoDevelop.Core.Instrumentation
public int ThreadId { get; }
- public string Message { get; }
+ public string? Message { get; }
public bool HasTimerTraces => traces != null;
- public IDictionary<string, object> Metadata {
+ public IDictionary<string, object>? Metadata {
get {
// If the value is for a timer, metadata will be stored in the traces list.
// That's because metadata may be allocated after CounterValue has been
@@ -447,7 +449,7 @@ namespace MonoDevelop.Core.Instrumentation
public IEnumerable<TimerTrace> GetTimerTraces ()
{
- TimerTrace trace = traces?.FirstTrace;
+ TimerTrace? trace = traces?.FirstTrace;
while (trace != null) {
yield return trace;
trace = trace.Next;
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/CounterCategory.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/CounterCategory.cs
index d18026491b..fc9a2ebffe 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/CounterCategory.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/CounterCategory.cs
@@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+#nullable enable
+
using System;
using System.Collections.Generic;
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationConsumer.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationConsumer.cs
index 344a786516..6456c35a50 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationConsumer.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationConsumer.cs
@@ -23,6 +23,9 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+
+#nullable enable
+
using System;
namespace MonoDevelop.Core.Instrumentation
@@ -55,7 +58,7 @@ namespace MonoDevelop.Core.Instrumentation
/// <returns>An IDisposable object that is disposed when the timing operation ends.</returns>
/// <param name="counter">The timer counter</param>
/// <param name="value">The value</param>
- public virtual IDisposable BeginTimer (TimerCounter 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 dfee0cc691..c034c4abdf 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationService.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/InstrumentationService.cs
@@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+#nullable enable
+
using System;
using System.IO;
using System.Collections.Generic;
@@ -54,7 +56,7 @@ namespace MonoDevelop.Core.Instrumentation
static bool enabled = true;
static DateTime startTime = DateTime.Now;
static int publicPort = -1;
- static Thread autoSaveThread;
+ static Thread? autoSaveThread;
static bool stopping;
static int autoSaveInterval;
static bool handlersLoaded;
@@ -206,11 +208,9 @@ namespace MonoDevelop.Core.Instrumentation
public static IInstrumentationService GetServiceData ()
{
- return new InstrumentationServiceData {
+ return new InstrumentationServiceData (counters, categories) {
EndTime = DateTime.Now,
StartTime = StartTime,
- Counters = counters,
- Categories = categories
};
}
@@ -244,32 +244,32 @@ namespace MonoDevelop.Core.Instrumentation
return CreateCounter (name, null);
}
- public static Counter CreateCounter (string name, string category)
+ public static Counter CreateCounter (string name, string? category)
{
return CreateCounter (name, category, false);
}
- public static Counter CreateCounter (string name, string category, bool logMessages)
+ public static Counter CreateCounter (string name, string? category, bool logMessages)
{
return CreateCounter (name, category, logMessages, null, false);
}
- public static Counter CreateCounter (string name, string category = null, bool logMessages = false, string id = null)
+ public static Counter CreateCounter (string name, string? category = null, bool logMessages = false, string? id = null)
{
return CreateCounter (name, category, logMessages, id, false);
}
- public static Counter<T> CreateCounter<T> (string name, string category = null, bool logMessages = false, string id = null) where T : CounterMetadata, new()
+ public static Counter<T> CreateCounter<T> (string name, string? category = null, bool logMessages = false, string? id = null) where T : CounterMetadata, new()
{
return (Counter<T>) CreateCounter<T> (name, category, logMessages, id, false);
}
- static Counter CreateCounter (string name, string category, bool logMessages, string id, bool isTimer)
+ static Counter CreateCounter (string name, string? category, bool logMessages, string? id, bool isTimer)
{
return CreateCounter<CounterMetadata> (name, category, logMessages, id, isTimer);
}
- static Counter CreateCounter<T> (string name, string category, bool logMessages, string id, bool isTimer) where T:CounterMetadata, new()
+ static Counter CreateCounter<T> (string name, string? category, bool logMessages, string? id, bool isTimer) where T:CounterMetadata, new()
{
if (name == null)
throw new ArgumentNullException ("name", "Counters must have a Name");
@@ -280,14 +280,14 @@ namespace MonoDevelop.Core.Instrumentation
category = "Global";
lock (counters) {
- CounterCategory cat = GetCategory (category);
+ CounterCategory? cat = GetCategory (category);
if (cat == null) {
cat = new CounterCategory (category);
categories.Add (cat);
}
var c = isTimer ? new TimerCounter<T> (name, cat) : (Counter) new Counter<T> (name, cat);
- c.Id = id;
+ c.Id = id!;
c.LogMessages = logMessages;
cat.AddCounter (c);
@@ -296,7 +296,7 @@ namespace MonoDevelop.Core.Instrumentation
old.Disposed = true;
counters [name] = c;
if (!string.IsNullOrEmpty (id)) {
- countersByID [id] = c;
+ countersByID [id!] = c;
}
foreach (var h in handlers) {
@@ -309,12 +309,12 @@ namespace MonoDevelop.Core.Instrumentation
}
}
- public static MemoryProbe CreateMemoryProbe (string name)
+ public static MemoryProbe? CreateMemoryProbe (string name)
{
return CreateMemoryProbe (name, null);
}
- public static MemoryProbe CreateMemoryProbe (string name, string category)
+ public static MemoryProbe? CreateMemoryProbe (string name, string? category)
{
if (!enabled)
return null;
@@ -332,17 +332,13 @@ namespace MonoDevelop.Core.Instrumentation
return CreateTimerCounter (name, null);
}
- public static TimerCounter CreateTimerCounter (string name, string category)
+ public static TimerCounter CreateTimerCounter (string name, string? category)
{
return CreateTimerCounter (name, category, 0, false);
}
- public static TimerCounter CreateTimerCounter (string name, string category, double minSeconds, bool logMessages)
- {
- 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)
+ 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.LogMessages = logMessages;
@@ -350,7 +346,7 @@ namespace MonoDevelop.Core.Instrumentation
return c;
}
- public static TimerCounter<T> CreateTimerCounter<T> (string name, string category = null, double minSeconds = 0, bool logMessages = false, string id = null) where T:CounterMetadata, new()
+ public static TimerCounter<T> CreateTimerCounter<T> (string name, string? category = null, double minSeconds = 0, bool logMessages = false, string? id = null) where T:CounterMetadata, new()
{
var c = (TimerCounter<T>) CreateCounter<T> (name, category, logMessages, id, true);
c.LogMessages = logMessages;
@@ -381,7 +377,7 @@ namespace MonoDevelop.Core.Instrumentation
}
}
- public static CounterCategory GetCategory (string name)
+ public static CounterCategory? GetCategory (string name)
{
lock (counters) {
foreach (CounterCategory cat in categories)
@@ -437,7 +433,7 @@ namespace MonoDevelop.Core.Instrumentation
class IntrumentationMonitor: ProgressMonitor
{
TimerCounter counter;
- Stack<ITimeTracker> timers = new Stack<ITimeTracker> ();
+ Stack<ITimeTracker?> timers = new Stack<ITimeTracker?> ();
public IntrumentationMonitor (TimerCounter counter)
{
@@ -447,7 +443,7 @@ namespace MonoDevelop.Core.Instrumentation
protected override void OnWriteLog (string message)
{
if (timers.Count > 0)
- timers.Peek ().Trace (message);
+ timers.Peek ()?.Trace (message);
}
protected override void OnBeginTask (string name, int totalWork, int stepWork)
@@ -464,7 +460,7 @@ namespace MonoDevelop.Core.Instrumentation
protected override void OnEndTask (string name, int totalWork, int stepWork)
{
if (timers.Count > 0) {
- ITimeTracker c = timers.Pop ();
+ ITimeTracker? c = timers.Pop ();
if (c != null)
c.End ();
}
@@ -477,7 +473,7 @@ namespace MonoDevelop.Core.Instrumentation
DateTime EndTime { get; }
IEnumerable<Counter> GetCounters ();
Counter GetCounter (string name);
- CounterCategory GetCategory (string name);
+ CounterCategory? GetCategory (string name);
IEnumerable<CounterCategory> GetCategories ();
}
@@ -505,7 +501,7 @@ namespace MonoDevelop.Core.Instrumentation
return InstrumentationService.GetCounter (name);
}
- public CounterCategory GetCategory (string name)
+ public CounterCategory? GetCategory (string name)
{
return InstrumentationService.GetCategory (name);
}
@@ -515,7 +511,7 @@ namespace MonoDevelop.Core.Instrumentation
return InstrumentationService.GetCategories ();
}
- public override object InitializeLifetimeService ()
+ public override object? InitializeLifetimeService ()
{
return null;
}
@@ -526,8 +522,14 @@ namespace MonoDevelop.Core.Instrumentation
{
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
- public Dictionary <string, Counter> Counters { get; set; }
- public List<CounterCategory> Categories { get; set; }
+ public Dictionary <string, Counter> Counters { get; }
+ public List<CounterCategory> Categories { get; }
+
+ public InstrumentationServiceData (Dictionary<string, Counter> counters, List<CounterCategory> categories)
+ {
+ Counters = counters;
+ Categories = categories;
+ }
public IEnumerable<Counter> GetCounters ()
{
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/MemoryProbe.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/MemoryProbe.cs
index a0f7c58d03..784aaed430 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/MemoryProbe.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/MemoryProbe.cs
@@ -24,13 +24,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+#nullable enable
+
using System;
namespace MonoDevelop.Core.Instrumentation
{
public class MemoryProbe
{
- Counter c;
+ readonly Counter c;
public MemoryProbe (Counter c)
{
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 833cc45079..130f28ac79 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimeCounter.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimeCounter.cs
@@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+#nullable enable
+
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -41,18 +43,18 @@ namespace MonoDevelop.Core.Instrumentation
public interface ITimeTracker<T>: IDisposable, ITimeTracker where T : CounterMetadata
{
- T Metadata { get; }
+ T? Metadata { get; }
}
interface ITimeCounter: ITimeTracker
{
void AddHandlerTracker (IDisposable t);
- TimerTraceList TraceList { get; }
+ TimerTraceList? TraceList { get; }
}
class DummyTimerCounter<T>: ITimeTracker<T> where T : CounterMetadata
{
- public DummyTimerCounter (T metadata)
+ public DummyTimerCounter (T? metadata)
{
Metadata = metadata;
}
@@ -69,23 +71,23 @@ namespace MonoDevelop.Core.Instrumentation
{
}
- public T Metadata { get; }
+ public T? Metadata { get; }
public TimeSpan Duration { get; }
}
class TimeCounter<T>: ITimeTracker<T>, ITimeCounter where T:CounterMetadata, new()
{
- Stopwatch stopWatch = new Stopwatch ();
- TimerTraceList traceList;
- TimerTrace lastTrace;
- TimerCounter counter;
- object linkedTrackers;
+ readonly Stopwatch stopWatch = new Stopwatch ();
+ TimerTraceList? traceList;
+ TimerTrace? lastTrace;
+ TimerCounter? counter;
+ object? linkedTrackers;
long lastTraceTime;
- T metadata;
+ T? metadata;
CancellationToken cancellationToken;
- internal TimeCounter (TimerCounter counter, T metadata, CancellationToken cancellationToken)
+ internal TimeCounter (TimerCounter counter, T? metadata, CancellationToken cancellationToken)
{
this.counter = counter;
this.metadata = metadata;
@@ -123,7 +125,7 @@ namespace MonoDevelop.Core.Instrumentation
((List<IDisposable>)linkedTrackers).Add (t);
}
- TimerTraceList ITimeCounter.TraceList {
+ TimerTraceList? ITimeCounter.TraceList {
get { return this.traceList; }
}
@@ -139,7 +141,7 @@ namespace MonoDevelop.Core.Instrumentation
lastTrace.Next = t;
lastTrace = t;
}
- traceList.TotalTime = t.Timestamp - traceList.FirstTrace.Timestamp;
+ traceList.TotalTime = t.Timestamp - traceList.FirstTrace!.Timestamp;
}
if (counter?.LogMessages == true) {
var time = stopWatch.ElapsedMilliseconds;
@@ -166,7 +168,7 @@ namespace MonoDevelop.Core.Instrumentation
if (metadata != null && cancellationToken.IsCancellationRequested)
metadata.SetUserCancel ();
- if (counter.LogMessages) {
+ if (counter!.LogMessages) {
var time = stopWatch.ElapsedMilliseconds;
InstrumentationService.LogMessage (string.Format ("[{0} (+{1})] END: {2}", time, (time - lastTraceTime), counter.Name));
}
@@ -201,19 +203,19 @@ namespace MonoDevelop.Core.Instrumentation
[DebuggerDisplay ("{DebuggingText}")]
class TimerTraceList
{
- public TimerTrace FirstTrace;
+ public TimerTrace? FirstTrace;
public TimeSpan TotalTime;
public int ValueIndex;
// Timer metadata is stored here, since it may change while the timer is alive.
// CounterValue will take the metadata from here.
- public IDictionary<string, object> Metadata;
+ public IDictionary<string, object>? Metadata;
string DebuggingText {
get {
var stringBuilder = new StringBuilder ();
var current = FirstTrace;
- TimerTrace previous = null;
+ TimerTrace? previous = null;
while (current != null) {
stringBuilder.Append (previous == null ? "N/A" : (current.Timestamp - previous.Timestamp).ToString (@"ss\.fff"));
stringBuilder.Append (" : ");
@@ -229,8 +231,8 @@ namespace MonoDevelop.Core.Instrumentation
[Serializable]
public class TimerTrace
{
- internal TimerTrace Next;
+ internal TimerTrace? Next;
public DateTime Timestamp { get; set; }
- public string Message { get; set; }
+ public string? Message { get; set; }
}
}
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 c5ed3fd66a..a3414ac9e7 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimerCounter.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Instrumentation/TimerCounter.cs
@@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+#nullable enable
+
using System;
using System.Collections.Generic;
using System.Threading;
@@ -93,27 +95,27 @@ namespace MonoDevelop.Core.Instrumentation
public ITimeTracker BeginTiming ()
{
- return BeginTiming (null, (IDictionary<string, object>)null);
+ return BeginTiming (null, null);
}
public ITimeTracker BeginTiming (string message)
{
- return BeginTiming (message, (IDictionary<string, object>)null);
+ return BeginTiming (message, null);
}
[Obsolete ("Use BeginTiming (string, IDictionary<string,object>) instead")]
- public ITimeTracker BeginTiming (IDictionary<string, string> metadata)
+ public ITimeTracker BeginTiming (IDictionary<string, string>? metadata)
{
var converted = metadata.ToDictionary (k => k.Key, k => (object)(k.Value));
return BeginTiming (null, converted);
}
- public ITimeTracker BeginTiming (string message, IDictionary<string, object> metadata)
+ public ITimeTracker BeginTiming (string? message, IDictionary<string, object>? metadata)
{
return BeginTiming (message, metadata != null ? new CounterMetadata (metadata) : null, CancellationToken.None);
}
- internal ITimeTracker<T> BeginTiming<T> (string message, T metadata, CancellationToken cancellationToken) where T : CounterMetadata, new()
+ internal ITimeTracker<T> BeginTiming<T> (string? message, T? metadata, CancellationToken cancellationToken) where T : CounterMetadata, new()
{
if (!Enabled && !LogMessages) {
return new DummyTimerCounter<T> (metadata);
@@ -126,7 +128,10 @@ namespace MonoDevelop.Core.Instrumentation
count++;
totalCount++;
int i = StoreValue (message, c, metadata?.Properties);
- ((ITimeCounter)c).TraceList.ValueIndex = i;
+
+ var traceList = ((ITimeCounter)c).TraceList;
+ if (traceList != null)
+ traceList.ValueIndex = i;
}
} else {
if (message != null)
@@ -231,11 +236,20 @@ namespace MonoDevelop.Core.Instrumentation
public void SetSuccess () => Result = CounterResult.Success;
public void SetUserCancel () => Result = CounterResult.UserCancel;
- protected void SetProperty (object value, [CallerMemberName]string name = null)
- => Properties[name] = value;
+ protected void SetProperty (object value, [CallerMemberName]string? name = null)
+ {
+ if (name == null)
+ throw new ArgumentNullException (nameof (name));
- protected T GetProperty<T> ([CallerMemberName]string name = null)
+ Properties [name] = value;
+ }
+
+ // [return: MaybeNull]
+ protected T GetProperty<T> ([CallerMemberName]string? name = null)
{
+ if (name == null)
+ throw new ArgumentNullException (nameof (name));
+
if (Properties.TryGetValue (name, out var result)) {
return (T)Convert.ChangeType (result, typeof (T), CultureInfo.InvariantCulture);
}
@@ -243,8 +257,11 @@ namespace MonoDevelop.Core.Instrumentation
return default (T);
}
- protected bool ContainsProperty ([CallerMemberName]string propName = null)
+ protected bool ContainsProperty ([CallerMemberName]string? propName = null)
{
+ if (propName == null)
+ throw new ArgumentNullException (nameof (propName));
+
return Properties.ContainsKey (propName);
}
}
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Utilities/RaceChecker.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Utilities/RaceChecker.cs
index 0c4e11d1ca..28880efdcc 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Utilities/RaceChecker.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Utilities/RaceChecker.cs
@@ -23,6 +23,8 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+#nullable enable
+
using System;
using System.Threading;
using MonoDevelop.Core;
@@ -31,7 +33,7 @@ namespace MonoDevelop.Utilities
{
abstract class RaceChecker
{
- string lockHolderStacktrace;
+ string? lockHolderStacktrace;
readonly object lockObject;
readonly Disposer lockRelease;
@@ -48,7 +50,7 @@ namespace MonoDevelop.Utilities
} else {
Monitor.Enter (lockObject);
var thisTrace = Environment.StackTrace;
- OnRace (lockHolderStacktrace, thisTrace);
+ OnRace (lockHolderStacktrace!, thisTrace);
lockHolderStacktrace = thisTrace;
}
@@ -57,7 +59,7 @@ namespace MonoDevelop.Utilities
protected abstract void OnRace (string trace1, string trace2);
- class Disposer : IDisposable
+ sealed class Disposer : IDisposable
{
readonly object lockObject;
@@ -74,7 +76,7 @@ namespace MonoDevelop.Utilities
}
}
- class LoggingRaceChecker : RaceChecker
+ sealed class LoggingRaceChecker : RaceChecker
{
protected override void OnRace (string trace1, string trace2)
{
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Utilities/SampleProfiler.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Utilities/SampleProfiler.cs
index 2a8f1cfa93..cfe52cf559 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Utilities/SampleProfiler.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Utilities/SampleProfiler.cs
@@ -23,11 +23,10 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+#nullable enable
+
using System;
-using System.Net.Sockets;
-using System.Net;
using System.Diagnostics;
-using System.Threading;
using MonoDevelop.Core;
using System.IO;
using System.Runtime.InteropServices;
@@ -35,7 +34,6 @@ using System.Text.RegularExpressions;
using System.Globalization;
using System.Collections.Generic;
using System.Text;
-using System.Threading.Tasks;
namespace MonoDevelop.Utilities
{
@@ -111,7 +109,7 @@ namespace MonoDevelop.Utilities
[DllImport ("__Internal")]
extern static string mono_pmip (long offset);
- readonly static Dictionary<long, string> methodsCache = new Dictionary<long, string> ();
+ readonly static Dictionary<long, string?> methodsCache = new Dictionary<long, string?> ();
public static void ConvertJITAddressesToMethodNames (string outputPath, string fileName, string profilingType)
{
@@ -167,9 +165,9 @@ namespace MonoDevelop.Utilities
}
}
- static string GetSymbolicatedLine (long offset)
+ static string? GetSymbolicatedLine (long offset)
{
- if (!methodsCache.TryGetValue (offset, out var pmipMethodName)) {
+ if (!methodsCache.TryGetValue (offset, out string? pmipMethodName)) {
pmipMethodName = mono_pmip (offset)?.TrimStart ();
if (pmipMethodName != null)
pmipMethodName = PmipParser.ToSample (pmipMethodName, offset);
@@ -194,7 +192,6 @@ namespace MonoDevelop.Utilities
try {
var input = initialInput.AsSpan ();
var sb = new StringBuilder ();
- string filename = null;
// Cut off wrapper part.
if (input.StartsWith ("(wrapper".AsSpan ())) {
@@ -249,6 +246,7 @@ namespace MonoDevelop.Utilities
// Skip the rest of the block(s) after the method signature until we get a path.
input = input.Slice (input.IndexOf ('[') + 1).TrimStart ();
+ string? filename = null;
if (input[0] == '/') {
// We have a filename
var end = input.IndexOf (']');