<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CollectN.Debug;

namespace CollectN.Plugins
{
    class MemoryPlugin : IInputPlugin
    {
        private readonly PerformanceCounter _availableBytes;

        public MemoryPlugin()
        {
            using (Profiler.Step("Memory Init"))
            {
                _availableBytes = new PerformanceCounter();
                _availableBytes.CategoryName = "memory";
                _availableBytes.CounterName = "Available MBytes";
                // Prime the counter 
                _availableBytes.NextValue();
            }
        }

        public IEnumerable<StatResult> Signal()
        {
            using (Profiler.Step("Memory Signal"))
            {
                var available = Convert.ToInt32(_availableBytes.NextValue());
                Console.WriteLine("Memory:\tAvailable MBytes\t{0}", available);

                var resultCollection = new List<StatResult>();
                resultCollection.Add(new StatResult { Key = "Memory.Available-MBytes", Value = available });

                return resultCollection;
            }
        }
    }
}<commit_msg>Refactored Memory plugin<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CollectN.Debug;

namespace CollectN.Plugins
{
    class MemoryPlugin : IInputPlugin
    {
        private readonly PerformanceCounter[] _counters;

        public MemoryPlugin()
        {
            using (Profiler.Step("Memory Init"))
            {
                var category = new PerformanceCounterCategory("Memory");

                _counters = category.GetCounters();
            }
        }

        public IEnumerable<StatResult> Signal()
        {
            using (Profiler.Step("Memory Signal"))
            {
                var resultCollection = new List<StatResult>();

                foreach (var performanceCounter in _counters)
                {
                    var value = performanceCounter.NextValue();
                    var name = ("memory" + performanceCounter.InstanceName +
                                "." + performanceCounter.CounterName.Replace("/", "-")).Replace(" ", "-").ToLower();
                    resultCollection.Add(new StatResult { Key = name, Value = (int)value });
                }

                return resultCollection;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09579897919120534, 'fraction_numerical': 0.001177856301531213, 'mean_word_length': 1.8726042841037205, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1985062', 'n_tokens_mistral': 616, 'n_tokens_neox': 587, 'n_words': 133}