private void AdjustForTruncatedTransaction(ITransaction root)
            {
                DefaultEvent next = new DefaultEvent("TruncatedTransaction", "TotalDuration");
                long         actualDurationInMicros = _mTotalDurationInMicros + root.DurationInMicros;

                next.AddData(Convert.ToString(actualDurationInMicros));
                next.Status = CatConstants.SUCCESS;
                root.AddChild(next);

                _mTotalDurationInMicros = 0;
            }
            public void LinkAsRunAway(DefaultForkedTransaction transaction)
            {
                DefaultEvent evt = new DefaultEvent("RemoteCall", "RunAway");

                evt.AddData(transaction.ForkedMessageId, transaction.Type + ":" + transaction.Name);
                evt.Timestamp = transaction.Timestamp;
                evt.Status    = CatConstants.SUCCESS;
                evt.SetCompleted(true);
                transaction.Standalone = true;

                _mManager.Add(evt);
            }
Beispiel #3
0
            internal void LinkAsRunAway(IForkedTransaction transaction)
            {
                var @event = new DefaultEvent(PureCatConstants.TYPE_REMOTE_CALL, "RunAway");

                @event.AddData(transaction.ForkedMessageId, $"{transaction.Type}:{transaction.Name}");
                @event.Timestamp = transaction.Timestamp;
                @event.Status    = PureCatConstants.SUCCESS;
                @event.Complete();

                transaction.Standalone = true;

                _manager.Add(@event);
            }
            internal void LinkAsRunAway(DefaultMessageManager manager, IForkedTransaction transaction)
            {
                IEvent @event = new DefaultEvent(PureCatConstants.TYPE_REMOTE_CALL, "RunAway");

                @event.AddData(transaction.ForkedMessageId, string.Format("{0}:{1}", transaction.Type, transaction.Name));
                @event.Timestamp = transaction.Timestamp;
                @event.Status    = PureCatConstants.SUCCESS;
                @event.Complete();

                transaction.Standalone = true;

                manager.Add(@event);
            }
            public void TruncateAndFlush(Context ctx, long timestamp)
            {
                IMessageTree tree = ctx.Tree;
                ThreadSafeStack <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);
                }
            }
            private void TruncateAndFlush(DefaultMessageManager manager, long timestamp)
            {
                IMessageTree         tree    = _mTree;
                Stack <ITransaction> stack   = _mStack;
                IMessage             message = tree.Message;

                if (message is DefaultTransaction)
                {
                    if (tree.MessageId == null)
                    {
                        tree.MessageId = manager.NextMessageId();
                    }

                    string rootId  = tree.RootMessageId;
                    string childId = manager.NextMessageId();

                    DefaultTransaction source = message as DefaultTransaction;
                    DefaultTransaction target = new DefaultTransaction(source.Type, source.Name, manager);
                    target.Timestamp        = source.Timestamp;
                    target.DurationInMicros = source.DurationInMicros;
                    target.AddData(source.Data);
                    target.Status = PureCatConstants.SUCCESS;

                    MigrateMessage(manager, stack, source, target, 1);

                    var list = stack.ToList();

                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        DefaultTransaction tran = list[i] as DefaultTransaction;
                        tran.Timestamp        = timestamp;
                        tran.DurationInMicros = -1;
                    }

                    IEvent next = new DefaultEvent(PureCatConstants.TYPE_REMOTE_CALL, "Next");
                    next.AddData(childId);
                    next.Status = PureCatConstants.SUCCESS;
                    target.AddChild(next);

                    IMessageTree t = tree.Copy();

                    t.Message = target;

                    _mTree.MessageId       = childId;
                    _mTree.ParentMessageId = tree.MessageId;
                    _mTree.RootMessageId   = rootId ?? tree.MessageId;

                    manager.Flush(t);
                }
            }
