public Location(PProfProto.Location item, PProfInfo.Mapping mappingInfo, PProfInfo.Function functionInfo) : this(item, mappingInfo, new PProfInfo.Function[1] { functionInfo }) { Validate.NotNull(functionInfo, nameof(functionInfo)); }
public Location(PProfProto.Location item, PProfInfo.Mapping mappingInfo, IReadOnlyList <PProfInfo.Function> functionInfos) { Validate.NotNull(item, nameof(item)); Validate.NotNull(mappingInfo, nameof(mappingInfo)); Validate.NotNull(functionInfos, nameof(functionInfos)); if (functionInfos.Count < 1) { throw new ArgumentException($"{nameof(functionInfos)} must contain at least one element."); } if (item.Line.Count != functionInfos.Count) { throw new ArgumentException($"{nameof(item)}.{nameof(item.Line)}.{nameof(item.Line.Count)} (={item.Line.Count})" + $" must have the same value as {nameof(functionInfos)}.{nameof(functionInfos.Count)} (={functionInfos.Count})."); } for (int i = 0; i < functionInfos.Count; i++) { if (functionInfos[i] == null) { throw new ArgumentException($"{nameof(functionInfos)} must not contain null elements, but element at index {i} is null."); } } this.Item = item; this.IsIncludedInSession = false; this.MappingInfo = mappingInfo; this.FunctionInfos = functionInfos; }
public PProfInfo.Mapping GetOrCreateMappingInfo(string moniker, string filename, string buildId) { Validate.NotNull(moniker, nameof(moniker)); Validate.NotNull(filename, nameof(filename)); // buildId may be null if (!_mappings.TryGetValue(moniker, out PProfInfo.Mapping mappingInfo)) { mappingInfo = new PProfInfo.Mapping( new PProfProto.Mapping() { Id = NextIdForMapping(), MemoryStart = ProtoConstants.NumericValue.UnsetUInt64, MemoryLimit = ProtoConstants.NumericValue.UnsetUInt64, FileOffset = ProtoConstants.NumericValue.UnsetUInt64, Filename = ProtoConstants.StringTableIndex.Unresolved, BuildId = string.IsNullOrEmpty(buildId) ? ProtoConstants.StringTableIndex.Unset : ProtoConstants.StringTableIndex.Unresolved, HasFunctions = true, HasFilenames = true, HasLineNumbers = false, HasInlineFrames = false }, GetOrCreateStringInfo(filename), string.IsNullOrEmpty(buildId) ? null : GetOrCreateStringInfo(buildId)); _mappings.Add(moniker, mappingInfo); } return(mappingInfo); }
public PProfInfo.Location GetOrCreateLocationInfo( LocationDescriptor locationDescriptor, PProfInfo.Mapping mappingInfo, PProfInfo.Function functionInfo) { return(GetOrCreateLocationInfo(locationDescriptor, mappingInfo, new PProfInfo.Function[1] { functionInfo })); }
private void AddToMappingsList(PProfInfo.Mapping mappingInfo) { if (mappingInfo != null && !mappingInfo.IsIncludedInSession) { PProfBuildSessionState buildState = ValidOwnerBuildState; mappingInfo.IsIncludedInSession = true; buildState.Mappings.Add(mappingInfo); _profile.Mapping.Add(mappingInfo.Item); } }
internal PProfInfo.Mapping GetOrCreateMainEntrypointMappingInfo() { // This method must only be called by PProfBuildSession when it's safe! // (I.e. at the very begining of the session, before anything has been added to the session lists.) PProfInfo.Mapping mainEntrypointMappingInfo = GetMainEntrypointMappingInfo(); if (mainEntrypointMappingInfo == null) { mainEntrypointMappingInfo = SetMainEntrypointMappingInfo(entrypointBinaryContainerName: null, entrypointBinaryContainerVersion: null); } return(mainEntrypointMappingInfo); }
public bool TrySetMainEntrypointMappingInfo( string entrypointBinaryContainerName, string entrypointBinaryContainerVersion, out PProfInfo.Mapping mainEntrypointMappingInfo) { if (_buildState.Session != null) { mainEntrypointMappingInfo = null; return(false); } mainEntrypointMappingInfo = SetMainEntrypointMappingInfo(entrypointBinaryContainerName, entrypointBinaryContainerVersion); return(true); }
private PProfInfo.Mapping SetMainEntrypointMappingInfo(string entrypointBinaryContainerName, string entrypointBinaryContainerVersion) { EnsureNoSessionState(nameof(SetMainEntrypointMappingInfo)); string newMainEntrypointMappingMoniker = BuildBinaryContainerMoniker(ref entrypointBinaryContainerName, ref entrypointBinaryContainerVersion); PProfInfo.Mapping newMainEntrypointMappingInfo = _cache .GetOrCreateMappingInfo(newMainEntrypointMappingMoniker, entrypointBinaryContainerName, entrypointBinaryContainerVersion); // It is tempting to remove the mapping keyed by _mainEntrypointMappingMoniker from _cache.Mappings, // but we cannot because that mapping may be used elsewhere. _mainEntrypointMappingMoniker = newMainEntrypointMappingMoniker; return(newMainEntrypointMappingInfo); }
internal bool TryGetOrResolveCreatePProfLocationInfo( LocationDescriptor locationDescriptor, PProfBuildSession pprofBuildSession, TryResolveLocationSymbolsDelegate tryResolveLocationSymbolsDelegate, out PProfInfo.Location locationInfo) { if (_cache.TryGetLocationInfo(locationDescriptor, out locationInfo)) { return(true); } if ( tryResolveLocationSymbolsDelegate == null || !tryResolveLocationSymbolsDelegate( pprofBuildSession, locationDescriptor, out string functionName, out string classTypeName, out string binaryContainerName, out string binaryContainerVersion)) { locationInfo = null; return(false); } BuildMonikers( ref functionName, ref classTypeName, ref binaryContainerName, ref binaryContainerVersion, out string functionMoniker, out string binaryContainerMoniker); // system name is not used so pass null (i.e. empty string) PProfInfo.Function functionInfo = _cache.GetOrCreateFunctionInfo(functionMoniker, functionMoniker, null); PProfInfo.Mapping mappingInfo = _cache.GetOrCreateMappingInfo(binaryContainerMoniker, binaryContainerName, binaryContainerVersion); locationInfo = _cache.GetOrCreateLocationInfo(locationDescriptor, mappingInfo, functionInfo); return(true); }
public PProfInfo.Location GetOrCreateLocationInfo( LocationDescriptor locationDescriptor, PProfInfo.Mapping mappingInfo, IReadOnlyList <PProfInfo.Function> functionInfos) { // locationDescriptor is value type so can never be null Validate.NotNull(mappingInfo, nameof(mappingInfo)); Validate.NotNull(functionInfos, nameof(functionInfos)); if (!_locations.TryGetValue(locationDescriptor, out PProfInfo.Location locationInfo)) { var locationItem = new PProfProto.Location() { Id = NextIdForLocation(), MappingId = mappingInfo.Item.Id, Address = ProtoConstants.NumericValue.UnsetUInt64, IsFolded = false }; for (int i = 0; i < functionInfos.Count; i++) { if (functionInfos[i] != null) { locationItem.Line.Add(new PProfProto.Line() { FunctionId = functionInfos[i].Item.Id, Line_ = ProtoConstants.NumericValue.UnsetInt64 }); } } locationInfo = new PProfInfo.Location(locationItem, mappingInfo, functionInfos); _locations.Add(locationDescriptor, locationInfo); } return(locationInfo); }
internal void InitProfile() { PProfInfo.String emptyStringInfo = OwnerBuilder.EmptyStringInfo; PProfInfo.Mapping entrypointMappingInfo = OwnerBuilder.GetMainEntrypointMappingInfo(); // Empty string: AddToStringTable(emptyStringInfo); // Main entry-point mapping: if (entrypointMappingInfo != null) { AddToStringTable(entrypointMappingInfo.FilenameInfo); entrypointMappingInfo.Item.Filename = entrypointMappingInfo.FilenameInfo.OffsetInStringTable; if (entrypointMappingInfo.BuildIdInfo != null) { AddToStringTable(entrypointMappingInfo.BuildIdInfo); entrypointMappingInfo.Item.BuildId = entrypointMappingInfo.BuildIdInfo.OffsetInStringTable; } AddToMappingsList(entrypointMappingInfo); } // Sample measurement values types/units: for (int i = 0; i < OwnerBuilder.SampleValueTypes.Count; i++) { PProfInfo.ValueType sampleValueTypeInfo = OwnerBuilder.SampleValueTypeInfos[i]; AddToStringTable(sampleValueTypeInfo.TypeInfo); AddToStringTable(sampleValueTypeInfo.UnitInfo); _profile.SampleType.Add(new PProfProto.ValueType() { Type = sampleValueTypeInfo.TypeInfo.OffsetInStringTable, Unit = sampleValueTypeInfo.UnitInfo.OffsetInStringTable }); } // Drop frames RegEx: if (!string.IsNullOrWhiteSpace(OwnerBuilder.DropFramesRegExpInfo?.Item)) { AddToStringTable(OwnerBuilder.DropFramesRegExpInfo); _profile.DropFrames = OwnerBuilder.DropFramesRegExpInfo.OffsetInStringTable; } // Keep frames RegEx: if (!string.IsNullOrWhiteSpace(OwnerBuilder.KeepFramesRegExpInfo?.Item)) { AddToStringTable(OwnerBuilder.KeepFramesRegExpInfo); _profile.DropFrames = OwnerBuilder.KeepFramesRegExpInfo.OffsetInStringTable; } // Period measurement type/unit: if (OwnerBuilder.PeriodTypeInfo.HasNonDefaultValues) { AddToStringTable(OwnerBuilder.PeriodTypeInfo.TypeInfo); AddToStringTable(OwnerBuilder.PeriodTypeInfo.UnitInfo); _profile.PeriodType = new PProfProto.ValueType() { Type = OwnerBuilder.PeriodTypeInfo.TypeInfo.OffsetInStringTable, Unit = OwnerBuilder.PeriodTypeInfo.UnitInfo.OffsetInStringTable }; _profile.Period = _period; } // Default sample type (not sure what DefaultSampleType is for; not supported for now): _profile.DefaultSampleType = ProtoConstants.NumericValue.UnsetInt64; }
public bool TryAddLocationToLastSample( LocationDescriptor locationDescriptor, PProfBuilder.TryResolveLocationSymbolsDelegate tryResolveLocationSymbolsDelegate) { if (!OwnerBuilder.TryGetOrResolveCreatePProfLocationInfo( locationDescriptor, this, tryResolveLocationSymbolsDelegate, out PProfInfo.Location locationInfo)) { return(false); } // Functions: for (int i = 0; i < locationInfo.FunctionInfos.Count; i++) { PProfInfo.Function functionInfo = locationInfo.FunctionInfos[0]; if (functionInfo.NameInfo != null) { AddToStringTable(functionInfo.NameInfo); functionInfo.Item.Name = functionInfo.NameInfo.OffsetInStringTable; } if (functionInfo.SystemNameInfo != null) { AddToStringTable(functionInfo.SystemNameInfo); functionInfo.Item.SystemName = functionInfo.SystemNameInfo.OffsetInStringTable; } if (functionInfo.FilenameInfo != null) { AddToStringTable(functionInfo.FilenameInfo); functionInfo.Item.Filename = functionInfo.FilenameInfo.OffsetInStringTable; } AddToFunctionsList(functionInfo); } // Mapping: PProfInfo.Mapping mappingInfo = locationInfo.MappingInfo; if (mappingInfo.FilenameInfo != null) { AddToStringTable(mappingInfo.FilenameInfo); mappingInfo.Item.Filename = mappingInfo.FilenameInfo.OffsetInStringTable; } if (mappingInfo.BuildIdInfo != null) { AddToStringTable(mappingInfo.BuildIdInfo); mappingInfo.Item.BuildId = mappingInfo.BuildIdInfo.OffsetInStringTable; } AddToMappingsList(mappingInfo); // Location: AddToLocationsList(locationInfo); // Sample: _lastSample.LocationId.Add(locationInfo.Item.Id); return(true); }
public bool TryGetMappingInfo(string moniker, out PProfInfo.Mapping mappingInfo) { mappingInfo = null; return((moniker != null) && _mappings.TryGetValue(moniker, out mappingInfo)); }
public void ResetSession() { // Clear Locations: { var list = _locations; int itemCount = list.Count; for (int i = 0; i < itemCount; i++) { PProfInfo.Location pprofInfo = list[i]; pprofInfo.IsIncludedInSession = false; } list.Clear(); } // Clear Mappings: { var list = _mappings; int itemCount = list.Count; for (int i = 0; i < itemCount; i++) { PProfInfo.Mapping pprofInfo = list[i]; pprofInfo.IsIncludedInSession = false; pprofInfo.Item.Filename = ProtoConstants.StringTableIndex.GetUnresolvedIfSet(pprofInfo.Item.Filename); pprofInfo.Item.BuildId = ProtoConstants.StringTableIndex.GetUnresolvedIfSet(pprofInfo.Item.BuildId); } list.Clear(); } // Clear Functions: { var list = _functions; int itemCount = list.Count; for (int i = 0; i < itemCount; i++) { PProfInfo.Function pprofInfo = list[i]; pprofInfo.IsIncludedInSession = false; pprofInfo.Item.Name = ProtoConstants.StringTableIndex.GetUnresolvedIfSet(pprofInfo.Item.Name); pprofInfo.Item.SystemName = ProtoConstants.StringTableIndex.GetUnresolvedIfSet(pprofInfo.Item.SystemName); pprofInfo.Item.Filename = ProtoConstants.StringTableIndex.GetUnresolvedIfSet(pprofInfo.Item.Filename); } list.Clear(); } // Clear the String Table: { var list = _stringTable; int itemCount = list.Count; for (int i = 0; i < itemCount; i++) { list[i].ResetOffsetInStringTable(); } list.Clear(); } // Finally, clear the Session: _currentSession = null; }