public PerProcessPipPerformanceInformationStoreTests(ITestOutputHelper output)
            : base(output)
        {
            m_context       = BuildXLContext.CreateInstanceForTesting();
            m_configuration = ConfigurationHelpers.GetDefaultForTesting(m_context.PathTable, AbsolutePath.Create(m_context.PathTable, Path.Combine(TemporaryDirectory, "config.ds")));

            m_perPipPerformanceInformationStore = new PerProcessPipPerformanceInformationStore(m_configuration.Logging.MaxNumPipTelemetryBatches, m_configuration.Logging.AriaIndividualMessageSizeLimitBytes);
        }
        public void TestMultipleBatchOfPipPerformanceInformation()
        {
            m_configuration.Logging.MaxNumPipTelemetryBatches = 4;
            m_perPipPerformanceInformationStore = new PerProcessPipPerformanceInformationStore(m_configuration.Logging.MaxNumPipTelemetryBatches, m_configuration.Logging.AriaIndividualMessageSizeLimitBytes);
            AddMultiplePips(200000);
            var resp = m_perPipPerformanceInformationStore.GenerateTopPipPerformanceInfoJsonArray();

            Assert.Equal(4, resp.Length);
            VerifyMultiplePips(AssertMessageSizesAndParseJsonArray(resp));
        }
        public void TestZeroCapacityPerPipPerformanceInformation()
        {
            var perPipPerformanceInformationStore = new PerProcessPipPerformanceInformationStore(0, m_configuration.Logging.AriaIndividualMessageSizeLimitBytes);

            perPipPerformanceInformationStore.AddPip(CreateSamplePip(1));
            var resp = m_perPipPerformanceInformationStore.GenerateTopPipPerformanceInfoJsonArray();

            Assert.Equal(0, resp.Length);
            var perfArr = AssertMessageSizesAndParseJsonArray(resp);

            Assert.Equal(0, perfArr.Length);
        }
        private void VerifyMultiplePips(string[] arr)
        {
            for (var i = 0; i < arr.Length; i++)
            {
                var jsonObj = JsonConvert.DeserializeObject <PerProcessPipPerformanceInformation>(arr[i]);
                int index   = jsonObj.IOReadMb;
                ProcessRunnablePip runnablePip = (ProcessRunnablePip)m_runnablePips[index];
                PerProcessPipPerformanceInformation pipInfo = GeneratePipInfoWithRunnablePipAndIndex(ref runnablePip, index);

                Assert.Equal(PerProcessPipPerformanceInformationStore.SerializePipPerfInfo(pipInfo), arr[i]);
            }
        }
        public void TestLargeDescPipBetweenRegularPipPerformanceInformation()
        {
            m_configuration.Logging.AriaIndividualMessageSizeLimitBytes = s_individualPipInfoStringLength * 2;
            m_configuration.Logging.MaxNumPipTelemetryBatches           = 10;
            m_perPipPerformanceInformationStore = new PerProcessPipPerformanceInformationStore(m_configuration.Logging.MaxNumPipTelemetryBatches, m_configuration.Logging.AriaIndividualMessageSizeLimitBytes);
            AddMultiplePips(1);
            m_perPipPerformanceInformationStore.AddPip(new PerProcessPipPerformanceInformation($"Pip LARGE Desc: {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix}", 8000, 8000, 8000, 8000));
            AddMultiplePips(10, 2);
            m_perPipPerformanceInformationStore.AddPip(new PerProcessPipPerformanceInformation($"Pip LARGE Desc: {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix}", 9000, 9000, 9000, 9000));
            AddMultiplePips(20, 11);
            m_perPipPerformanceInformationStore.AddPip(new PerProcessPipPerformanceInformation($"Pip LARGE Desc: {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix} {LargeDesciptionsSuffix}", 7000, 7000, 7000, 7000));
            var resp = m_perPipPerformanceInformationStore.GenerateTopPipPerformanceInfoJsonArray();

            Assert.Equal(10, resp.Length);
            VerifyMultiplePips(AssertMessageSizesAndParseJsonArray(resp), 20);
        }
        public PerProcessPipPerformanceInformationStoreTests(ITestOutputHelper output)
            : base(output)
        {
            m_context        = BuildXLContext.CreateInstanceForTesting();
            m_loggingContext = CreateLoggingContextForTest();
            m_configuration  = ConfigurationHelpers.GetDefaultForTesting(m_context.PathTable, AbsolutePath.Create(m_context.PathTable, Path.Combine(TemporaryDirectory, "config.ds")));
            m_perPipPerformanceInformationStore = new PerProcessPipPerformanceInformationStore(MaxNumPipTelemetryBatches, m_configuration.Logging.AriaIndividualMessageSizeLimitBytes);
            m_runnablePips = new Hashtable();

            var pipTable = new PipTable(
                m_context.PathTable,
                m_context.SymbolTable,
                initialBufferSize: 1024,
                maxDegreeOfParallelism: (Environment.ProcessorCount + 2) / 3,
                debug: false);

            m_executionEnvironment = new DummyPipExecutionEnvironment(m_loggingContext, m_context, m_configuration, pipTable: pipTable);

            m_individualPipInfoStringLength = PerProcessPipPerformanceInformationStore.SerializePipPerfInfo(CreateSamplePip(0)).Length;
        }