예제 #1
0
        private IList <DataengineEvent> GetAllQueryExecuteEvents(int sessionId, IList <BsonDocument> sessionLines)
        {
            IList <DataengineEvent> queryExecuteEvents = new List <DataengineEvent>();
            Queue <BsonDocument>    lineQueue          = new Queue <BsonDocument>();

            foreach (var line in sessionLines)
            {
                string message = BsonDocumentHelper.GetString("message", line);
                if (message.Contains("QueryExecute"))
                {
                    lineQueue.Enqueue(line);
                }
            }

            lineQueue = SortByLogLine(lineQueue);

            while (lineQueue.Count >= 2)
            {
                try
                {
                    DataengineEvent queryExecuteEvent = GetDataEngineEvent(sessionId, "QueryExecute", lineQueue.Dequeue(), lineQueue.Dequeue());
                    // Filter out all (database null) queries, which are used for closing a connection.
                    if (!queryExecuteEvent.Query.Equals("(database null)"))
                    {
                        queryExecuteEvents.Add(queryExecuteEvent);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Problem gathering QueryExecute event data on session:" + sessionId, ex);
                }
            }

            return(queryExecuteEvents);
        }
예제 #2
0
        private IList <DataengineEvent> GetAllStatementExecuteEvents(int sessionId, IList <BsonDocument> sessionLines, IDictionary <int, StatementPrepareEvent> statementPrepareEvents)
        {
            IList <DataengineEvent> statementExecuteEvents = new List <DataengineEvent>();
            Queue <BsonDocument>    lineQueue = new Queue <BsonDocument>();

            foreach (var line in sessionLines)
            {
                string message = BsonDocumentHelper.GetString("message", line);
                if (message.Contains("StatementExecute"))
                {
                    lineQueue.Enqueue(line);
                }
            }

            lineQueue = SortByLogLine(lineQueue);

            while (lineQueue.Count >= 2)
            {
                try
                {
                    BsonDocument    startEvent            = lineQueue.Dequeue();
                    BsonDocument    endEvent              = lineQueue.Dequeue();
                    DataengineEvent statementExecuteEvent = GetDataEngineEvent(sessionId, "StatementExecute", startEvent, endEvent);

                    int statementGuid = GetStatementGuidFromLogLine(startEvent);
                    StatementPrepareEvent prepareEvent = statementPrepareEvents[statementGuid];
                    string queryText = prepareEvent.Query;

                    statementExecuteEvent.Query = queryText;
                    statementExecuteEvents.Add(statementExecuteEvent);
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Problem gathering StatementExecute event data on session '{0}': {1}", sessionId, ex.Message);
                }
            }

            return(statementExecuteEvents);
        }
예제 #3
0
        private DataengineEvent GetDataEngineEvent(int sessionGuid, string eventType, BsonDocument startEvent, BsonDocument endEvent)
        {
            DataengineEvent dataEngineEvent = new DataengineEvent
            {
                SessionGuid = sessionGuid,
                ThreadId    = Int32.Parse(BsonDocumentHelper.GetString("tid", startEvent)),
                Timestamp   = BsonDocumentHelper.GetDateTime("ts", endEvent),
                Worker      = BsonDocumentHelper.GetInt("worker", startEvent),
                LineNumber  = BsonDocumentHelper.GetInt("line", endEvent),
                EventType   = eventType
            };

            foreach (var sessionEvent in GetEventsForRange(startEvent, endEvent))
            {
                string message = BsonDocumentHelper.GetString("message", sessionEvent);
                if (!message.Contains(eventType) && !message.StartsWith("Compiling query"))
                {
                    dataEngineEvent.Query = String.Format("{0} {1}", dataEngineEvent.Query, message);
                }

                if (message.StartsWith("Compiling query with Memory Budget="))
                {
                    string memoryBudgetString = message.Replace("Compiling query with Memory Budget=", "");
                    Int64  memoryBudget;
                    if (Int64.TryParse(memoryBudgetString, out memoryBudget))
                    {
                        dataEngineEvent.MemoryBudget = memoryBudget;
                    }
                }

                if (message.Contains(eventType + ": OK"))
                {
                    dataEngineEvent.Success = true;

                    var messageChunks = message.Split(',').Select(s => s.Trim());
                    foreach (var chunk in messageChunks)
                    {
                        if (chunk.StartsWith("Elapsed time:"))
                        {
                            dataEngineEvent.ElapsedTime = ExtractTime(chunk, "Elapsed time:");
                        }

                        if (chunk.StartsWith("Compilation time:"))
                        {
                            dataEngineEvent.CompilationTime = ExtractTime(chunk, "Compilation time:");
                        }

                        if (chunk.StartsWith("Execution time:"))
                        {
                            dataEngineEvent.ExecutionTime = ExtractTime(chunk, "Execution time:");
                        }

                        if (chunk.StartsWith("n_columns="))
                        {
                            int columns;
                            if (Int32.TryParse(chunk.Split(' ').Last().Split('=')[1], out columns))
                            {
                                dataEngineEvent.Columns = columns;
                            }
                        }
                    }
                }

                if (message.Contains(eventType + ": FAILED"))
                {
                    dataEngineEvent.Success = false;

                    var messageChunks = message.Split(',').Select(s => s.Trim());
                    foreach (var chunk in messageChunks)
                    {
                        if (chunk.StartsWith("error="))
                        {
                            dataEngineEvent.Error = chunk.Replace("error=", "");
                        }
                    }
                }
            }

            // Trim unneccessary whitespace.
            if (!String.IsNullOrEmpty(dataEngineEvent.Query))
            {
                dataEngineEvent.Query = dataEngineEvent.Query.Trim();
            }

            dataEngineEvent.LogsetHash = logsetHash;
            dataEngineEvent.EventHash  = HashHelper.GenerateHashGuid(dataEngineEvent.SessionGuid, dataEngineEvent.ThreadId, dataEngineEvent.Timestamp, dataEngineEvent.LineNumber);

            return(dataEngineEvent);
        }