コード例 #1
0
        private IEnumerable <FakeDump> CreateFakeDumps(int n)
        {
            var rand = new Random();

            for (int i = 0; i < n; i++)
            {
                var res = new SDResult {
                    ThreadInformation = new Dictionary <uint, SDThread>()
                };
                res.ThreadInformation[1] = new SDThread(1)
                {
                    StackTrace = new SDCombinedStackTrace(new List <SDCombinedStackFrame>()
                    {
                        new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyErrorFrameA", 123, 456, 789, 1011, 1213, null),
                        new SDCombinedStackFrame(StackFrameType.Native, "app.dll", "MyAppFrameA", 123, 456, 789, 1011, 1213, null),
                        new SDCombinedStackFrame(StackFrameType.Native, "app.dll", "MyAppFrameB", 123, 456, 789, 1011, 1213, null),
                        new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameA", 123, 456, 789, 1011, 1213, null),
                        new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameB", 123, 456, 789, 1011, 1213, null),
                        new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameC", 123, 456, 789, 1011, 1213, null),
                        new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MySystemFrameA", 123, 456, 789, 1011, 1213, null),
                        new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MySystemFrameA_" + rand.NextDouble(), 123, 456, 789, 1011, 1213, null),                         // add some slight difference
                    })
                };
                AddTagToFrameAndThread(res, SDTag.NativeExceptionTag);

                yield return(new FakeDump {
                    MetaInfo = new DumpMetainfo {
                        BundleId = $"bundle{i}", DumpId = $"dump{i}", Status = DumpStatus.Finished
                    },
                    FileInfo = null,
                    Result = res,
                    MiniInfo = CrashSimilarity.SDResultToMiniInfo(res)
                });
            }
        }
コード例 #2
0
        public void TestStacktraceSimilarityNullValues()
        {
            var res1 = new SDResult {
                ThreadInformation = new Dictionary <uint, SDThread>()
            };

            res1.ThreadInformation[1] = new SDThread(1)
            {
                StackTrace = new SDCombinedStackTrace(new List <SDCombinedStackFrame>()
                {
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyErrorFrameA", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, null, null, 123, 456, 789, 1011, 1213, null),
                })
            };
            AddTagToFrameAndThread(res1, SDTag.NativeExceptionTag);

            var res2 = new SDResult {
                ThreadInformation = new Dictionary <uint, SDThread>()
            };

            res2.ThreadInformation[1] = new SDThread(1)
            {
                StackTrace = new SDCombinedStackTrace(new List <SDCombinedStackFrame>()
                {
                    new SDCombinedStackFrame(StackFrameType.Native, null, null, 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "app.dll", "MyAppFrameZ", 123, 456, 789, 1011, 1213, null),
                })
            };
            AddTagToFrameAndThread(res2, SDTag.NativeExceptionTag);

            var similarity = CrashSimilarity.Calculate(CrashSimilarity.SDResultToMiniInfo(res1), CrashSimilarity.SDResultToMiniInfo(res2));

            Assert.NotNull(similarity);
        }
コード例 #3
0
        public async Task <DumpMiniInfo> GetOrCreateMiniInfo(DumpIdentifier id)
        {
            if (dumpRepo.MiniInfoExists(id))
            {
                try {
                    var loadedMiniInfo = await dumpRepo.GetMiniInfo(id);

                    if (loadedMiniInfo.DumpSimilarityInfoVersion == CrashSimilarity.MiniInfoVersion)
                    {
                        return(loadedMiniInfo);
                    }
                } catch {
                    Console.WriteLine($"could not load miniinfo for {id}. will re-create it.");
                }
            }

            // no mini-info exists yet, or version is outdated. re-create.
            var result = await dumpRepo.GetResult(id);

            var miniInfo =
                (result == null)
                                ? new DumpMiniInfo() // just store an empty mini-info if result is null
                                : CrashSimilarity.SDResultToMiniInfo(result);
            await dumpRepo.StoreMiniInfo(id, miniInfo);

            return(miniInfo);
        }