Beispiel #7
0
            private void TruncateAndFlush(long timestamp)
            {
                var tree    = _mTree;
                var stack   = _mStack;
                var message = tree.Message;

                if (message is DefaultTransaction)
                {
                    var id      = tree.MessageId ?? _manager.NextMessageId();
                    var rootId  = tree.RootMessageId;
                    var childId = _manager.NextMessageId();

                    var source = message as DefaultTransaction;
                    var target = new DefaultTransaction(source.Type, source.Name, _manager);
                    target.Timestamp        = source.Timestamp;
                    target.DurationInMicros = source.DurationInMicros;
                    target.AddData(source.Data);
                    target.Status = PureCatConstants.SUCCESS;

                    MigrateMessage(stack, source, target, 1);

                    var list = stack.ToList();

                    for (var i = list.Count - 1; i >= 0; i--)
                    {
                        var tran = list[i] as DefaultTransaction;
                        if (tran != null)
                        {
                            tran.Timestamp        = timestamp;
                            tran.DurationInMicros = -1;
                        }
                    }

                    var next = new DefaultEvent(PureCatConstants.TYPE_REMOTE_CALL, "Next");
                    next.AddData(childId);
                    next.Status = PureCatConstants.SUCCESS;
                    target.AddChild(next);

                    var t = tree.Copy();

                    t.Message = target;

                    _mTree.MessageId       = childId;
                    _mTree.ParentMessageId = id;
                    _mTree.RootMessageId   = rootId ?? tree.MessageId;

                    _manager.Flush(t);
                }
            }
 public void Bind(string tag, string childMessageId, string title)
 {
     try
     {
         DefaultEvent evt = new DefaultEvent("RemoteCall", "Tagged");
         if (String.IsNullOrEmpty(title))
         {
             title = Type + ":" + Name;
         }
         evt.AddData(childMessageId, title);
         evt.Timestamp = Timestamp;
         evt.Status = CatConstants.SUCCESS;
         evt.SetCompleted(true);
         AddChild(evt);
     }
     catch (Exception ex)
     {
         Cat.lastException = ex;
     }
 }
        public virtual IEvent NewEvent(String type, String name, String nameValuePairs)
        {
            if (!_mManager.HasContext())
            {
                _mManager.Setup();
            }

            if (_mManager.CatEnabled)
            {
                IEvent evt0 = new DefaultEvent(type, name);

                // Need add data before event is added into context, so that estimated bytes is correct.
                if (!string.IsNullOrEmpty(nameValuePairs))
                {
                    evt0.AddData(nameValuePairs);
                }

                _mManager.Add(evt0);
                return(evt0);
            }
            return(new NullEvent());
        }
        public virtual IEvent NewEvent(String type, String name, String nameValuePairs)
        {
            if (!_mManager.HasContext())
            {
                _mManager.Setup();
            }

            if (_mManager.CatEnabled)
            {
                IEvent evt0 = new DefaultEvent(type, name);

                // Need add data before event is added into context, so that estimated bytes is correct.
                if (!string.IsNullOrEmpty(nameValuePairs))
                {
                    evt0.AddData(nameValuePairs);
                }

                _mManager.Add(evt0);
                return evt0;
            }
            return new NullEvent();
        }
        protected internal IMessage DecodeLine(ChannelBuffer buf, ITransaction parent,
                                               Stack<ITransaction> stack, IMessageTree tree)
        {
            BufferHelper helper = _mBufferHelper;
            byte identifier = buf.ReadByte();
            String timestamp = helper.Read(buf, TAB);
            String type = helper.Read(buf, TAB);
            String name = helper.Read(buf, TAB);

            if (identifier == 'E')
            {
                IMessage evt = new DefaultEvent(type, name);
                String status = helper.Read(buf, TAB);
                String data = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                evt.Timestamp = _mDateHelper.Parse(timestamp);
                evt.Status = status;
                evt.AddData(data);

                if (parent != null)
                {
                    parent.AddChild(evt);
                    tree.EstimatedByteSize += evt.EstimateByteSize();
                    return parent;
                }
                return evt;
            }
            if (identifier == 'M')
            {
                DefaultMetric metric = new DefaultMetric(type, name);
                String status = helper.Read(buf, TAB);
                String data = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                metric.Timestamp = _mDateHelper.Parse(timestamp);
                metric.Status = status;
                metric.AddData(data);

                if (parent != null)
                {
                    parent.AddChild(metric);
                    tree.EstimatedByteSize += metric.EstimateByteSize();
                    return parent;
                }
                return metric;
            }
            if (identifier == 'H')
            {
                IMessage heartbeat = new DefaultHeartbeat(type, name);
                String status0 = helper.Read(buf, TAB);
                String data1 = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                heartbeat.Timestamp = _mDateHelper.Parse(timestamp);
                heartbeat.Status = status0;
                heartbeat.AddData(data1);

                if (parent != null)
                {
                    parent.AddChild(heartbeat);
                    tree.EstimatedByteSize += heartbeat.EstimateByteSize();
                    return parent;
                }
                return heartbeat;
            }
            if (identifier == 't')
            {
                IMessage transaction = new DefaultTransaction(type, name,
                                                              null);

                helper.Read(buf, LF); // get rid of line feed
                transaction.Timestamp = _mDateHelper.Parse(timestamp);

                if (parent != null)
                {
                    parent.AddChild(transaction);
                }

                stack.Push(parent);
                return transaction;
            }
            if (identifier == 'A')
            {
                ITransaction transaction2 = new DefaultTransaction(type, name, null);
                String status3 = helper.Read(buf, TAB);
                String duration = helper.Read(buf, TAB);
                String data4 = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                transaction2.Timestamp = _mDateHelper.Parse(timestamp);
                transaction2.Status = status3;
                transaction2.AddData(data4);

                long d = Int64.Parse(duration.Substring(0, duration.Length - 2), NumberStyles.Integer);
                transaction2.DurationInMicros = d;

                if (parent != null)
                {
                    parent.AddChild(transaction2);
                    tree.EstimatedByteSize += transaction2.EstimateByteSize();
                    return parent;
                }
                return transaction2;
            }
            if (identifier == 'T')
            {
                String status5 = helper.Read(buf, TAB);
                String duration6 = helper.Read(buf, TAB);
                String data7 = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                parent.Status = status5;
                parent.AddData(data7);

                long d8 = Int64.Parse(
                    duration6.Substring(0, duration6.Length - 2),
                    NumberStyles.Integer);
                parent.DurationInMicros = d8;
                tree.EstimatedByteSize += parent.EstimateByteSize();
                return stack.Pop();
            }
            Logger.Error("Unknown identifier(" + identifier + ") of message: " + buf);

            // unknown message, ignore it
            return parent;
        }
