Пример #1
0
 public void ServerTrace(InstrumentationToken token, Guid traceId)
 {
     lock (_lock)
     {
         _tracingIds.Add(traceId);
     }
 }
Пример #2
0
 public void ClientTrace(InstrumentationToken token, EventType eventType)
 {
     if (0 != (token.ExecutionFlags & ExecutionFlags.ClientTracing))
     {
         string buffer = string.Format("INSTR {0} [{1}] - id:{2} type:{3}",
                                       DateTime.Now, Thread.CurrentThread.ManagedThreadId,
                                       token.Id, eventType);
         Console.WriteLine(buffer);
     }
 }
 public void ClientConnectionInfo(InstrumentationToken token, IPAddress coordinator, byte streamId)
 {
     if (0 != (token.ExecutionFlags & ExecutionFlags.ClientTracing))
     {
         string buffer = string.Format("INSTR {0} [{1}] - id:{2} type:{3} coordinator:{4} streamId:{5} cql:{6}",
                                       DateTime.Now, Thread.CurrentThread.ManagedThreadId,
                                       token.Id, token.Type, coordinator, streamId, token.Cql);
         Console.WriteLine(buffer);
     }
 }
 public void ClientTrace(InstrumentationToken token, EventType eventType)
 {
     if (CommandContext.DebugLog)
     {
         string buffer = string.Format("INSTR {0} [{1}] - queryId:{2} type:{3}",
                                       DateTime.Now, Thread.CurrentThread.ManagedThreadId,
                                       token.Id, eventType);
         Console.WriteLine(buffer);
     }
 }
 public void ClientConnectionInfo(InstrumentationToken token, IPAddress coordinator, byte streamId)
 {
     if (CommandContext.DebugLog)
     {
         string buffer = string.Format("INSTR {0} [{1}] - queryId:{2} coordinator:{3} streamId:{4}",
                                       DateTime.Now, Thread.CurrentThread.ManagedThreadId,
                                       token.Id, coordinator, streamId);
         Console.WriteLine(buffer);
     }
 }
 public void ClientTrace(InstrumentationToken token, EventType eventType)
 {
     if (0 != (token.ExecutionFlags & ExecutionFlags.ClientTracing))
     {
         string buffer = string.Format("INSTR {0} [{1}] - id:{2} type:{3}",
                                       DateTime.Now, Thread.CurrentThread.ManagedThreadId,
                                       token.Id, eventType);
         Console.WriteLine(buffer);
     }
 }
Пример #7
0
 public void ClientConnectionInfo(InstrumentationToken token, IPAddress coordinator, ushort streamId)
 {
     if (0 != (token.ExecutionFlags & ExecutionFlags.ClientTracing))
     {
         string buffer = string.Format("INSTR {0} [{1}] - id:{2} type:{3} coordinator:{4} streamId:{5} cql:{6}",
                                       DateTime.Now, Thread.CurrentThread.ManagedThreadId,
                                       token.Id, token.Type, coordinator, streamId, token.Cql);
         Console.WriteLine(buffer);
     }
 }
            public void ServerTrace(InstrumentationToken token, TracingSession tracingSession)
            {
                StringBuilder sb = new StringBuilder();
                foreach (TracingEvent te in tracingSession.TracingEvents)
                {
                    sb.AppendFormat("{0},{1},{2},{3},{4},{5}", tracingSession.SessionId, te.Activity, te.EventId, te.Source, te.SourceElapsed, te.Thread);
                    sb.AppendLine();
                }

                lock (_lock)
                    _txtWriter.Write(sb);
            }
Пример #9
0
 private static void QueryAndPushTracingSessionWorker(IConnection connection, Guid tracingId, InstrumentationToken token,
                                                      IInstrumentation instrumentation,
                                                      ILogger logger)
 {
     try
     {
         QueryAndPushTracingSession(connection, tracingId, token, instrumentation);
     }
     catch (Exception ex)
     {
         logger.Error("Failed to read performance for {0}: {1}", tracingId, ex);
     }
 }
