public void AttributeSamplesToIP(ulong ip, long numSamples) { MemoryRegionInfo region = _memMap.GetInfo(ip); if (region == null) { SamplesOutsideManagedCode += numSamples; return; } if (region.NativeToILMap == null) { SamplesInManagedCodeWithoutAnyMappings += numSamples; return; } if (!region.NativeToILMap.TryLookup(checked ((uint)(ip - region.StartAddress)), out IPMapping mapping)) { SamplesInManagedCodeOutsideMappings += numSamples; return; } if (mapping.InlineeMethod == null) { SamplesInUnknownInlinees += numSamples; return; } PerMethodInfo pmi = GetOrCreateInfo(mapping.InlineeMethod); if (pmi == null) { SamplesInManagedCodeWithoutIL += numSamples; return; } if (pmi.Profile.TryAttributeSamples(mapping.ILOffset, 1)) { TotalAttributedSamples += numSamples; } else { SamplesInManagedCodeOutsideFlowGraph += numSamples; } }
private PerMethodInfo GetOrCreateInfo(MethodDesc md) { if (!_methodInf.TryGetValue(md, out PerMethodInfo pmi)) { MethodIL il = md switch { EcmaMethod em => EcmaMethodIL.Create(em), _ => new InstantiatedMethodIL(md, EcmaMethodIL.Create((EcmaMethod)md.GetTypicalMethodDefinition())), }; if (il == null) { return(null); } _methodInf.Add(md, pmi = new PerMethodInfo()); pmi.IL = il; pmi.FlowGraph = FlowGraph.Create(il); pmi.Profile = new SampleProfile(pmi.IL, pmi.FlowGraph); } return(pmi); }