public void TruncateAndFlush(Context ctx, long timestamp) { IMessageTree tree = ctx.Tree; Stack <ITransaction> stack = ctx.Stack; IMessage message = tree.Message; if (message is DefaultTransaction) { string id = tree.MessageId; string rootId = tree.RootMessageId; string childId = _mManager.NextMessageId(); DefaultTransaction source = (DefaultTransaction)message; DefaultTransaction target = new DefaultTransaction(source.Type, source.Name, _mManager); target.Timestamp = source.Timestamp; target.DurationInMicros = source.DurationInMicros; target.AddData(source.Data); target.Status = CatConstants.SUCCESS; MigrateMessage(stack, source, target, 1); int reducedByteSize = 0; foreach (ITransaction transaction in stack) { DefaultTransaction tran = (DefaultTransaction)transaction; tran.Timestamp = timestamp; reducedByteSize += transaction.EstimateByteSize(); } DefaultEvent next = new DefaultEvent("RemoteCall", "Next"); next.AddData(childId); next.Status = CatConstants.SUCCESS; target.AddChild(next); IMessageTree t = tree.Copy(); t.Message = target; ctx.Tree.MessageId = childId; ctx.Tree.ParentMessageId = id; ctx.Tree.RootMessageId = (rootId != null ? rootId : id); ctx._mLength = stack.Count; // Update estimated byte size of the truncated tree to be the total size of all on-stack transactions. ctx.Tree.EstimatedByteSize = reducedByteSize; ctx._mTotalDurationInMicros = ctx._mTotalDurationInMicros + target.DurationInMicros; _mManager.Flush(t); } }
/// <summary> /// 添加Event和Heartbeat /// </summary> /// <param name="manager"> </param> /// <param name="message"> </param> public void Add(IMessage message) { if ((_mStack.Count == 0)) { IMessageTree tree = _mTree.Copy(); if (String.IsNullOrWhiteSpace(tree.MessageId)) { tree.MessageId = _mManager.NextMessageId(); } tree.Message = message; tree.EstimatedByteSize = message.EstimateByteSize(); _mTree.EstimatedByteSize = 0; _mManager.Flush(tree); } else { ITransaction parent = _mStack.Peek(); AddTransactionChild(message, parent); } Tree.EstimatedByteSize += message.EstimateByteSize(); }