public void findDelegateCreator(ModuleDefinition module) { var callCounter = new CallCounter(); foreach (var type in module.Types) { if (type.Namespace != "" || !DotNetUtils.derivesFromDelegate(type)) { continue; } var cctor = DotNetUtils.getMethod(type, ".cctor"); if (cctor == null) { continue; } foreach (var method in DotNetUtils.getMethodCalls(cctor)) { callCounter.add(method); } } var mostCalls = callCounter.most(); if (mostCalls == null) { return; } setDelegateCreatorMethod(DotNetUtils.getMethod(module, mostCalls)); }
public void FindDelegateCreator(ModuleDefMD module) { var callCounter = new CallCounter(); foreach (var type in module.Types) { if (type.Namespace != "" || !DotNetUtils.DerivesFromDelegate(type)) { continue; } var cctor = type.FindStaticConstructor(); if (cctor == null) { continue; } foreach (var method in DotNetUtils.GetMethodCalls(cctor)) { callCounter.Add(method); } } var mostCalls = callCounter.Most(); if (mostCalls == null) { return; } SetDelegateCreatorMethod(DotNetUtils.GetMethod(module, mostCalls)); }
public ContentStoreInternalTracer(ContentStoreSettings?settings, AbsolutePath rootPath) : base($"{FileSystemContentStoreInternal.Component}({rootPath})") { CallCounters.Add(_createHardLinkCallCounter = new CallCounter(CreateHardLinkCallName)); CallCounters.Add(_placeFileCopyCallCounter = new CallCounter(PlaceFileCopyCallName)); CallCounters.Add(_reconstructCallCounter = new CallCounter(ReconstructCallName)); CallCounters.Add(_evictCallCounter = new CallCounter(EvictCallName)); CallCounters.Add(_purgeCallCounter = new CallCounter(PurgeCallName)); CallCounters.Add(_calibrateCallCounter = new CallCounter(CalibrateCallName)); CallCounters.Add(_hashContentFileCallCounter = new CallCounter(HashContentFileCallName)); CallCounters.Add(_putFileExistingHardlinkCallCounter = new CallCounter(PutFileExistingHardlinkCallName)); CallCounters.Add(_putFileNewHardlinkCallCounter = new CallCounter(PutFileNewHardlinkCallName)); CallCounters.Add(_putFileNewCopyCallCounter = new CallCounter(PutFileNewCopyCallName)); CallCounters.Add(_putContentInternalCallCounter = new CallCounter(PutContentInternalCallName)); CallCounters.Add(_applyPermsCallCounter = new CallCounter(ApplyPermsCallName)); _counters.Add(_startBytesCount = new Counter(StartByteCountName)); _counters.Add(_startFilesCount = new Counter(StartFileCountName)); _counters.Add(_putBytesCount = new Counter(PutBytesCountName)); _counters.Add(_putFilesCount = new Counter(PutFilesCountName)); _counters.Add(_evictBytesCount = new Counter(EvictBytesCountName)); _counters.Add(_evictFilesCount = new Counter(EvictFilesCountName)); _counters.Add(_reconstructCallExceptionCounter = new Counter(ReconstructCallExceptionName)); _traceDiagnosticEvents = settings?.TraceFileSystemContentStoreDiagnosticMessages ?? true; _longOperationDurationThreshold = settings.GetLongOperationDurationThreshold(); }
public ContentStoreInternalTracer(bool traceDiagnosticEvents = false) : base(FileSystemContentStoreInternal.Component) { CallCounters.Add(_createHardLinkCallCounter = new CallCounter(CreateHardLinkCallName)); CallCounters.Add(_placeFileCopyCallCounter = new CallCounter(PlaceFileCopyCallName)); CallCounters.Add(_reconstructCallCounter = new CallCounter(ReconstructCallName)); CallCounters.Add(_evictCallCounter = new CallCounter(EvictCallName)); CallCounters.Add(_purgeCallCounter = new CallCounter(PurgeCallName)); CallCounters.Add(_calibrateCallCounter = new CallCounter(CalibrateCallName)); CallCounters.Add(_hashContentFileCallCounter = new CallCounter(HashContentFileCallName)); CallCounters.Add(_putFileExistingHardlinkCallCounter = new CallCounter(PutFileExistingHardlinkCallName)); CallCounters.Add(_putFileNewHardlinkCallCounter = new CallCounter(PutFileNewHardlinkCallName)); CallCounters.Add(_putFileNewCopyCallCounter = new CallCounter(PutFileNewCopyCallName)); CallCounters.Add(_putContentInternalCallCounter = new CallCounter(PutContentInternalCallName)); CallCounters.Add(_applyPermsCallCounter = new CallCounter(ApplyPermsCallName)); _counters.Add(_startBytesCount = new Counter(StartByteCountName)); _counters.Add(_startFilesCount = new Counter(StartFileCountName)); _counters.Add(_putBytesCount = new Counter(PutBytesCountName)); _counters.Add(_putFilesCount = new Counter(PutFilesCountName)); _counters.Add(_evictBytesCount = new Counter(EvictBytesCountName)); _counters.Add(_evictFilesCount = new Counter(EvictFilesCountName)); _counters.Add(_reconstructCallExceptionCounter = new Counter(ReconstructCallExceptionName)); _traceDiagnosticEvents = traceDiagnosticEvents; }
public void find() { var additionalTypes = new string[] { "System.IntPtr", // "System.Reflection.Assembly", //TODO: Not in unknown DNR version with jitter support }; var checkedMethods = new Dictionary<IMethod, bool>(MethodEqualityComparer.CompareDeclaringTypes); var callCounter = new CallCounter(); int typesLeft = 30; foreach (var type in module.GetTypes()) { var cctor = type.FindStaticConstructor(); if (cctor == null || cctor.Body == null) continue; if (typesLeft-- <= 0) break; foreach (var method in DotNetUtils.getCalledMethods(module, cctor)) { if (!checkedMethods.ContainsKey(method)) { checkedMethods[method] = false; if (method.DeclaringType.BaseType == null || method.DeclaringType.BaseType.FullName != "System.Object") continue; if (!DotNetUtils.isMethod(method, "System.Void", "()")) continue; if (!encryptedResource.couldBeResourceDecrypter(method, additionalTypes)) continue; checkedMethods[method] = true; } else if (!checkedMethods[method]) continue; callCounter.add(method); } } encryptedResource.Method = (MethodDef)callCounter.most(); }
public void CallCountAccumulates() { var counter = new CallCounter("name"); counter.Completed(0); counter.Completed(0); counter.Calls.Should().Be(2); }
private void IncreaseCallCounter(string method) { if (!CallCounter.ContainsKey(method)) { CallCounter[method] = 0; } ++CallCounter[method]; }
public async Task TestTimerPeriod() { var counter = new CallCounter(); using(new Timer(TimerCallback, counter, 100, 100)) { await Task.Delay(350); } Assert.That(counter.Count, Is.EqualTo(3)); }
public DistributedContentTracer() : base(Component) { Counters.Add(_remoteBytesCounter = new Counter(RemoteBytesCopiedCountName)); Counters.Add(_remoteFilesCopiedCounter = new Counter(RemoteCopyFileSuccessCountName)); Counters.Add(_remoteFilesFailedCopyCounter = new Counter(RemoteCopyFileFailCountName)); CallCounters.Add(_remoteCopyCallCounter = new CallCounter(RemoteCopyFileCallName)); }
public void CallDurationAccumulates() { var counter = new CallCounter("name"); counter.Completed(1); counter.Duration.Ticks.Should().Be(1); counter.Completed(TimeSpan.FromMilliseconds(1).Ticks); counter.Duration.Ticks.Should().Be(TimeSpan.FromMilliseconds(1).Ticks + 1); ((long)counter.Duration.TotalMilliseconds).Should().Be(1); }
public async Task TestCancelTimer() { var counter = new CallCounter(); using(var timer = new Timer(TimerCallback, counter, 100, 100)) { timer.Cancel(); await Task.Delay(200); } Assert.That(counter.Count, Is.EqualTo(0)); }
public async Task TestTimerPeriod() { var counter = new CallCounter(); using (new Timer(TimerCallback, counter, 100, 100)) { await Task.Delay(350); } Assert.That(counter.Count, Is.EqualTo(3)); }
public void AsyncMaxAttemptsFitExceptionTest() { var beforeRetryCount = 0; var callActionCount = new CallCounter(); var callStrategy = new MaxAttemptsRetriableAsyncCallStrategy(5, 1); Assert.ThrowsAsync <AttemptsExceededException>(() => callStrategy.CallAsync(() => IOExceptionActionAsync(callActionCount), e => e is IOException, () => beforeRetryCount++)); Assert.That(beforeRetryCount, Is.EqualTo(4)); Assert.That(callActionCount.Count, Is.EqualTo(5)); }
public void MaxAttemptsNotFitExceptionTest() { var beforeRetryCount = 0; var callActionCount = new CallCounter(); var callStrategy = new MaxAttemptsRetriableCallStrategy(5, 1); Assert.Throws <IOException>(() => callStrategy.Call(() => IOExceptionAction(callActionCount), e => e is StackOverflowException, () => beforeRetryCount++)); Assert.That(beforeRetryCount, Is.EqualTo(0)); Assert.That(callActionCount.Count, Is.EqualTo(1)); }
public async Task TestCancelTimer() { var counter = new CallCounter(); using (var timer = new Timer(TimerCallback, counter, 100, 100)) { timer.Cancel(); await Task.Delay(200); } Assert.That(counter.Count, Is.EqualTo(0)); }
/// <summary> /// Initializes a new instance of the <see cref="RedisContentLocationStoreTracer"/> class. /// </summary> public RedisContentLocationStoreTracer(string name) : base(name) { Contract.Requires(name != null); CallCounters.Add(_updateBulkCallCounter = new CallCounter(UpdateBulkCallName)); CallCounters.Add(_getBulkCallCounter = new CallCounter(GetBulkCallName)); CallCounters.Add(_trimBulkCallCounter = new CallCounter(TrimBulkCallName)); CallCounters.Add(_trimOrGetLastAccessTimeCallCounter = new CallCounter(TrimOrGetLastAccessTimeCallName)); CallCounters.Add(_trimBulkLocalCallCounter = new CallCounter(TrimBulkLocalCallName)); CallCounters.Add(_touchBulkCallCounter = new CallCounter(TouchBulkCallName)); }
public void find() { var additionalTypes = new string[] { "System.IntPtr", // "System.Reflection.Assembly", //TODO: Not in unknown DNR version with jitter support }; var checkedMethods = new Dictionary <MethodReferenceAndDeclaringTypeKey, bool>(); var callCounter = new CallCounter(); int typesLeft = 30; foreach (var type in module.GetTypes()) { var cctor = DotNetUtils.getMethod(type, ".cctor"); if (cctor == null || cctor.Body == null) { continue; } if (typesLeft-- <= 0) { break; } foreach (var method in DotNetUtils.getCalledMethods(module, cctor)) { var key = new MethodReferenceAndDeclaringTypeKey(method); if (!checkedMethods.ContainsKey(key)) { checkedMethods[key] = false; if (method.DeclaringType.BaseType == null || method.DeclaringType.BaseType.FullName != "System.Object") { continue; } if (!DotNetUtils.isMethod(method, "System.Void", "()")) { continue; } if (!encryptedResource.couldBeResourceDecrypter(method, additionalTypes)) { continue; } checkedMethods[key] = true; } else if (!checkedMethods[key]) { continue; } callCounter.add(method); } } encryptedResource.Method = (MethodDefinition)callCounter.most(); }
public ContentSessionTracer(string name) : base(name) { CallCounters.Add(_getStatsCallCounter = new CallCounter(GetStatsCallName)); CallCounters.Add(_pinCallCounter = new CallCounter(PinCallName)); CallCounters.Add(_pinBulkCallCounter = new CallCounter(PinBulkCallName)); CallCounters.Add(_openStreamCallCounter = new CallCounter(OpenStreamCallName)); CallCounters.Add(_placeFileCallCounter = new CallCounter(PlaceFileCallName)); CallCounters.Add(_putStreamCallCounter = new CallCounter(PutStreamCallName)); CallCounters.Add(_putFileCallCounter = new CallCounter(PutFileCallName)); Counters.Add(_pinBulkFileCountCounter = new Counter(PinBulkFileCountCounterName)); }
public void Setup() { this.callCounter = new CallCounter(); var container = new UnityContainer(); container.AddNewExtension <Interception>(); container.AddNewExtension <TransientPolicyBuildUpExtension>(); container.RegisterInstance <CallCounter>(this.callCounter); var serviceLocator = new UnityServiceLocator(container); this.policyInjector = new PolicyInjector(serviceLocator); }
public async Task CountdownTimer_Start_StartsCountdown() { // Arrange var timer = CreateCountdownTimer(); var callCounter = new CallCounter(); // Act timer.Start(50, callCounter.Invoke); await Process(callCounter); // Assert callCounter.Count.Should().Be(1); }
/// <summary> /// Initializes a new instance of the <see cref="DistributedCacheSessionTracer" /> class. /// </summary> public DistributedCacheSessionTracer(ILogger logger, string name) : base(name) { CallCounters.Add(_getSelectorsCallCounter = new CallCounter(GetSelectorsCallName)); CallCounters.Add(_addSelectorsCallCounter = new CallCounter(AddSelectorsCallName)); CallCounters.Add(_invalidateCacheEntryCallCounter = new CallCounter(InvalidateCacheEntryCallName)); CallCounters.Add(_getContentHashListCallCounter = new CallCounter(GetContentHashListCallName)); CallCounters.Add(_addContentHashListCallCounter = new CallCounter(AddContentHashListCallName)); Counters.Add(_getContentHashListFetchedDistributed = new Counter(GetContentHashListFetchedDistributedName)); Counters.Add(_getContentHashListFetchedBacking = new Counter(GetContentHashListFetchedBackingName)); Counters.Add(_getSelectorsFetchedDistributed = new Counter(GetSelectorsFetchedDistributedName)); Counters.Add(_getSelectorsFetchedBacking = new Counter(GetSelectorsFetchedBackingName)); }
public void AlwaysCallbackTest() { CallCounter counter = new CallCounter(); Deferred<None> d = new Deferred<None>(); d.Always(p => counter.Always++ ); d.Resolve(); d.Reject(); Assert.AreEqual(2, counter.Always); }
private static async Task Process(CallCounter callCounter) { for (var i = 0; i < 20; i++) { if (callCounter.Count == 0) { await Task.Delay(50); } else { break; } } }
/// <summary> /// Initializes a new instance of the <see cref="SQLiteMemoizationStoreTracer"/> class. /// </summary> /// <param name="logger">Logger</param> /// <param name="name">Tracer Name</param> public SQLiteMemoizationStoreTracer(ILogger logger, string name) : base(logger, name) { Counters.Add(_masterDbCorruptionCount = new Counter("MasterDbCorruptionCount")); Counters.Add(_backupDbCorruptionCount = new Counter("BackupDbCorruptionCount")); Counters.Add(_sqliteMarkerCreatedCount = new Counter("SQLiteMarkerCreated")); Counters.Add(_sqliteMarkerCreateFailedCount = new Counter("SQLiteMarkerCreateFailed")); Counters.Add(_sqliteMarkerDeletedCount = new Counter("SQLiteMarkerDeleted")); Counters.Add(_sqliteMarkerDeleteFailedCount = new Counter("SQLiteMarkerDeleteFailed")); Counters.Add(_sqliteMarkerLeftBehindCount = new Counter("SQLiteMarkerLeftBehind")); Counters.Add(_sqliteIntegrityCheckSucceeded = new Counter("SQLiteIntegrityCheckSucceeded")); Counters.Add(_sqliteIntegrityCheckFailed = new Counter("SQLiteIntegrityCheckFailed")); CallCounters.Add(_sqliteIntegrityCheckCallCounter = new CallCounter(SQLiteIntegrityCheckCallName)); _sqliteDatabaseSize = -1; }
public async Task CountdownTimer_AbortStart_StartsNewCountdown() { const int millisecondStartDelay = 100; // Arrange var timer = CreateCountdownTimer(); var callCounter = new CallCounter(); timer.Start(millisecondStartDelay, callCounter.Invoke); // Act timer.Abort(); timer.Start(millisecondStartDelay, callCounter.Invoke); await Process(callCounter); // Assert callCounter.Count.Should().Be(1); }
void init() { var callCounter = new CallCounter(); int count = 0; foreach (var type in module.GetTypes()) { if (count >= 40) { break; } foreach (var method in type.Methods) { if (method.Name != ".ctor" && method.Name != ".cctor" && module.EntryPoint != method) { continue; } foreach (var calledMethod in DotNetUtils.getCalledMethods(module, method)) { if (!calledMethod.IsStatic || calledMethod.Body == null) { continue; } if (!DotNetUtils.isMethod(calledMethod, "System.Void", "()")) { continue; } if (isEmptyClass(calledMethod)) { callCounter.add(calledMethod); count++; } } } } int numCalls; var theMethod = (MethodDef)callCounter.most(out numCalls); if (numCalls >= 10) { emptyMethod = theMethod; } }
public void DeferTest() { CallCounter counter = new CallCounter(); Deferred.Defer<None>(d => d.Resolve() ).Done(p => counter.Done++ ).Next<None>(d => { counter.Next++; d.Resolve(); }).Next<None>(d => { counter.Next++; d.Reject(); }); Assert.AreEqual(1, counter.Done); Assert.AreEqual(2, counter.Next); }
public void FailCallbackTest() { CallCounter counter = new CallCounter(); Deferred<None> d = new Deferred<None>(); d.Done(p => counter.Done++ ).Fail(p => counter.Fail++ ).Progress(p => counter.Progress++ ); d.Reject(); Assert.AreEqual(0, counter.Done); Assert.AreEqual(1, counter.Fail); Assert.AreEqual(0, counter.Progress); }
public MemoizationStoreTracer(string name) : base(name) { Contract.Requires(name != null); CallCounters.Add(_getStatsCallCounter = new CallCounter(GetStatsCallName)); CallCounters.Add(_getSelectorsCallCounter = new CallCounter(GetSelectorsCallName)); CallCounters.Add(_getContentHashListCallCounter = new CallCounter(GetContentHashListCallName)); CallCounters.Add(_addOrGetContentHashListCallCounter = new CallCounter(AddOrGetContentHashListCallName)); CallCounters.Add(_incorporateStrongFingerprintsCallCounter = new CallCounter(IncorporateStrongFingerprintsCallName)); Counters.Add(_startContentHashListsCount = new Counter(StartContentHashListsCountName)); Counters.Add(_getContentHashListMissCounter = new Counter(GetContentHashListMissCountName)); Counters.Add(_getContentHashListHitCounter = new Counter(GetContentHashListHitCountName)); Counters.Add(_getContentHashListErrorCounter = new Counter(GetContentHashListErrorCountName)); Counters.Add(_addOrGetContentHashListAddCounter = new Counter(AddOrGetContentHashListAddCountName)); Counters.Add(_addOrGetContentHashListGetCounter = new Counter(AddOrGetContentHashListGetCountName)); Counters.Add(_addOrGetContentHashListErrorCounter = new Counter(AddOrGetContentHashListErrorCountName)); Counters.Add(_getSelectorsEmptyCounter = new Counter(GetSelectorsEmptyCountName)); }
public async Task CountdownTimer_StartTwice_AbortsOldTimer() { const int millisecondStartDelay = 10; // Arrange var timer = CreateCountdownTimer(); var callCounter1 = new CallCounter(); var callCounter2 = new CallCounter(); // Act timer.Start(millisecondStartDelay, callCounter1.Invoke); timer.Start(millisecondStartDelay, callCounter2.Invoke); await Task.Delay(250); await Process(callCounter2); // Assert callCounter2.Count.Should().Be(1); callCounter1.Count.Should().Be(0); }
public async Task GetCredentialProvidersExecutedOnlyOnce() { var counter = new CallCounter(); var service = new CredentialService(new AsyncLazy <IEnumerable <ICredentialProvider> >(() => counter.GetProviders()), nonInteractive: true, handlesDefaultCredentials: true); var uri1 = new Uri("http://uri1"); // Act var result1 = await service.GetCredentialsAsync( uri1, proxy : null, type : CredentialRequestType.Unauthorized, message : null, cancellationToken : CancellationToken.None); var result2 = await service.GetCredentialsAsync( uri1, proxy : null, type : CredentialRequestType.Unauthorized, message : null, cancellationToken : CancellationToken.None); Assert.Equal(1, counter.CallCount); }
public void GetProgressTest() { CallCounter counter = new CallCounter(); Deferred<System.String> d = new Deferred<System.String>(); d.Progress(p => { Assert.AreEqual(0.5f, p.ProgressValue); counter.Progress++; }); d.Notify(0.5f); Assert.AreEqual(1, counter.Progress); }
public void WhenFailTest() { CallCounter counter = new CallCounter(); Deferred.When( Deferred.Defer<None>(d => { counter.Coroutine++; d.Resolve(); }), Deferred.Defer<None>(d => { counter.Coroutine++; d.Resolve(); }), Deferred.Defer<None>(d => { counter.Coroutine++; d.Reject(); }), Deferred.Defer<None>(d => { counter.Coroutine++; d.Reject(); }), Deferred.Defer<None>(d => { counter.Coroutine++; d.Resolve(); }) ).Fail(p => { counter.Fail++; }); Assert.AreEqual(5, counter.Coroutine); Assert.AreEqual(1, counter.Fail); }
public uint CallCount(string method) => CallCounter.TryGetValue(method, out var v) ? v : 0;
public void NextCallBackTest() { CallCounter counter = new CallCounter(); Deferred<None> d = new Deferred<None>(); d.Done(p => counter.Done++ ).Next<None>(df => { Assert.AreEqual(1, counter.Done); counter.Next++; df.Reject(); }).Fail(p => counter.Fail++ ).Next<None>(df => counter.Next++ ); d.Resolve(); Assert.AreEqual(1, counter.Done); Assert.AreEqual(1, counter.Fail); Assert.AreEqual(1, counter.Next); }
public void GetResultTest() { CallCounter counter = new CallCounter(); Deferred<System.String> d = new Deferred<System.String>(); d.Done(p => { Assert.AreEqual("UniDeffered", p.GetResult<System.String>()); counter.Done++; }); d.Resolve("UniDeffered"); Assert.AreEqual(1, counter.Done); }
private bool IOExceptionAction(CallCounter counter) { counter.Count++; throw new IOException(); }
private async Task <bool> IOExceptionActionAsync(CallCounter counter) { counter.Count++; throw new IOException(); }
public ContentStoreTracer(string name) : base(name) { _callCounters.Add(_removeFromTrackerCallCounter = new CallCounter(_removeFromTrackerName)); }
public void GetErrorTest() { CallCounter counter = new CallCounter(); Deferred<System.String> d = new Deferred<System.String>(); d.Fail(p => { Assert.AreEqual("UniDeffered", p.Error); counter.Fail++; }); d.Reject("UniDeffered"); Assert.AreEqual(1, counter.Fail); }