Пример #10
0
        private void PushResult(QueryInfo queryInfo, IFrameReader frameReader, bool isAsync)
        {
            try
            {
                _instrumentation.ClientTrace(queryInfo.Token, EventType.BeginRead);
                try
                {
                    if (null != frameReader.ResponseException)
                    {
                        throw frameReader.ResponseException;
                    }

                    queryInfo.Push(frameReader);
                }
                catch (Exception ex)
                {
                    queryInfo.NotifyError(ex);

                    if (IsStreamInBadState(ex))
                    {
                        throw;
                    }
                }

                _instrumentation.ClientTrace(queryInfo.Token, EventType.EndRead);

                InstrumentationToken token = queryInfo.Token;
                if (0 != (token.ExecutionFlags & ExecutionFlags.ServerTracing))
                {
                    _instrumentation.ServerTrace(token, frameReader.TraceId);
                }
            }
            catch (Exception ex)
            {
                if (isAsync)
                {
                    HandleError(ex);
                }
            }
            finally
            {
                if (isAsync)
                {
                    frameReader.SafeDispose();
                }
            }
        }
        private void SendQuery()
        {
            foreach (var queryInfo in _pendingQueries.GetConsumingEnumerable())
            {
                byte streamId = AcquireNextStreamId();

                if (_isClosed == 1)
                {
                    // abort queries.
                    var ex = new OperationCanceledException();
                    queryInfo.NotifyError(ex);
                    _instrumentation.ClientTrace(queryInfo.Token, EventType.Cancellation);
                    throw ex;
                }

                try
                {
                    InstrumentationToken token = queryInfo.Token;
                    bool tracing = 0 != (token.ExecutionFlags & ExecutionFlags.ServerTracing);
                    using (var bufferingFrameWriter = new BufferingFrameWriter(tracing))
                    {
                        queryInfo.Write(bufferingFrameWriter);

                        _logger.Debug("Starting writing frame for stream {0}@{1}", streamId, Endpoint);
                        _instrumentation.ClientTrace(token, EventType.BeginWrite);

                        _queryInfos[streamId] = queryInfo;
                        bufferingFrameWriter.SendFrame(streamId, _socket);

                        _logger.Debug("Done writing frame for stream {0}@{1}", streamId, Endpoint);
                        _instrumentation.ClientTrace(token, EventType.EndWrite);
                    }
                }
                catch (Exception ex)
                {
                    queryInfo.NotifyError(ex);

                    if (IsStreamInBadState(ex))
                    {
                        throw;
                    }
                }
            }
        }
Пример #12
0
        private static void QueryAndPushTracingSession(IConnection connection, Guid tracingId, InstrumentationToken token, IInstrumentation instrumentation)
        {
            string queryEvents = "select * from system_traces.events where session_id=" + tracingId;
            IDataMapperFactory facEvents = new DataMapperFactory<TracingEvent>(null);
            var obsEvents = CQLCommandHelpers.CreateQuery(connection, queryEvents, ConsistencyLevel.ONE, facEvents, ExecutionFlags.None).Cast<TracingEvent>();
            var tracingEvents = obsEvents.AsFuture().Result.ToList();
            tracingEvents.Sort(CompareTracingEvent);
            TracingEvent[] events = tracingEvents.ToArray();

            string querySession = "select * from system_traces.sessions where session_id=" + tracingId;

            IDataMapperFactory facSession = new DataMapperFactory<TracingSession>(null);
            var obsSession =
                    CQLCommandHelpers.CreateQuery(connection, querySession, ConsistencyLevel.ONE, facSession, ExecutionFlags.None).Cast<TracingSession>();
            TracingSession tracingSession = obsSession.AsFuture().Result.Single();
            tracingSession.TracingEvents = events;

            instrumentation.ServerTrace(token, tracingSession);
        }
        public void ServerTrace(InstrumentationToken token, TracingSession tracingSession)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("INSTR {0} [{1}] - ",
                            DateTime.Now, Thread.CurrentThread.ManagedThreadId);
            int len = sb.Length;
            string offset = new string(' ', len);

            sb.AppendFormat("sessionId:{0} startedAt:{1} coordinator:{2} duration:{3} request:{4}",
                            tracingSession.SessionId, tracingSession.StartedAt, tracingSession.Coordinator, tracingSession.Duration,
                            tracingSession.Parameters["query"]);
            foreach (TracingEvent tracingEvent in tracingSession.TracingEvents)
            {
                sb.AppendLine();
                sb.Append(offset);
                sb.AppendFormat("sourceElapsed:{0} activity:{1} thread:{2}", tracingEvent.SourceElapsed, tracingEvent.Activity, tracingEvent.Thread);
            }

            Console.WriteLine(sb);
        }