コード例 #4
0
ファイル: SimilarityService.cs プロジェクト: tanium/superdump
        public async Task CalculateSimilarity(DumpMetainfo dumpA, bool force, DateTime timeFrom)
        {
            try {
                var swTotal = new Stopwatch();
                swTotal.Start();
                var resultA = await dumpRepo.GetResult(dumpA.BundleId, dumpA.DumpId);

                if (resultA == null)
                {
                    return;                                  // no results found. do nothing.
                }
                var allDumps = dumpRepo.GetAll().Where(x => x.Created >= timeFrom).OrderBy(x => x.Created);
                Console.WriteLine($"starting CalculateSimilarity for {allDumps.Count()} dumps; {dumpA} (TID:{Thread.CurrentThread.ManagedThreadId})");

                int i  = allDumps.Count();
                var sw = new Stopwatch();
                foreach (var dumpB in allDumps)
                {
                    i--;
                    sw.Start();
                    if (!force)
                    {
                        if (await relationShipRepo.GetRelationShip(dumpA.Id, dumpB.Id) != 0)
                        {
                            continue;                                                                                          // relationship already exists. skip!
                        }
                    }

                    if (!PreSelectOnMetadata(dumpA, dumpB))
                    {
                        continue;
                    }
                    var resultB = await dumpRepo.GetResult(dumpB.BundleId, dumpB.DumpId);

                    if (resultB == null)
                    {
                        continue;
                    }
                    if (!PreSelectOnResults(resultA, resultB))
                    {
                        continue;
                    }

                    CrashSimilarity crashSimilarity = CrashSimilarity.Calculate(resultA, resultB);

                    // only store value if above a certain threshold to avoid unnecessary disk writes
                    if (crashSimilarity.OverallSimilarity > 0.2)
                    {
                        await relationShipRepo.UpdateSimilarity(dumpA.Id, dumpB.Id, crashSimilarity);
                    }
                    sw.Stop();
                    //Console.WriteLine($"CalculateSimilarity.Finished for {dumpA}/{dumpB} ({i} to go...); (elapsed: {sw.Elapsed}) (TID:{Thread.CurrentThread.ManagedThreadId})");
                    sw.Reset();
                }
                swTotal.Stop();
                Console.WriteLine($"CalculateSimilarity.Finished for all {allDumps.Count()} dumps (total elapsed: {swTotal.Elapsed}); {dumpA} (TID:{Thread.CurrentThread.ManagedThreadId})");
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
コード例 #5
0
        private long MemUsageHashed()
        {
            var before = GC.GetTotalMemory(true);
            var x      = CrashSimilarity.SDResultToMiniInfo(sdresult);
            var after  = GC.GetTotalMemory(true);

            return(after - before);
        }
コード例 #6
0
        public void TestStacktraceSimilarity()
        {
            var res1 = new SDResult {
                ThreadInformation = new Dictionary <uint, SDThread>()
            };

            res1.ThreadInformation[1] = new SDThread(1)
            {
                StackTrace = new SDCombinedStackTrace(new List <SDCombinedStackFrame>()
                {
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyErrorFrameA", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "app.dll", "MyAppFrameA", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "app.dll", "MyAppFrameB", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameA", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameB", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameC", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MySystemFrameA", 123, 456, 789, 1011, 1213, null),
                })
            };
            AddTagToFrameAndThread(res1, SDTag.NativeExceptionTag);

            var res2 = new SDResult {
                ThreadInformation = new Dictionary <uint, SDThread>()
            };

            res2.ThreadInformation[1] = new SDThread(1)
            {
                StackTrace = new SDCombinedStackTrace(new List <SDCombinedStackFrame>()
                {
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyErrorFrameA", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "app.dll", "MyAppFrameZ", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "app.dll", "MyAppFrameA", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "app.dll", "MyAppFrameB", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameA", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameB", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameC", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MySystemFrameA", 123, 456, 789, 1011, 1213, null),
                })
            };
            AddTagToFrameAndThread(res2, SDTag.NativeExceptionTag);

            var similarity = CrashSimilarity.Calculate(CrashSimilarity.SDResultToMiniInfo(res1), CrashSimilarity.SDResultToMiniInfo(res2));

            Assert.Equal(0.875, similarity.StackTraceSimilarity);
            Assert.Equal(1.0, similarity.ModulesSimilarity);
            Assert.Null(similarity.LastEventSimilarity);
            Assert.Null(similarity.ExceptionSimilarity);
            Assert.Equal(0.9375, similarity.OverallSimilarity);
        }
コード例 #7
0
        public async Task <IActionResult> CompareDumps(string bundleId1, string dumpId1, string bundleId2, string dumpId2)
        {
            try {
                var res1 = await dumpRepository.GetResult(bundleId1, dumpId1);

                var res2 = await dumpRepository.GetResult(bundleId2, dumpId2);

                if (res1 == null || res2 == null)
                {
                    return(View(new SimilarityModel($"could not compare dumps.")));
                }
                var similarity = CrashSimilarity.Calculate(res1, res2);
                return(View(new SimilarityModel(new DumpIdentifier(bundleId1, dumpId2), new DumpIdentifier(bundleId2, dumpId2), similarity)));
            } catch (Exception e) {
                return(View(new SimilarityModel($"exception while comparing: {e.ToString()}")));
            }
        }
コード例 #8
0
        public async Task <IActionResult> CompareDumps(string bundleId1, string dumpId1, string bundleId2, string dumpId2)
        {
            try {
                var id1 = DumpIdentifier.Create(bundleId1, dumpId1);
                var id2 = DumpIdentifier.Create(bundleId2, dumpId2);

                var res1 = await similarityService.GetOrCreateMiniInfo(id1);

                var res2 = await similarityService.GetOrCreateMiniInfo(id2);

                logger.LogSimilarityEvent("CompareDumps", HttpContext, bundleId1, dumpId1, bundleId2, dumpId2);
                var similarity = CrashSimilarity.Calculate(res1, res2);
                return(View(new SimilarityModel(DumpIdentifier.Create(bundleId1, dumpId2), DumpIdentifier.Create(bundleId2, dumpId2), similarity)));
            } catch (Exception e) {
                return(View(new SimilarityModel($"exception while comparing: {e.ToString()}")));
            }
        }
コード例 #9
0
        private IEnumerable <FakeDump> CreateFakeDumps()
        {
            int n = 10;

            for (int i = 0; i < n; i++)
            {
                var res = new SDResult {
                    ThreadInformation = new Dictionary <uint, SDThread>()
                };
                yield return(new FakeDump {
                    MetaInfo = new DumpMetainfo {
                        BundleId = $"bundle{i}", DumpId = $"dump{i}", Status = DumpStatus.Finished
                    },
                    FileInfo = null,
                    Result = res,
                    MiniInfo = CrashSimilarity.SDResultToMiniInfo(res)
                });
            }
        }
コード例 #10
0
        private FakeDump CreateFakeDump()
        {
            var res = new SDResult {
                ThreadInformation = new Dictionary <uint, SDThread>()
            };

            res.ThreadInformation[1] = new SDThread(1)
            {
                StackTrace = new SDCombinedStackTrace(new List <SDCombinedStackFrame>()
                {
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyErrorFrameA", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "app.dll", "MyAppFrameA", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "app.dll", "MyAppFrameB", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameA", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameB", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MyFrameworkFrameC", 123, 456, 789, 1011, 1213, null),
                    new SDCombinedStackFrame(StackFrameType.Native, "ntdll.dll", "MySystemFrameA", 123, 456, 789, 1011, 1213, null)
                })
            };
            AddTagToFrameAndThread(res, SDTag.NativeExceptionTag);

            res.SystemContext = new SDSystemContext {
                ProcessArchitecture = "X64",
                Modules             = new List <SDModule> {
                    new SDModule {
                        FileName = "jvm.dll"
                    }
                }
            };

            return(new FakeDump {
                MetaInfo = new DumpMetainfo {
                    BundleId = $"bundle1", DumpId = $"dump1", Status = DumpStatus.Finished
                },
                FileInfo = null,
                Result = res,
                MiniInfo = CrashSimilarity.SDResultToMiniInfo(res)
            });
        }
コード例 #11
0
 public SimilarityModel(DumpIdentifier dumpA, DumpIdentifier dumpB, CrashSimilarity crashSimilarity)
 {
     this.DumpA           = dumpA;
     this.DumpB           = dumpB;
     this.CrashSimilarity = crashSimilarity;
 }
コード例 #12
0
        public async Task CalculateSimilarityAsync(DumpMetainfo dumpA, bool force, DateTime timeFrom)
        {
            try {
                var swTotal = new Stopwatch();
                swTotal.Start();
                if (!dumpRepo.IsPopulated)
                {
                    Console.WriteLine($"CalculateSimilarity for {dumpA.Id} is blocked because dumpRepo is not yet fully populated...");
                    await Utility.BlockUntil(() => dumpRepo.IsPopulated);

                    Console.WriteLine($"...continuing CalculateSimilarity for {dumpA.Id}.");
                }

                var resultA = await GetOrCreateMiniInfo(dumpA.Id);

                var allDumps = dumpRepo.GetAll().Where(x => x.Created >= timeFrom).OrderBy(x => x.Created);
                Console.WriteLine($"starting CalculateSimilarity for {allDumps.Count()} dumps; {dumpA} (TID:{Thread.CurrentThread.ManagedThreadId})");

                foreach (var dumpB in allDumps)
                {
                    if (!force)
                    {
                        var existingSimilarity = await relationShipRepo.GetRelationShip(dumpA.Id, dumpB.Id);

                        if (existingSimilarity != 0)
                        {
                            // relationship already exists. skip!
                            // but make sure the relationship is stored bi-directional
                            await relationShipRepo.UpdateSimilarity(dumpA.Id, dumpB.Id, existingSimilarity);

                            continue;
                        }
                    }

                    if (!PreSelectOnMetadata(dumpA, dumpB))
                    {
                        continue;
                    }
                    var resultB = await GetOrCreateMiniInfo(dumpB.Id);

                    if (!PreSelectOnResults(resultA, resultB))
                    {
                        continue;
                    }

                    CrashSimilarity crashSimilarity = CrashSimilarity.Calculate(resultA, resultB);

                    // only store value if above a certain threshold to avoid unnecessary disk writes
                    if (crashSimilarity.OverallSimilarity > 0.6)
                    {
                        await relationShipRepo.UpdateSimilarity(dumpA.Id, dumpB.Id, crashSimilarity.OverallSimilarity);
                    }
                    //Console.WriteLine($"CalculateSimilarity.Finished for {dumpA}/{dumpB} ({i} to go...); (elapsed: {sw.Elapsed}) (TID:{Thread.CurrentThread.ManagedThreadId})");
                }

                await relationShipRepo.FlushDirtyRelationships();

                swTotal.Stop();
                Console.WriteLine($"CalculateSimilarity.Finished for all {allDumps.Count()} dumps (total elapsed: {swTotal.Elapsed}); {dumpA} (TID:{Thread.CurrentThread.ManagedThreadId})");
            } catch (Exception e) {
                Console.Error.WriteLine($"CalculateSimilarity failed: {e}");
            }
        }
コード例 #13
0
 public void CalculateSimilaritySimilardumps()
 {
     CrashSimilarity.Calculate(dump1, dump2);
 }
コード例 #14
0
 public void CalculateSimilarityDifferentdumps()
 {
     CrashSimilarity.Calculate(dump1, dump3);
 }
コード例 #15
0
        private async Task UpdateRelationship(DumpIdentifier dumpA, DumpIdentifier dumpB, CrashSimilarity similarity, IDictionary <DumpIdentifier, double> relationShip)
        {
            relationShip[dumpB] = similarity.OverallSimilarity;

            // update storage
            await relationshipStorage.StoreRelationships(dumpA, relationShip);
        }
コード例 #16
0
        private async Task UpdateSimilarity0(DumpIdentifier dumpA, DumpIdentifier dumpB, CrashSimilarity similarity)
        {
            if (relationShips.TryGetValue(dumpA, out IDictionary <DumpIdentifier, double> relationShip))
            {
                await UpdateRelationship(dumpA, dumpB, similarity, relationShip);
            }
            else
            {
                var dict = new Dictionary <DumpIdentifier, double>();
                await UpdateRelationship(dumpA, dumpB, similarity, dict);

                relationShips[dumpA] = dict;
            }
        }
コード例 #17
0
        public async Task UpdateSimilarity(DumpIdentifier dumpA, DumpIdentifier dumpB, CrashSimilarity similarity)
        {
            await semaphoreSlim.WaitAsync().ConfigureAwait(false);

            try {
                await UpdateSimilarity0(dumpA, dumpB, similarity);
                await UpdateSimilarity0(dumpB, dumpA, similarity);
            } finally {
                semaphoreSlim.Release();
            }
        }
コード例 #18
0
 public void CalculateSimilaritySamedump()
 {
     CrashSimilarity.Calculate(dump1, dump1);
 }