Exemplo n.º 1
0
        private bool ReadCursor()
        {
            if (_cursor == null)
            {
                return(false);
            }
            StringBuilder sbDumpCursor = new StringBuilder();

            Stopwatch swReadCursor = new Stopwatch();

            swReadCursor.Start();

            _cursor.Begin();

            string attributeName, attributeValue, columnName, columnValue = Str.Empty;
            int    attributeSize, columnSize = 0;

            //read all attributes (once)
            foreach (string attrName in _cursor.AttributesNames)
            {
                attributeName  = $"[attribute] {attrName}";
                attributeValue = _cursor.GetAttribute(attrName);
                swReadCursor.Stop();                    //stop watch while add/update dictionnary and dump

                //attribute size
                attributeSize = attributeValue.Length;
                if (cursorSizeBreakdown.ContainsKey(attributeName))
                {
                    cursorSizeBreakdown[attributeName] += attributeSize;
                }
                else
                {
                    cursorSizeBreakdown.Add(attributeName, attributeSize);
                }

                //dump attribute name/value
                if (_threadGroup.conf.dumpCursor)
                {
                    sbDumpCursor.AppendLine($"{attributeName}{_threadGroup.conf.outputCSVSeparator}{attributeValue}");
                }

                //restart watch
                swReadCursor.Start();
            }

            //dump column name
            if (_threadGroup.conf.dumpCursor)
            {
                for (int i = 0; i < _cursor.ColumnCount; i++)
                {
                    columnName = $"[column] {_cursor.GetColumnName(i)}";
                    sbDumpCursor.Append($"{columnName}{_threadGroup.conf.outputCSVSeparator}");
                }
                sbDumpCursor.Append(Environment.NewLine);
            }

            while (!_cursor.End() && _cursor.CursorRowCount > 0)
            {
                //read all columns from the cursor (all rows)
                for (int i = 0; i < _cursor.ColumnCount; i++)
                {
                    columnName  = $"[column] {_cursor.GetColumnName(i)}";
                    columnValue = _cursor.GetColumn(i);
                    swReadCursor.Stop();                      //stop watch while add/update dictionnary and dump

                    //column value size
                    columnSize = columnValue.Length;
                    if (cursorSizeBreakdown.ContainsKey(columnName))
                    {
                        cursorSizeBreakdown[columnName] += columnSize;
                    }
                    else
                    {
                        cursorSizeBreakdown.Add(columnName, columnSize);
                    }

                    //dump column value
                    if (_threadGroup.conf.dumpCursor)
                    {
                        sbDumpCursor.Append($"{columnValue}{_threadGroup.conf.outputCSVSeparator}");
                    }
                }
                if (_threadGroup.conf.dumpCursor)
                {
                    sbDumpCursor.Append(Environment.NewLine);
                }

                //restart watch
                swReadCursor.Start();
                _cursor.MoveNext();
            }

            swReadCursor.Stop();
            readCursorTimer = swReadCursor.ElapsedMilliseconds;
            AddToTotalTime(readCursorTimer);
            swReadCursor.Reset();

            Sys.Log2(50, $"{{{threadId}}} Thread group [{threadGroupName}][{iteration}] ReadCursor [{Sys.TimerGetText(readCursorTimer)}]");

            //write cursor
            //TODO - dump separator exist in column / attr ?
            //TODO use log array ?
            if (_threadGroup.conf.dumpCursor && processingTime >= _threadGroup.conf.dumpCursorMinProcessingTime && cursorSizeMB >= _threadGroup.conf.dumpCursorMinSize)
            {
                string dumpQueryFilePath = Toolbox.GetOutputFilePath(_threadGroup.conf.outputFolderPath, $"cursor_{_threadGroup.name}_{iteration}", "csv", "Cursors");

                Stopwatch swDumpCursor = new Stopwatch();
                swDumpCursor.Start();
                if (Toolbox.DumpFile(dumpQueryFilePath, sbDumpCursor.ToString()))
                {
                    swDumpCursor.Stop();
                    Sys.Log($"{{{threadId}}} Thread group [{threadGroupName}][{iteration}] Create Cursor dump [{dumpQueryFilePath}] [{Sys.TimerGetText(swDumpCursor.ElapsedMilliseconds)}]");
                }
            }
            else
            {
                Sys.Log2(50, $"{{{threadId}}} Thread group [{threadGroupName}][{iteration}] Skip Cursor dump, ProcessingTime [{processingTime.ToString()}] < Minimum query processing time [{_threadGroup.conf.dumpCursorMinProcessingTime.ToString()}] or Cursor Size [{cursorSizeMB.ToString()}] < Minimun cursor size [{_threadGroup.conf.dumpCursorMinSize.ToString()}]");
            }

            return(true);
        }