<commit_before>// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections;
using System.Collections.Specialized;
using Xunit;

namespace System.Diagnostics.Tests
{
    [SkipOnTargetFramework(TargetFrameworkMonikers.Uap)] // In appcontainer, cannot write to perf counters
    public static class PerformanceCounterTests
    {
        [ConditionalFact(typeof(AdminHelpers), nameof(AdminHelpers.IsProcessElevated))]
        public static void PerformanceCounterCategory_CreateCategory()
        {
            if ( !PerformanceCounterCategory.Exists("AverageCounter64SampleCategory") ) 
            {
                CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();

                // Add the counter.
                CounterCreationData averageCount64 = new CounterCreationData();
                averageCount64.CounterType = PerformanceCounterType.AverageCount64;
                averageCount64.CounterName = "AverageCounter64Sample";
                counterDataCollection.Add(averageCount64);

                // Add the base counter.
                CounterCreationData averageCount64Base = new CounterCreationData();
                averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
                averageCount64Base.CounterName = "AverageCounter64SampleBase";
                counterDataCollection.Add(averageCount64Base);

                // Create the category.
                PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
                    "Demonstrates usage of the AverageCounter64 performance counter type.",
                    PerformanceCounterCategoryType.SingleInstance, counterDataCollection);
            }

            Assert.True(PerformanceCounterCategory.Exists("AverageCounter64SampleCategory"));
        }

        [ConditionalFact(typeof(AdminHelpers), nameof(AdminHelpers.IsProcessElevated))]
        public static void PerformanceCounter_CreateCounter_Count0()
        {
            PerformanceCounter averageCounter64Sample = new PerformanceCounter("AverageCounter64SampleCategory", 
                "AverageCounter64Sample", false);

            averageCounter64Sample.RawValue = 0;

            Assert.Equal(0, averageCounter64Sample.RawValue);
        }
    }
}<commit_msg>update the CreateCounter test to use custom counter<commit_after>// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections;
using System.Collections.Specialized;
using Xunit;

namespace System.Diagnostics.Tests
{
    [SkipOnTargetFramework(TargetFrameworkMonikers.Uap)] // In appcontainer, cannot write to perf counters
    public static class PerformanceCounterTests
    {
        [ConditionalFact(typeof(AdminHelpers), nameof(AdminHelpers.IsProcessElevated))]
        public static void PerformanceCounterCategory_CreateCategory()
        {
            if ( !PerformanceCounterCategory.Exists("AverageCounter64SampleCategory") ) 
            {
                CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();

                // Add the counter.
                CounterCreationData averageCount64 = new CounterCreationData();
                averageCount64.CounterType = PerformanceCounterType.AverageCount64;
                averageCount64.CounterName = "AverageCounter64Sample";
                counterDataCollection.Add(averageCount64);

                // Add the base counter.
                CounterCreationData averageCount64Base = new CounterCreationData();
                averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
                averageCount64Base.CounterName = "AverageCounter64SampleBase";
                counterDataCollection.Add(averageCount64Base);

                // Create the category.
                PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
                    "Demonstrates usage of the AverageCounter64 performance counter type.",
                    PerformanceCounterCategoryType.SingleInstance, counterDataCollection);
            }

            Assert.True(PerformanceCounterCategory.Exists("AverageCounter64SampleCategory"));
        }

        [ConditionalFact(typeof(AdminHelpers), nameof(AdminHelpers.IsProcessElevated))]
        public static void PerformanceCounter_CreateCounter_Count0()
        {
            var name = Guid.NewGuid().ToString("N") + "_Counter";
            var category = name + "_Category";
            if ( !PerformanceCounterCategory.Exists(category) ) 
            {
                CounterCreationDataCollection counterDataCollection = new CounterCreationDataCollection();

                // Add the counter.
                CounterCreationData counter = new CounterCreationData();
                counter.CounterType = PerformanceCounterType.AverageCount64;
                counter.CounterName = name;
                counterDataCollection.Add(counter);

                // Add the base counter.
                CounterCreationData counterBase = new CounterCreationData();
                counterBase.CounterType = PerformanceCounterType.AverageBase;
                counterBase.CounterName = name + "Base";
                counterDataCollection.Add(counterBase);

                // Create the category.
                PerformanceCounterCategory.Create(category,
                    "description",
                    PerformanceCounterCategoryType.SingleInstance, counterDataCollection);
            }

            PerformanceCounter counterSample = new PerformanceCounter(category, 
                name, false);

            counterSample.RawValue = 0;

            Assert.Equal(0, counterSample.RawValue);
        }
    }
}
{'fraction_non_alphanumeric': 0.0661485033901108, 'fraction_numerical': 0.012898958161071606, 'mean_word_length': 2.5978584176085664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6543307', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1250, 'n_words': 304}