Пример #14
0
        public void ClientTrace(InstrumentationToken token, EventType eventType)
        {
            switch (eventType)
            {
            case EventType.BeginRead:
                _readWatch.Start();
                break;

            case EventType.EndRead:
                _readWatch.Stop();
                break;

            case EventType.BeginWrite:
                _writeWatch.Start();
                break;

            case EventType.EndWrite:
                _writeWatch.Stop();
                break;
            }
        }
Пример #15
0
        public void ServerTrace(InstrumentationToken token, Guid traceId)
        {
            //TracingSession tracingSession = tracingSessionFunc();

            //StringBuilder sb = new StringBuilder();
            //sb.AppendFormat("INSTR {0} [{1}] - ",
            //                DateTime.Now, Thread.CurrentThread.ManagedThreadId);
            //int len = sb.Length;
            //string offset = new string(' ', len);

            //sb.AppendFormat("sessionId:{0} startedAt:{1} coordinator:{2} duration:{3} request:{4}",
            //                tracingSession.SessionId, tracingSession.StartedAt, tracingSession.Coordinator, tracingSession.Duration,
            //                tracingSession.Parameters["query"]);
            //foreach (TracingEvent tracingEvent in tracingSession.TracingEvents)
            //{
            //    sb.AppendLine();
            //    sb.Append(offset);
            //    sb.AppendFormat("sourceElapsed:{0} activity:{1} stage:{2} thread:{3}", tracingEvent.SourceElapsed, tracingEvent.Activity, tracingEvent.Stage, tracingEvent.Thread);
            //}

            //Console.WriteLine(sb);
        }
Пример #16
0
 public void ClientTrace(InstrumentationToken token, EventType eventType)
 {
 }
Пример #17
0
 public void ClientConnectionInfo(InstrumentationToken token, IPAddress coordinator, byte streamId)
 {
 }
Пример #18
0
 public void ClientQuery(InstrumentationToken token)
 {
 }
Пример #19
0
        protected override InstrumentationToken CreateInstrumentationToken()
        {
            InstrumentationToken token = InstrumentationToken.Create(RequestType.Authenticate, ExecutionFlags.None);

            return(token);
        }
Пример #20
0
        protected override InstrumentationToken CreateInstrumentationToken()
        {
            InstrumentationToken token = InstrumentationToken.Create(RequestType.Prepare, ExecutionFlags, CQL);

            return(token);
        }
Пример #21
0
 public void ClientConnectionInfo(InstrumentationToken token, IPAddress coordinator, byte streamId)
 {
 }
        public void Execute <T>(Action <IFrameWriter> writer, Func <IFrameReader, IEnumerable <T> > reader, InstrumentationToken token,
                                IObserver <T> observer)
        {
            if (_isClosed == 1)
            {
                var ex = new OperationCanceledException();
                OnFailure?.Invoke(this, new FailureEventArgs(ex));
                throw ex;
            }
            QueryInfo queryInfo = new QueryInfo <T>(writer, reader, token, observer);

            _pendingQueries.Add(queryInfo);
        }
Пример #23
0
        public void Execute <T>(Action <IFrameWriter> writer, Func <IFrameReader, IEnumerable <T> > reader, InstrumentationToken token,
                                IObserver <T> observer)
        {
            QueryInfo queryInfo = new QueryInfo <T>(writer, reader, token, observer);

            lock (_lock)
            {
                Monitor.Pulse(_lock);
                if (_isClosed)
                {
                    throw new OperationCanceledException();
                }

                _pendingQueries.Enqueue(queryInfo);
            }
        }
