示例#1
0
        public TraceObserver <T> ReadTraceRecords <T>(IObservable <T> source)
        {
            DateTime          startTime = DateTime.Now;
            TraceObserver <T> observer  = new TraceObserver <T>();

            source.Subscribe(observer);
            int  records    = -1;
            bool waitResult = false;

            while (!waitResult && observer.Records.Count > records)
            {
                records = observer.Records.Count;
                Log.Debug($"waiting for completion:current record count{records}");
                waitResult = observer.Completed.Wait(Constants.ThreadSleepMs10000, _fileTasks.CancellationToken);
            }

            if (!waitResult)
            {
                _instance.TotalErrors++;
                Log.Error($"timed out waiting for observer progress.", source);
            }

            int    totalMs          = (int)(DateTime.Now - startTime).TotalMilliseconds;
            int    recordsCount     = observer.Records.Count;
            double recordsPerSecond = recordsCount / (totalMs * .001);

            Log.Info($"complete:{waitResult} total ms:{totalMs} total records:{recordsCount} records per second:{recordsPerSecond}");
            return(observer);
        }
示例#2
0
        public bool TxEtl(FileObject fileObject, string outputFile)
        {
            // this forces blg output timestamps to use local capture timezone which is utc for azure
            // Tx module is not able to determine with PDH api blg source timezone
            // todo: verify if needed for etl...
            //TimeUtil.DateTimeKind = DateTimeKind.Unspecified;

            DateTime startTime = DateTime.Now;
            IObservable <EtwNativeEvent>   observable   = default(IObservable <EtwNativeEvent>);
            TraceObserver <EtwNativeEvent> traceSession = default(TraceObserver <EtwNativeEvent>);
            //List<EtwNativeEvent> records = new List<EtwNativeEvent>();
            List <DtrTraceRecord> csvRecords = new List <DtrTraceRecord>();

            // todo: verify if needed for etl...testing pdh found invalid data when using concurrently
            // lock (_lockObj)
            // {
            Log.Debug($"observable creating: {fileObject.FileUri}");
            observable = EtwObservable.FromFiles(fileObject.FileUri);

            Log.Debug($"observable created: {fileObject.FileUri}");
            traceSession = ReadTraceRecords(observable);
            Log.Debug($"finished total ms: {DateTime.Now.Subtract(startTime).TotalMilliseconds} reading: {fileObject.FileUri}");
            //    records = traceSession.Records;
            // }

            //foreach (EtwNativeEvent record in records)
            foreach (EtwNativeEvent record in traceSession.Records)
            {
                //Log.Info("record", record);
                //if (!string.IsNullOrEmpty(record.Value.ToString()))
                //{
                //    string counterValue = record.Value.ToString() == "NaN" ? "0" : record.Value.ToString();

                //    try
                //    {
                //        csvRecords.Add(new CsvCounterRecord()
                //        {
                //            Timestamp = record.Timestamp,
                //            CounterName = record.CounterPath.Replace("\"", "").Trim(),
                //            CounterValue = Decimal.Parse(counterValue, NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint),
                //            Object = record.CounterSet?.Replace("\"", "").Trim(),
                //            Counter = record.CounterName.Replace("\"", "").Trim(),
                //            Instance = record.Instance?.Replace("\"", "").Trim(),
                //            NodeName = fileObject.NodeName,
                //            FileType = fileObject.FileDataType.ToString(),
                //            RelativeUri = fileObject.RelativeUri
                //        });
                //    }
                //    catch (Exception ex)
                //    {
                //        Log.Exception($"stringValue:{counterValue} exception:{ex}", record);
                //    }
                //}
                //else
                //{
                //    Log.Warning($"empty counter value:", record);
                //}
            }

            fileObject.Stream.Write(csvRecords);
            Log.Info($"records: {traceSession.Records.Count()} {csvRecords.Count}");
            traceSession.Dispose();
            return(true);
        }
示例#3
0
        public bool TxBlg(FileObject fileObject, string outputFile)
        {
            // this forces blg output timestamps to use local capture timezone which is utc for azure
            // Tx module is not able to determine with PDH api blg source timezone
            TimeUtil.DateTimeKind = DateTimeKind.Unspecified;

            DateTime startTime = DateTime.Now;
            IObservable <PerformanceSample>   observable     = default(IObservable <PerformanceSample>);
            TraceObserver <PerformanceSample> counterSession = default(TraceObserver <PerformanceSample>);
            List <PerformanceSample>          records        = new List <PerformanceSample>();
            List <CsvCounterRecord>           csvRecords     = new List <CsvCounterRecord>();

            // testing pdh found invalid data when using concurrently
            lock (_lockObj)
            {
                Log.Debug($"observable creating: {fileObject.FileUri}");
                observable = PerfCounterObservable.FromFile(fileObject.FileUri);

                Log.Debug($"observable created: {fileObject.FileUri}");
                counterSession = ReadTraceRecords(observable);

                Log.Debug($"finished total ms: {DateTime.Now.Subtract(startTime).TotalMilliseconds} reading: {fileObject.FileUri}");
                records = counterSession.Records;
            }

            foreach (PerformanceSample record in records)
            {
                if (!string.IsNullOrEmpty(record.Value.ToString()))
                {
                    string counterValue = record.Value.ToString() == "NaN" ? "0" : record.Value.ToString();

                    try
                    {
                        csvRecords.Add(new CsvCounterRecord()
                        {
                            Timestamp    = record.Timestamp,
                            CounterName  = record.CounterPath.Replace("\"", "").Trim(),
                            CounterValue = Decimal.Parse(counterValue, NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint),
                            Object       = record.CounterSet?.Replace("\"", "").Trim(),
                            Counter      = record.CounterName.Replace("\"", "").Trim(),
                            Instance     = record.Instance?.Replace("\"", "").Trim(),
                            NodeName     = fileObject.NodeName,
                            FileType     = fileObject.FileDataType.ToString(),
                            RelativeUri  = fileObject.RelativeUri
                        });
                    }
                    catch (Exception ex)
                    {
                        Log.Exception($"stringValue:{counterValue} exception:{ex}", record);
                    }
                }
                else
                {
                    Log.Warning($"empty counter value:", record);
                }
            }

            fileObject.Stream.Write(csvRecords);
            Log.Info($"records: {records.Count()} {csvRecords.Count}");
            return(true);
        }