public static bool MonitorUpdateDuration(IEnumerator tickable, string runnerName) { var key = tickable.ToString().FastConcat(runnerName); #if ENABLE_PIX_EVENTS PixWrapper.PIXBeginEventEx(0x11000000, key); #endif _stopwatch.Start(); var result = tickable.MoveNext(); _stopwatch.Stop(); #if ENABLE_PIX_EVENTS PixWrapper.PIXEndEventEx(); #endif lock (LOCK_OBJECT) { TaskInfo info; if (taskInfos.TryGetValue(key, out info) == false) { info = new TaskInfo(tickable); info.AddThreadInfo(runnerName.FastConcat(": ")); taskInfos.Add(key, ref info); } else { info.AddUpdateDuration(_stopwatch.Elapsed.TotalMilliseconds); taskInfos.Update(key, ref info); } } _stopwatch.Reset(); return(result); }
public static bool MonitorUpdateDuration <T #if ENABLE_PLATFORM_PROFILER , PP #endif >(T sveltoTask, string runnerName #if ENABLE_PLATFORM_PROFILER , PP profiler #endif ) where T : ISveltoTask #if ENABLE_PLATFORM_PROFILER where PP : IPlatformProfiler #endif { var key = sveltoTask.ToString().FastConcat(runnerName); bool result; #if ENABLE_PLATFORM_PROFILER using (profiler.Sample(sveltoTask.ToString())) #endif { _stopwatch.Start(); #if ENABLE_PIX_EVENTS PixWrapper.PIXBeginEventEx(0x11000000, key); #endif result = sveltoTask.MoveNext(); #if ENABLE_PIX_EVENTS PixWrapper.PIXEndEventEx(); #endif _stopwatch.Stop(); } lock (LOCK_OBJECT) { if (taskInfos.TryGetValue(key, out var info) == false) { info = new TaskInfo(sveltoTask.ToString()); info.AddThreadInfo(runnerName.FastConcat(": ")); taskInfos.Add(key, ref info); } else { info.AddUpdateDuration(_stopwatch.Elapsed.TotalMilliseconds); taskInfos.Update(key, ref info); } } _stopwatch.Reset(); return(result); }
public static bool MonitorUpdateDuration <T, PP>(ref T sveltoTask, string runnerName, PP profiler) where T : ISveltoTask where PP : IPlatformProfiler { var samplerName = sveltoTask.name; var key = samplerName.FastConcat(runnerName); bool result; using (profiler.Sample(samplerName)) { _stopwatch.Start(); #if ENABLE_PIX_EVENTS PixWrapper.PIXBeginEventEx(0x11000000, key); #endif result = sveltoTask.MoveNext(); #if ENABLE_PIX_EVENTS PixWrapper.PIXEndEventEx(); #endif _stopwatch.Stop(); } lock (LOCK_OBJECT) { if (taskInfos.TryGetValue(key, out var info) == false) { info = new TaskInfo(samplerName); #warning Todo for seb: avoid allocation here please info.AddThreadInfo(runnerName); taskInfos.Add(key, ref info); } else { info.AddUpdateDuration(_stopwatch.Elapsed.TotalMilliseconds); taskInfos.Update(key, ref info); } } _stopwatch.Reset(); return(result); }
public void UpdateNullFactory() { var dict = new ThreadSafeDictionary <int, int>(); dict.Update(1, 1, null); }
public void Update() { var dict = new ThreadSafeDictionary <int, int>(Enumerable.Range(0, 100).Select(x => new KeyValuePair <int, int>(x, 2 * x))); int val; Assert.IsFalse(dict.Update(10, 10, 1, EqualityComparer <int> .Default, out val)); Assert.AreNotEqual(10, dict[10]); Assert.AreEqual(val, 20); Assert.IsTrue(dict.Update(10, 10, 20, EqualityComparer <int> .Default, out val)); Assert.AreEqual(val, 20); Assert.AreEqual(10, dict[10]); Assert.IsFalse(dict.Update(-1, 10, 10, EqualityComparer <int> .Default, out val)); Assert.AreEqual(0, val); dict[10] = 20; Assert.IsFalse(dict.Update(10, 10, 1, EqualityComparer <int> .Default)); Assert.AreNotEqual(10, dict[10]); Assert.IsTrue(dict.Update(10, 10, 20, EqualityComparer <int> .Default)); Assert.AreEqual(10, dict[10]); Assert.IsFalse(dict.Update(-1, 10, 10, EqualityComparer <int> .Default)); dict[10] = 20; Assert.IsFalse(dict.Update(10, 10, 1, out val)); Assert.AreNotEqual(10, dict[10]); Assert.AreEqual(val, 20); Assert.IsTrue(dict.Update(10, 10, 20, out val)); Assert.AreEqual(val, 20); Assert.AreEqual(10, dict[10]); Assert.IsFalse(dict.Update(-1, 10, 10, out val)); Assert.AreEqual(0, val); dict[10] = 20; Assert.IsFalse(dict.Update(10, 10, 1)); Assert.AreNotEqual(10, dict[10]); Assert.IsTrue(dict.Update(10, 10, 20)); Assert.AreEqual(10, dict[10]); Assert.IsFalse(dict.Update(-1, 10, 10)); dict[10] = 20; Assert.IsFalse(dict.Update(10, 10, x => x == 1, out val)); Assert.AreNotEqual(10, dict[10]); Assert.AreEqual(val, 20); Assert.IsTrue(dict.Update(10, 10, x => x == 20, out val)); Assert.AreEqual(val, 20); Assert.AreEqual(10, dict[10]); Assert.IsFalse(dict.Update(-1, 10, x => true, out val)); Assert.AreEqual(0, val); dict[10] = 20; Assert.IsFalse(dict.Update(10, 10, x => x == 1)); Assert.AreNotEqual(10, dict[10]); Assert.IsTrue(dict.Update(10, 10, x => x == 20)); Assert.AreEqual(10, dict[10]); Assert.IsFalse(dict.Update(-1, 10, x => true)); dict[10] = 20; }