Пример #24
0
        private void SendQuery()
        {
            while (true)
            {
                QueryInfo queryInfo;
                lock (_lock)
                {
                    while (!_isClosed && 0 == _pendingQueries.Count)
                    {
                        Monitor.Wait(_lock);
                    }
                    if (_isClosed)
                    {
                        Monitor.Pulse(_lock);
                        return;
                    }

                    queryInfo = _pendingQueries.Dequeue();
                }

                try
                {
                    // acquire the global lock to write the request
                    InstrumentationToken token = queryInfo.Token;
                    bool tracing = 0 != (token.ExecutionFlags & ExecutionFlags.ServerTracing);
                    using (BufferingFrameWriter bufferingFrameWriter = new BufferingFrameWriter(tracing))
                    {
                        queryInfo.Write(bufferingFrameWriter);

                        ushort streamId;
                        lock (_lock)
                        {
                            while (!_isClosed && 0 == _availableStreamIds.Count)
                            {
                                Monitor.Wait(_lock);
                            }
                            if (_isClosed)
                            {
                                queryInfo.NotifyError(new OperationCanceledException());
                                _instrumentation.ClientTrace(token, EventType.Cancellation);
                                Monitor.Pulse(_lock);
                                return;
                            }

                            streamId = _availableStreamIds.Pop();
                        }

                        _logger.Debug("Starting writing frame for stream {0}@{1}", streamId, Endpoint);
                        _instrumentation.ClientTrace(token, EventType.BeginWrite);

                        _queryInfos[streamId] = queryInfo;
                        bufferingFrameWriter.SendFrame(streamId, _socket);

                        _logger.Debug("Done writing frame for stream {0}@{1}", streamId, Endpoint);
                        _instrumentation.ClientTrace(token, EventType.EndWrite);
                    }
                }
                catch (Exception ex)
                {
                    queryInfo.NotifyError(ex);

                    if (IsStreamInBadState(ex))
                    {
                        throw;
                    }
                }
            }
        }
Пример #25
0
 protected QueryInfo(InstrumentationToken token)
 {
     Token = token;
 }
Пример #26
0
 public void ServerTrace(InstrumentationToken token, Guid tracingId)
 {
 }
Пример #27
0
 public void ServerTrace(InstrumentationToken token, Guid tracingId)
 {
 }
 public void ServerTrace(InstrumentationToken token, TracingSession tracingSession)
 {
 }
Пример #29
0
 public static void AsyncQueryAndPushTracingSession(IConnection connection, Guid tracingId, InstrumentationToken token, IInstrumentation instrumentation,
                                                    ILogger logger)
 {
     Task.Factory.StartNew(() => QueryAndPushTracingSessionWorker(connection, tracingId, token, instrumentation, logger));
 }
Пример #30
0
        public Task<IEnumerable<object>> Execute(Action<IFrameWriter> writer, Func<IFrameReader, IEnumerable<object>> reader, ExecutionFlags executionFlags,
            InstrumentationToken instrumentationToken)
        {
            _instrumentation.ClientQuery(instrumentationToken);

            Task<IEnumerable<object>> taskRead;
            byte streamId;
            lock (_globalLock)
            {
                while (0 == _availableStreamIds.Count)
                {
                    _logger.Debug("Waiting for available stream id for {0}", Endpoint);
                    _cancellation.Token.ThrowIfCancellationRequested();
                    Monitor.Wait(_globalLock);
                }
                _cancellation.Token.ThrowIfCancellationRequested();

                // get the stream id and initialize async reader context
                streamId = _availableStreamIds.Pop();

                // promise to stream results
                taskRead = new Task<IEnumerable<object>>(() => ReadResultStream(streamId, reader));
                _queryInfos[streamId].InstrumentationToken = instrumentationToken;
                _queryInfos[streamId].ReadTask = taskRead;

                _instrumentation.ClientConnectionInfo(instrumentationToken, Endpoint, streamId);
            }
            _logger.Debug("Using stream {0}@{1}", streamId, Endpoint);

            // write the request asynchronously
            StartWriteNextFrame(writer, streamId, executionFlags);

            return taskRead;
        }
Пример #31
0
 public void ClientTrace(InstrumentationToken token, EventType eventType)
 {
 }
Пример #32
0
 public void ClientQuery(InstrumentationToken token)
 {
 }