Beispiel #12
0
        protected internal IMessage DecodeLine(ChannelBuffer buf, ITransaction parent,
                                               Stack <ITransaction> stack, IMessageTree tree)
        {
            BufferHelper helper     = _mBufferHelper;
            byte         identifier = buf.ReadByte();
            String       timestamp  = helper.Read(buf, TAB);
            String       type       = helper.Read(buf, TAB);
            String       name       = helper.Read(buf, TAB);

            if (identifier == 'E')
            {
                IMessage evt    = new DefaultEvent(type, name);
                String   status = helper.Read(buf, TAB);
                String   data   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                evt.Timestamp = _mDateHelper.Parse(timestamp);
                evt.Status    = status;
                evt.AddData(data);

                if (parent != null)
                {
                    parent.AddChild(evt);
                    tree.EstimatedByteSize += evt.EstimateByteSize();
                    return(parent);
                }
                return(evt);
            }
            if (identifier == 'M')
            {
                DefaultMetric metric = new DefaultMetric(type, name);
                String        status = helper.Read(buf, TAB);
                String        data   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                metric.Timestamp = _mDateHelper.Parse(timestamp);
                metric.Status    = status;
                metric.AddData(data);

                if (parent != null)
                {
                    parent.AddChild(metric);
                    tree.EstimatedByteSize += metric.EstimateByteSize();
                    return(parent);
                }
                return(metric);
            }
            if (identifier == 'H')
            {
                IMessage heartbeat = new DefaultHeartbeat(type, name);
                String   status0   = helper.Read(buf, TAB);
                String   data1     = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                heartbeat.Timestamp = _mDateHelper.Parse(timestamp);
                heartbeat.Status    = status0;
                heartbeat.AddData(data1);

                if (parent != null)
                {
                    parent.AddChild(heartbeat);
                    tree.EstimatedByteSize += heartbeat.EstimateByteSize();
                    return(parent);
                }
                return(heartbeat);
            }
            if (identifier == 't')
            {
                IMessage transaction = new DefaultTransaction(type, name,
                                                              null);

                helper.Read(buf, LF); // get rid of line feed
                transaction.Timestamp = _mDateHelper.Parse(timestamp);

                if (parent != null)
                {
                    parent.AddChild(transaction);
                    tree.EstimatedByteSize += transaction.EstimateByteSize();
                }

                stack.Push(parent);
                return(transaction);
            }
            if (identifier == 'A')
            {
                ITransaction transaction2 = new DefaultTransaction(type, name, null);
                String       status3      = helper.Read(buf, TAB);
                String       duration     = helper.Read(buf, TAB);
                String       data4        = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                transaction2.Timestamp = _mDateHelper.Parse(timestamp);
                transaction2.Status    = status3;
                transaction2.AddData(data4);

                long d = Int64.Parse(duration.Substring(0, duration.Length - 2), NumberStyles.Integer);
                transaction2.DurationInMicros = d;

                if (parent != null)
                {
                    parent.AddChild(transaction2);
                    tree.EstimatedByteSize += transaction2.EstimateByteSize();
                    return(parent);
                }
                return(transaction2);
            }
            if (identifier == 'T')
            {
                String status5   = helper.Read(buf, TAB);
                String duration6 = helper.Read(buf, TAB);
                String data7     = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF); // get rid of line feed
                parent.Status = status5;
                parent.AddData(data7);

                long d8 = Int64.Parse(
                    duration6.Substring(0, duration6.Length - 2),
                    NumberStyles.Integer);
                parent.DurationInMicros = d8;

                return(stack.Pop());
            }
            Logger.Error("Unknown identifier(" + identifier + ") of message: " + buf);

            // unknown message, ignore it
            return(parent);
        }
        protected internal IMessage DecodeLine(ChannelBuffer buf, ITransaction parent,
                                               Stack <ITransaction> stack, IMessageTree tree)
        {
            BufferHelper helper     = _mBufferHelper;
            char         identifier = (char)buf.ReadByte();
            string       timestamp  = helper.Read(buf, TAB);
            string       type       = helper.Read(buf, TAB);
            string       name       = helper.Read(buf, TAB);

            switch (identifier)
            {
            case 't':
                IMessage transaction = new DefaultTransaction(type, name, null);

                helper.Read(buf, LF);     // get rid of line feed
                transaction.Timestamp = _mDateHelper.Parse(timestamp);

                if (parent != null)
                {
                    parent.AddChild(transaction);
                }

                stack.Push(parent);
                return(transaction);

            case 'A':
                DefaultTransaction tran     = new DefaultTransaction(type, name, null);
                string             status   = helper.Read(buf, TAB);
                string             duration = helper.Read(buf, TAB);
                string             data     = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                tran.Timestamp = _mDateHelper.Parse(timestamp);
                tran.Status    = status;
                tran.AddData(data);

                long d = long.Parse(duration.Substring(0, duration.Length - 2), NumberStyles.Integer);

                tran.DurationInMicros = d;

                if (parent != null)
                {
                    parent.AddChild(tran);
                    return(parent);
                }
                return(tran);

            case 'T':
                string transactionStatus   = helper.Read(buf, TAB);
                string transactionDuration = helper.Read(buf, TAB);
                string transactionData     = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                parent.Status = transactionStatus;
                parent.AddData(transactionData);

                long transactionD = long.Parse(transactionDuration.Substring(0, transactionDuration.Length - 2), NumberStyles.Integer);

                parent.DurationInMicros = transactionD;

                return(stack.Pop());

            case 'E':
                DefaultEvent evt         = new DefaultEvent(type, name);
                string       eventStatus = helper.Read(buf, TAB);
                string       eventData   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                evt.Timestamp = _mDateHelper.Parse(timestamp);
                evt.Status    = eventStatus;
                evt.AddData(eventData);

                if (parent != null)
                {
                    parent.AddChild(evt);
                    return(parent);
                }
                return(evt);

            case 'M':
                DefaultMetric metric       = new DefaultMetric(type, name);
                string        metricStatus = helper.Read(buf, TAB);
                string        metricData   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);
                metric.Timestamp = _mDateHelper.Parse(timestamp);
                metric.Status    = metricStatus;
                metric.AddData(metricData);

                if (parent != null)
                {
                    parent.AddChild(metric);
                    return(parent);
                }
                return(metric);

            case 'L':
                DefaultTrace trace       = new DefaultTrace(type, name);
                string       traceStatus = helper.Read(buf, TAB);
                string       traceData   = helper.Read(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                trace.Timestamp = _mDateHelper.Parse(timestamp);
                trace.Status    = traceStatus;
                trace.AddData(traceData);

                if (parent != null)
                {
                    parent.AddChild(trace);
                    return(parent);
                }
                return(trace);

            case 'H':
                DefaultHeartbeat heartbeat       = new DefaultHeartbeat(type, name);
                string           heartbeatStatus = helper.Read(buf, TAB);
                string           heartbeatData   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                heartbeat.Timestamp = _mDateHelper.Parse(timestamp);
                heartbeat.Status    = heartbeatStatus;
                heartbeat.AddData(heartbeatData);

                if (parent != null)
                {
                    parent.AddChild(heartbeat);
                    return(parent);
                }
                return(heartbeat);
            }

            Logger.Error("Unknown identifier(" + identifier + ") of message: " + buf);
            //throw new Exception("Unknown identifier int name"); //java版的抛出异常

            // unknown message, ignore it
            return(parent);
        }
            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);
                }
            }
            public void LinkAsRunAway(DefaultForkedTransaction transaction)
            {
                DefaultEvent evt = new DefaultEvent("RemoteCall", "RunAway");

                evt.AddData(transaction.ForkedMessageId, transaction.Type + ":" + transaction.Name);
                evt.Timestamp = transaction.Timestamp;
                evt.Status = CatConstants.SUCCESS;
                evt.SetCompleted(true);
                transaction.Standalone = true;

                _mManager.Add(evt);
            }
            private void AdjustForTruncatedTransaction(ITransaction root)
            {
                DefaultEvent next = new DefaultEvent("TruncatedTransaction", "TotalDuration");
                long actualDurationInMicros = _mTotalDurationInMicros + root.DurationInMicros;

                next.AddData(Convert.ToString(actualDurationInMicros));
                next.Status = CatConstants.SUCCESS;
                root.AddChild(next);

                _mTotalDurationInMicros = 0;
            }