public void Dispose() { PProfBuildSessionState prevOwnerBuildState = Interlocked.Exchange(ref _ownerBuildState, null); if (prevOwnerBuildState != null) { if (!OwnerBuilder.TryFinishPProfBuildSessionInternal(this)) { throw new InvalidOperationException($"Cannot dispose this {nameof(PProfBuildSession)}." + $" Is this not the current session of the {nameof(OwnerBuilder)}?"); } } }
public void SetComment(string commentString) { if (_comment != null) { throw new InvalidOperationException($"The comment for this {nameof(PProfBuildSession)} was already set to {_comment}:" + $" impossible to change to {commentString}."); } _comment = OwnerBuilder.GetOrCreateStringInfo(commentString); if (_comment != null) { AddToStringTable(_comment); _profile.Comment.Add(_comment.OffsetInStringTable); } }
public void SetSampleLabels(IEnumerable <PProfSampleLabel> labels) { if (SamplesCount == 0) { throw new InvalidOperationException($"Cannot invoke {nameof(SetSampleLabels)}(..) because" + $" no samples were added to the current {nameof(PProfBuildSession)}."); } if (_lastSample.Label != null && _lastSample.Label.Count > 0) { throw new InvalidOperationException($"The labels for the {nameof(_lastSample)} of this {nameof(PProfBuildSession)} are already set." + $" The labels for a particular sample cannot be modified once set."); } foreach (PProfSampleLabel label in labels) { PProfInfo.Label labelInfo = OwnerBuilder.CreateNewLabelInfo(label); AddToStringTable(labelInfo.KeyInfo); labelInfo.Item.Key = labelInfo.KeyInfo.OffsetInStringTable; switch (labelInfo.ValueKind) { case PProfSampleLabel.Kind.Number: AddToStringTable(labelInfo.NumberUnitInfo); labelInfo.Item.NumUnit = labelInfo.NumberUnitInfo.OffsetInStringTable; break; case PProfSampleLabel.Kind.String: AddToStringTable(labelInfo.StringValueInfo); labelInfo.Item.Str = labelInfo.StringValueInfo.OffsetInStringTable; break; default: throw new InvalidOperationException($"Invalid {nameof(labelInfo.ValueKind)}: '{labelInfo.ValueKind}'."); } _lastSample.Label.Add(labelInfo.Item); } }
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); }