예제 #1
0
        public static TracingSession GetTracingSession(this IConnection @this, Guid tracingId)
        {
            string queryEvents = "select * from system_traces.events where session_id=" + tracingId.ToString();
            List<TracingEvent> tracingEvents = new List<TracingEvent>();
            IDataMapperFactory factory = new DataMapperFactory(null);
            foreach (IDictionary<string, object> mapEvents in CQLCommandHelpers.Query(@this, queryEvents, ConsistencyLevel.ONE, factory, ExecutionFlags.None).Result)
            {
                TracingEvent tracingEvent = new TracingEvent((string) mapEvents["activity"],
                                                             (Guid) mapEvents["event_id"],
                                                             (IPAddress) mapEvents["source"],
                                                             (int) mapEvents["source_elapsed"],
                                                             (string) mapEvents["thread"]);
                tracingEvents.Add(tracingEvent);
            }
            tracingEvents.Sort(CompareTracingEvent);
            TracingEvent[] events = tracingEvents.ToArray();

            string querySession = "select * from system_traces.sessions where session_id=" + tracingId.ToString();
            IDictionary<string, object> mapSession =
                    (IDictionary<string, object>)
                    CQLCommandHelpers.Query(@this, querySession, ConsistencyLevel.ONE, factory, ExecutionFlags.None).Result.Single();
            TracingSession tracingSession = new TracingSession((IPAddress) mapSession["coordinator"],
                                                               (int) mapSession["duration"],
                                                               (IDictionary<string, string>) mapSession["parameters"],
                                                               (string) mapSession["request"],
                                                               (Guid) mapSession["session_id"],
                                                               (DateTime) mapSession["started_at"],
                                                               events);

            return tracingSession;
        }
예제 #2
0
        public static TracingSession QueryTracingInfo(this ICluster @this, Guid tracingId)
        {
            var cmd = @this.CreatePocoCommand();

            // query events and session
            string queryEvents = "select * from system_traces.events where session_id = " + tracingId;
            var    obsEvents   = cmd.WithConsistencyLevel(ConsistencyLevel.ONE)
                                 .Execute <TracingEvent>(queryEvents)
                                 .AsFuture();

            string querySession = "select * from system_traces.sessions where session_id = " + tracingId;
            var    obsSession   = cmd.WithConsistencyLevel(ConsistencyLevel.ONE)
                                  .Execute <TracingSession>(querySession)
                                  .AsFuture();

            Task.WaitAll(obsEvents, obsSession);

            // format the events
            var tracingEvents = obsEvents.Result.ToList();

            tracingEvents.Sort(CompareTracingEvent);
            TracingEvent[] events = tracingEvents.ToArray();
            foreach (var evt in events)
            {
                string[] tmp = evt.Thread.Split(':');
                evt.Stage  = tmp[0];
                evt.Thread = tmp[1];
            }

            // build the result
            TracingSession tracingSession = obsSession.Result.Single();

            tracingSession.TracingEvents = events;
            return(tracingSession);
        }
예제 #3
0
        public async Task BasicFlow()
        {
            //Assume
            const string insertCql   = @"insert into Test.BasicFlow (id,value) values (?,?);";
            const string retrieveCql = @"select * from Test.BasicFlow;";

            const int insertCount = 1000;

            //Act
            using (var connection = new CqlConnection(ConnectionString))
            {
                await connection.OpenAsync();

                var executions = new Task <ICqlQueryResult> [insertCount];

                var options = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 1
                };
                Parallel.For(0, insertCount, options, (i) =>
                {
                    var cmd = new CqlCommand(connection, insertCql, CqlConsistency.One);
                    cmd.Prepare();

                    var b = new BasicFlowData {
                        Id = i, Data = "Hallo " + i
                    };
                    cmd.PartitionKey.Set(b);
                    cmd.Parameters.Set(b);

                    executions[i] = cmd.ExecuteNonQueryAsync();
                });

                await Task.WhenAll(executions);

                var presence = new bool[insertCount];

                var selectCmd = new CqlCommand(connection, retrieveCql, CqlConsistency.One)
                {
                    EnableTracing = true
                };

                CqlDataReader <BasicFlowData> reader = await selectCmd.ExecuteReaderAsync <BasicFlowData>();

                while (await reader.ReadAsync())
                {
                    BasicFlowData row = reader.Current;
                    Assert.AreEqual(row.Data, "Hallo " + row.Id);
                    presence[row.Id] = true;
                }

                Assert.IsTrue(presence.All(p => p));

                var            tracer  = new QueryTraceCommand(connection, reader.TracingId.Value);
                TracingSession session = await tracer.GetTraceSessionAsync();

                Assert.IsNotNull(session);
            }
        }
            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);
            }
        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);
        }
 public void ServerTrace(InstrumentationToken token, TracingSession tracingSession)
 {
 }