<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace DevelopersCommunity.PerformanceCounters
{
    public class PCReader : IEnumerable<IReadOnlyList<PCItem>>
    {
        private string fileName;
        private string[] counters;
        private DateTime? start;
        private DateTime? end;

        public PCReader(string fileName, IEnumerable<string> counters, bool expandCounter) : this(fileName, counters, expandCounter, null, null)
        {

        }

        public PCReader(string fileName, IEnumerable<string> counters, bool expandCounter, DateTime? start, DateTime? end)
        {
            if (end <= start)
            {
                throw new ArgumentException("End time <= start time", nameof(end));
            }
            this.fileName = fileName;
            this.start = start;
            this.end = end;

            if (expandCounter)
            {
                List<string> expandedCounters = new List<string>();
                foreach (string wildCard in counters)
                {
                    expandedCounters.AddRange(NativeUtil.ExpandWildCard(fileName, wildCard));
                }
                this.counters = expandedCounters.ToArray();
            }
            else
            {
                this.counters = counters.ToArray();
            }
        }

        public IReadOnlyList<string> GetMachines()
        {
            uint len = 0;
            uint status = NativeMethods.PdhEnumMachines(fileName, null, ref len);
            char[] computers = null;
            if (status == NativeMethods.PDH_MORE_DATA)
            {
                computers = new char[len];
                NativeUtil.CheckPdhStatus(NativeMethods.PdhEnumMachines(fileName, computers, ref len));
            }

            return NativeUtil.MultipleStringsToList(computers);
        }

        public static IEnumerable<string> ExpandWildCard(string fileName, string wildCard)
        {
            return NativeUtil.ExpandWildCard(fileName, wildCard);
        }

        //TODO se for possivel tirar o unsafe, tirar tb a flag do projeto
        public unsafe static IEnumerable<string> BrowseCounters(string fileName)
        {
            NativeMethods.PDH_BROWSE_DLG_CONFIG config = new NativeMethods.PDH_BROWSE_DLG_CONFIG();

            config.Flags |= NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.WildCardInstances
                | NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.IncludeInstanceIndex
                | NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.HideDetailBox
                | NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.DisableMachineSelection
                | NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.IncludeCostlyObjects
                | NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.SingleCounterPerAdd
                | NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.SingleCounterPerDialog
                ;
            config.DataSource = fileName;
            //config.DialogBoxCaption = "Teste 123";
            config.DefaultDetailLevel = 400;//TODO validar

            const int bufferSize = 10000;<commit_msg>Allows to select more than one counter<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace DevelopersCommunity.PerformanceCounters
{
    public class PCReader : IEnumerable<IReadOnlyList<PCItem>>
    {
        private string fileName;
        private string[] counters;
        private DateTime? start;
        private DateTime? end;

        public PCReader(string fileName, IEnumerable<string> counters, bool expandCounter) : this(fileName, counters, expandCounter, null, null)
        {

        }

        public PCReader(string fileName, IEnumerable<string> counters, bool expandCounter, DateTime? start, DateTime? end)
        {
            if (end <= start)
            {
                throw new ArgumentException("End time <= start time", nameof(end));
            }
            this.fileName = fileName;
            this.start = start;
            this.end = end;

            if (expandCounter)
            {
                List<string> expandedCounters = new List<string>();
                foreach (string wildCard in counters)
                {
                    expandedCounters.AddRange(NativeUtil.ExpandWildCard(fileName, wildCard));
                }
                this.counters = expandedCounters.ToArray();
            }
            else
            {
                this.counters = counters.ToArray();
            }
        }

        public IReadOnlyList<string> GetMachines()
        {
            uint len = 0;
            uint status = NativeMethods.PdhEnumMachines(fileName, null, ref len);
            char[] computers = null;
            if (status == NativeMethods.PDH_MORE_DATA)
            {
                computers = new char[len];
                NativeUtil.CheckPdhStatus(NativeMethods.PdhEnumMachines(fileName, computers, ref len));
            }

            return NativeUtil.MultipleStringsToList(computers);
        }

        public static IEnumerable<string> ExpandWildCard(string fileName, string wildCard)
        {
            return NativeUtil.ExpandWildCard(fileName, wildCard);
        }

        //TODO se for possivel tirar o unsafe, tirar tb a flag do projeto
        public unsafe static IEnumerable<string> BrowseCounters(string fileName)
        {
            NativeMethods.PDH_BROWSE_DLG_CONFIG config = new NativeMethods.PDH_BROWSE_DLG_CONFIG();

            config.Flags |= NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.WildCardInstances
                | NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.IncludeInstanceIndex
                | NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.HideDetailBox
                | NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.DisableMachineSelection
                | NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.IncludeCostlyObjects
                //| NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.SingleCounterPerAdd
                | NativeMethods.PDH_BROWSE_DLG_CONFIG_Flags.SingleCounterPerDialog
                ;
            config.DataSource = fileName;
            //config.DialogBoxCaption = "Teste 123";
            config.DefaultDetailLevel = 400;//TODO validar

            const int bufferSize = 10000;
{'fraction_non_alphanumeric': 0.07295401402961808, 'fraction_numerical': 0.0037412314886983633, 'mean_word_length': 2.122141119221411, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2746342', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1651, 'n_words': 339}