internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("raise"); if (ExceptType != null) { ExceptType.AppendCodeString(res, ast, format); } if (this.IsAltForm(ast)) { res.Append(this.GetSecondWhiteSpace(ast)); res.Append("from"); Cause.AppendCodeString(res, ast, format); } else { if (Value != null) { res.Append(this.GetSecondWhiteSpace(ast)); res.Append(','); Value.AppendCodeString(res, ast, format); if (Traceback != null) { res.Append(this.GetThirdWhiteSpace(ast)); res.Append(','); Traceback.AppendCodeString(res, ast, format); } } } }
public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { ExceptType?.Walk(walker); Value?.Walk(walker); Traceback?.Walk(walker); Cause?.Walk(walker); } walker.PostWalk(this); }
public static void RunTheCode(string seq1File, string seq2File, int matchWeight, int misMatchWeight, int indlWeight) { ScoringParameterDto scoringParameter = new ScoringParameterDto(matchWeight, misMatchWeight, indlWeight); var seq1 = LoadProteinDatabase.GetProteins(seq1File); var seq2 = LoadProteinDatabase.GetProteins(seq2File); SequencesDto sequences = new SequencesDto(seq1[0].Seq, seq2[0].Seq); EvaluateDto evaluation = GridEvaluateFunction.Evaluate(scoringParameter, sequences); ResultsDto results = Traceback.Trace(evaluation, sequences); WriteAlignment.Write(results, scoringParameter); }
static unsafe void Serialize(ref SerializationContext context, ref Traceback input) { var buffer = new byte[8 + input.Frames.Count * 4]; fixed(uint *pFrames = &input.Frames.Array[input.Frames.Offset]) fixed(byte *pBuffer = buffer) { *(UInt32 *)(pBuffer + 0) = input.ID; *(int *)(pBuffer + 4) = input.Frames.Count; Squared.Data.Mangler.Internal.Native.memmove( pBuffer + 8, (byte *)pFrames, new UIntPtr((uint)(input.Frames.Count * 4)) ); } context.SetResult(buffer); }
public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { if (await walker.WalkAsync(this, cancellationToken)) { if (ExceptType != null) { await ExceptType.WalkAsync(walker, cancellationToken); } if (Value != null) { await Value.WalkAsync(walker, cancellationToken); } if (Traceback != null) { await Traceback.WalkAsync(walker, cancellationToken); } if (Cause != null) { await Cause.WalkAsync(walker, cancellationToken); } } await walker.PostWalkAsync(this, cancellationToken); }
static unsafe void Deserialize(ref DeserializationContext context, out Traceback output) { if (context.SourceLength < 8) { throw new InvalidDataException(); } var id = *(UInt32 *)(context.Source + 0); var count = *(int *)(context.Source + 4); if (context.SourceLength < 8 + (count * 4)) { throw new InvalidDataException(); } var array = ImmutableArrayPool <UInt32> .Allocate(count); fixed(uint *pFrames = array.Array) Squared.Data.Mangler.Internal.Native.memmove( (byte *)(&pFrames[array.Offset]), context.Source + 8, new UIntPtr((uint)(count * 4)) ); output = new Traceback(id, array); }
public HeapSnapshot(int index, DateTime when, string filename, string text) { MemoryStatistics memory = new MemoryStatistics(); bool scanningForStart = true, scanningForMemory = false; Heap scanningHeap = null; var regexes = new Regexes(); int groupModule = regexes.SnapshotModule.GroupNumberFromName("module"); int groupModuleOffset = regexes.SnapshotModule.GroupNumberFromName("offset"); int groupModuleSize = regexes.SnapshotModule.GroupNumberFromName("size"); int groupHeaderId = regexes.HeapHeader.GroupNumberFromName("id"); int groupAllocOffset = regexes.Allocation.GroupNumberFromName("offset"); int groupAllocSize = regexes.Allocation.GroupNumberFromName("size"); int groupAllocOverhead = regexes.Allocation.GroupNumberFromName("overhead"); int groupAllocId = regexes.Allocation.GroupNumberFromName("id"); Match m; // Instead of allocating a tiny new UInt32[] for every traceback we read in, // we store groups of tracebacks into fixed-size buffers so that the GC has // less work to do when performing collections. Tracebacks are read-only after // being constructed, and all the tracebacks from a snapshot have the same // lifetime, so this works out well. var frameBuffer = new UInt32[FrameBufferSize]; int frameBufferCount = 0; var lr = new LineReader(text); LineReader.Line line; while (lr.ReadLine(out line)) { if (scanningHeap != null) { if (line.StartsWith("*-") && line.Contains("End of data for heap")) { scanningHeap.Allocations.TrimExcess(); scanningHeap = null; } else if (regexes.Allocation.TryMatch(ref line, out m)) { var tracebackId = UInt32.Parse(m.Groups[groupAllocId].Value, NumberStyles.HexNumber); Traceback traceback; if (!Tracebacks.TryGetValue(tracebackId, out traceback)) { // If the frame buffer could fill up while we're building our traceback, // let's allocate a new one. if (frameBufferCount >= frameBuffer.Length - MaxTracebackLength) { frameBuffer = new UInt32[frameBuffer.Length]; frameBufferCount = 0; } int firstFrame = frameBufferCount; // This is only valid if every allocation is followed by an empty line while (lr.ReadLine(out line)) { if (line.StartsWith("\t")) { frameBuffer[frameBufferCount++] = UInt32.Parse( line.ToString(), NumberStyles.HexNumber | NumberStyles.AllowLeadingWhite ); } else { lr.Rewind(ref line); break; } } Tracebacks.Add(traceback = new Traceback( tracebackId, new ArraySegment <UInt32>(frameBuffer, firstFrame, frameBufferCount - firstFrame) )); } scanningHeap.Allocations.Add(new Allocation( UInt32.Parse(m.Groups[groupAllocOffset].Value, NumberStyles.HexNumber), UInt32.Parse(m.Groups[groupAllocSize].Value, NumberStyles.HexNumber), UInt32.Parse(m.Groups[groupAllocOverhead].Value, NumberStyles.HexNumber), traceback.ID )); } } else if (scanningForMemory) { if (regexes.HeapHeader.TryMatch(ref line, out m)) { scanningHeap = new Heap(index, UInt32.Parse(m.Groups[groupHeaderId].Value, NumberStyles.HexNumber)); Heaps.Add(scanningHeap); } else if (line.StartsWith("// Memory=")) { memory = new MemoryStatistics(line.ToString()); scanningForMemory = false; break; } else { continue; } } else if (scanningForStart) { if (line.Contains("Loaded modules")) { scanningForStart = false; } else if (line.Contains("Start of data for heap")) { break; } else { continue; } } else { if (!regexes.SnapshotModule.TryMatch(ref line, out m)) { if (line.Contains("Process modules enumerated")) { scanningForMemory = true; } else { continue; } } else { var modulePath = Path.GetFullPath(m.Groups[groupModule].Value).ToLowerInvariant(); Modules.Add(new Module( modulePath, UInt32.Parse(m.Groups[groupModuleOffset].Value, System.Globalization.NumberStyles.HexNumber), UInt32.Parse(m.Groups[groupModuleSize].Value, System.Globalization.NumberStyles.HexNumber) )); } } } foreach (var heap in Heaps) { heap.Allocations.Sort( (lhs, rhs) => lhs.Address.CompareTo(rhs.Address) ); heap.ComputeStatistics(); } Info = new HeapSnapshotInfo(index, when, filename, memory, this); }