public PerformanceCountersPartConfig(PerformanceCountersPartConfig other, string newPartID = null)
 {
     PartID = newPartID.MapNullOrEmptyTo(other.PartID);
     PerformanceCounterGroupsFileIndexUserRowFlagBits = other.PerformanceCounterGroupsFileIndexUserRowFlagBits;
     SampleInterval = other.SampleInterval;
     PerformanceCounterSpecArray = (other.PerformanceCounterSpecArray ?? emptyPCSpecArray).Select(pcs => new PerformanceCounterSpec(pcs)).ToArray();
 }
        public PerformanceCountersPart(PerformanceCountersPartConfig config, PartsLib.Tools.MDRF.Writer.IMDRFWriter mdrfWriter)
            : base(config.PartID, initialSettings: SimpleActivePartBaseSettings.DefaultVersion0.Build(waitTimeLimit: (0.10).FromSeconds(), goOnlineAndOfflineHandling: GoOnlineAndGoOfflineHandling.All))
        {
            Config          = new PerformanceCountersPartConfig(config);
            this.mdrfWriter = mdrfWriter;

            // we trigger acquiring a new sample two times a second
            sampleIntervalTimer = new QpcTimer()
            {
                TriggerInterval = Config.SampleInterval, AutoReset = true
            }.Start();

            performanceCounterTrackerArray = Config.PerformanceCounterSpecArray.Select(pcs => new PerformanceCounterTracker(Log, pcs)).ToArray();

            pccTupleArray = performanceCounterTrackerArray.GroupBy(pct => pct.pcc, (pcc, pctSet) => Tuple.Create(pcc, pctSet.ToArray())).ToArray();

            groupInfo = new MDRF.Writer.GroupInfo()
            {
                Name = "{0}.Grp".CheckedFormat(PartID),
                GroupBehaviorOptions     = MDRF.Writer.GroupBehaviorOptions.UseVCHasBeenSetForTouched | MDRF.Writer.GroupBehaviorOptions.IncrSeqNumOnTouched,
                FileIndexUserRowFlagBits = (ulong)Config.PerformanceCounterGroupsFileIndexUserRowFlagBits,
                GroupPointInfoArray      = performanceCounterTrackerArray.Select(pct => pct.gpInfo).ToArray(),
            };

            mdrfWriter.Add(groupInfo);

            noMDRFLogger = new Logging.Logger(PartID).SetDefaultNamedValueSetForEmitter(Logging.LogGate.All, new NamedValueSet()
            {
                { "noMDRF" }
            });
        }