コード例 #1
0
        public ICollectorSet Create()
        {
            // Data collector set is the core abstraction for collecting diagnostic data.
            DataCollectorSet dcs = new DataCollectorSet();

            // Set base folder to place output files.
            dcs.RootPath = this.OutputPath;

            // Create a data collector for perf counters.
            IPerformanceCounterDataCollector dc = (IPerformanceCounterDataCollector)dcs.DataCollectors.CreateDataCollector(DataCollectorType.plaPerformanceCounter);

            dc.name = this.Name + "_DC";
            dcs.DataCollectors.Add(dc);

            // Set output file name to use a pattern, as described at
            // http://msdn.microsoft.com/en-us/library/windows/desktop/aa372131(v=vs.85).aspx .
            dc.FileName              = this.Name;
            dc.FileNameFormat        = AutoPathFormat.plaPattern;
            dc.FileNameFormatPattern = @"\-yyyyMMdd\-HHmmss";

            // Set sample interval, if present.
            if (this.SampleInterval.HasValue)
            {
                dc.SampleInterval = (uint)this.SampleInterval.Value.TotalSeconds;
            }

            // Set log file format, if present.
            if (this.LogFileFormat.HasValue)
            {
                dc.LogFileFormat = (FileFormat)this.LogFileFormat.Value;
            }

            // Build up the list of performance counters.
            string[] counterNames = new string[this.CounterNames.Count];
            for (int i = 0; i < this.CounterNames.Count; ++i)
            {
                counterNames[i] = this.CounterNames[i].ToString();
            }

            dc.PerformanceCounters = counterNames;

            // Now actually create (or modify existing) the set.
            dcs.Commit(this.Name, null, CommitMode.plaCreateOrModify);

            // Return an opaque wrapper with which the user can control the session.
            return(new CollectorSetWrapper(dcs));
        }
コード例 #2
0
        private DataCollectorSet ConstructDataCollectorSet()
        {
            if (string.IsNullOrEmpty(this.performanceLogXmlFile))
            {
                throw new ArgumentException("performanceLogXmlFile");
            }
            if (!File.Exists(this.performanceLogXmlFile))
            {
                throw new ArgumentException(string.Format("PerformanceLogXmlFile {0} does not exist", this.performanceLogXmlFile));
            }
            string xml = File.ReadAllText(this.performanceLogXmlFile);

            if (PerformanceLogSet.twentyFourHours < this.sampleInterval)
            {
                throw new ArgumentOutOfRangeException("sampleInterval", string.Format("Must be less than or equal to {0} hours", PerformanceLogSet.twentyFourHours.ToString()));
            }
            if (PerformanceLogSet.twentyFourHours < this.maximumDuration)
            {
                throw new ArgumentOutOfRangeException("maximumDuration", string.Format("Must be less than or equal to {0} hours", PerformanceLogSet.twentyFourHours.ToString()));
            }
            DataCollectorSet dataCollectorSet = new DataCollectorSetClass();

            dataCollectorSet.SetXml(xml);
            dataCollectorSet.Security = null;
            IDataCollectorCollection dataCollectors = dataCollectorSet.DataCollectors;

            if (1 != dataCollectors.Count || dataCollectors[0].DataCollectorType != null)
            {
                throw new ArgumentException("performanceLogXmlFile is invalid. It must contain only 1 data collected of type Performance Counter");
            }
            IPerformanceCounterDataCollector performanceCounterDataCollector = (IPerformanceCounterDataCollector)dataCollectors[0];

            if (this.counterSetName == null)
            {
                throw new ArgumentNullException("counterSetName");
            }
            dataCollectorSet.DisplayName             = this.counterSetName;
            performanceCounterDataCollector.FileName = this.counterSetName;
            if (this.performanceLogPath != null)
            {
                dataCollectorSet.RootPath = this.performanceLogPath;
            }
            if (this.logFormat != null)
            {
                performanceCounterDataCollector.LogFileFormat = this.logFormat.Value;
            }
            if (this.fileNameFormat != null)
            {
                performanceCounterDataCollector.FileNameFormat = this.fileNameFormat.Value;
            }
            if (0.0 != this.maximumDuration.TotalSeconds)
            {
                dataCollectorSet.SegmentMaxDuration = (uint)this.maximumDuration.TotalSeconds;
            }
            if (0.0 != this.sampleInterval.TotalSeconds)
            {
                performanceCounterDataCollector.SampleInterval = (uint)this.sampleInterval.TotalSeconds;
            }
            dataCollectorSet.Commit(this.counterSetName, null, 4096);
            return(dataCollectorSet);
        }