<commit_before>package de.uni_hildesheim.sse.monitoring.runtime.recording;

import java.util.Timer;
import java.util.TimerTask;

import de.uni_hildesheim.sse.monitoring.runtime.boot.RecorderFrontend;
import de.uni_hildesheim.sse.monitoring.runtime.configuration.Configuration;
import de.uni_hildesheim.sse.monitoring.runtime.configuration.
    ConfigurationListener;
//import de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IFactory;
import de.uni_hildesheim.sse.monitoring.runtime.recordingStrategies.ProcessData;
import de.uni_hildesheim.sse.monitoring.runtime.recordingStrategies.
    ProcessData.Measurements;
import de.uni_hildesheim.sse.monitoring.runtime.recordingStrategies.ThreadsInfo;
import de.uni_hildesheim.sse.monitoring.runtime.utils.LongLongHashMap;
import de.uni_hildesheim.sse.system.GathererFactory;
import de.uni_hildesheim.sse.system.IMemoryDataGatherer;
import de.uni_hildesheim.sse.system.IThisProcessDataGatherer;
import de.uni_hildesheim.sse.system.IThreadDataGatherer;

/**
 * Does basic monitoring of the underlying operating system.
 * 
 * @author <NAME>
 * @since 1.00
 * @version 1.20
 */
public class SystemMonitoring {
    
    /**
     * Stores the (default) timer execution period for the load counter.
     */
    public static final long LOAD_COUNTER_PERIOD = 1000;

    /**
     * Stores the thread data gatherer.
     */
    public static final IThreadDataGatherer THREAD_DATA_GATHERER 
        = GathererFactory.getThreadDataGatherer();
    
    /**
     * Stores the memory data gatherer.
     */
    public static final IMemoryDataGatherer MEMORY_DATA_GATHERER 
        = GathererFactory.getMemoryDataGatherer();
    
    /**
     * Stores the central timer instance.
     */
    private static Timer timer;
    
    /**
     * Stores the sum of all system loads.
     */
    private static double sysLoadSum = 0;

    /**
     * Stores the local process data object used for collecting minimum and
     * maximum information.
     */
    private static ProcessData processData = ProcessData.getFromPool();
        
    /**
     * Stores the sum of all JVM loads.
     */
    private static double jvmLoadSum = 0;

    /**
     * Stores the sum of all JVM memory usages.
     */
    private static long jvmMemUseSum = 0;

    /**
     * Stores the sum of all system memory usages.
     */
    private static long sysMemUseSum = 0;
    
    /**
     * Stores the number of load ticks (probes) taken.
     */
    private static long loadTickCount = 0;
    
    /**
     * Stores the number of elapsed out interval counts.
     * Initialized to <code>-1</code> to force output
     * on first opportunity depending on {@link Configuration#getOutInterval()}.
     */
    private static int outIntervalCount = -1;
    
    /**
     * Stores the load and statistics collecting thread.
     */
    private static final LoadCounterTask LOAD_COUNTER 
        = new LoadCounterTask();

    /**
     * Stores the load and statistics collecting thread.
     */
    private static LogEventTask logEventTask = new LogEventTask();
    
    /**
     * Stores the thread timings.
     */
    //private static final Map<Long, Long> THREADS = new HashMap<Long, Long>();
    
    /**
     * Prevents instance creation from outside.
     * 
     * @since 1.00
     */
    private SystemMonitoring() {
    }
    
    /**
     * A runnable for periodically collecting measurements on the system.
     * 
     * @author <NAME>
     * @since 1.00
     * @version 1.00
     */
    private static class LoadCounterTask extends TimerTask {
        
        /**
         * Stores if this runnable should keep on running and if it was
         * started (<b>null</b> not started, <code>true</code> started and
         * running, <b>false</b> should stop).
         */
        private Boolean run = null;
        
        /**
         * {@inheritDoc}
         * 
         * @since 1.00
         */
        @Override
        public boolean cancel() {
            run = false;
            return super.cancel();
        }
        
        /**
         * Returns if it is running (better if it should not stop).
         * 
         * @return <code>true</code> if it is running, <code>false</code> if
         * it should stop or if it was stopped
         * 
         * @since 1.00
         */
        public boolean isRunning() {
            return null != run;
        }
        
        /**
         * Execute the data collection by calling {@link #collectOnce()}.
         */
        public void run() {
            run = true;
            collectOnce();
        }
        
        /**
         * Collect the data.
         * 
         * @since 1.00
         */
        public void collectOnce() {
            synchronized (processData) {
                IThisProcessDataGatherer pdg = 
                    GathererFactory.getThisProcessDataGatherer();
    
                Measurements jvm = processData.getJvm();
                Measurements sys = processData.getSystem();
                
                double load = pdg.getCurrentProcessProcessorLoad();
                jvmLoadSum += load;
                jvm.setMinMaxLoad(load);

                load = GathererFactory.getProcessorDataGatherer()
                    .getCurrentSystemLoad();
                sysLoadSum += load;
                sys.setMinMaxLoad(load);

                long memUse = pdg.getCurrentProcessMemoryUse();
                jvmMemUseSum += memUse;
                jvm.setMinMaxMemUse(memUse);
    
                memUse = GathererFactory.getMemoryDataGatherer()
                    .getCurrentMemoryUse();
                sysMemUseSum += memUse;
                sys.setMinMaxMemUse(memUse);
                
                int maxOutInterval = Configuration.INSTANCE.getOutInterval();
                // start legacy
                if (maxOutInterval > 0) {
                    outIntervalCount++;
                    ElschaLogger.info("CollectOnce with outIntervalCount = " + outIntervalCount + ", maxOutInterval = " + maxOutInterval);
                    if (outIntervalCount >= maxOutInterval) {
                       outIntervalCount = -1;  //0;
                    }
                    if (0 == outIntervalCount) {
                        RecorderFrontend.instance.printCurrentState();
                    }
                }
                // end legacy
                loadTickCount++;
                /*
                if (loadTickCount % 10 == 0) {
                    IFactory.getInstance().cleanup();
                }*/
                RecorderFrontend.instance.clearTemporaryData();
                /*
                Cleanup clean = InternalPluginRegistry.getInstrumenterCleanup();
                if (null != clean) {
                    clean.cleanupIfRequired();
                }*/
                //IFactory.getInstance().cleanupIfRequired();

            }
        }
        
    }
    <commit_msg>Reverted fix, as the location is not responsible for the bug.<commit_after>package de.uni_hildesheim.sse.monitoring.runtime.recording;

import java.util.Timer;
import java.util.TimerTask;

import de.uni_hildesheim.sse.monitoring.runtime.boot.RecorderFrontend;
import de.uni_hildesheim.sse.monitoring.runtime.configuration.Configuration;
import de.uni_hildesheim.sse.monitoring.runtime.configuration.
    ConfigurationListener;
//import de.uni_hildesheim.sse.monitoring.runtime.instrumentation.lib.IFactory;
import de.uni_hildesheim.sse.monitoring.runtime.recordingStrategies.ProcessData;
import de.uni_hildesheim.sse.monitoring.runtime.recordingStrategies.
    ProcessData.Measurements;
import de.uni_hildesheim.sse.monitoring.runtime.recordingStrategies.ThreadsInfo;
import de.uni_hildesheim.sse.monitoring.runtime.utils.LongLongHashMap;
import de.uni_hildesheim.sse.system.GathererFactory;
import de.uni_hildesheim.sse.system.IMemoryDataGatherer;
import de.uni_hildesheim.sse.system.IThisProcessDataGatherer;
import de.uni_hildesheim.sse.system.IThreadDataGatherer;

/**
 * Does basic monitoring of the underlying operating system.
 * 
 * @author <NAME>
 * @since 1.00
 * @version 1.20
 */
public class SystemMonitoring {
    
    /**
     * Stores the (default) timer execution period for the load counter.
     */
    public static final long LOAD_COUNTER_PERIOD = 1000;

    /**
     * Stores the thread data gatherer.
     */
    public static final IThreadDataGatherer THREAD_DATA_GATHERER 
        = GathererFactory.getThreadDataGatherer();
    
    /**
     * Stores the memory data gatherer.
     */
    public static final IMemoryDataGatherer MEMORY_DATA_GATHERER 
        = GathererFactory.getMemoryDataGatherer();
    
    /**
     * Stores the central timer instance.
     */
    private static Timer timer;
    
    /**
     * Stores the sum of all system loads.
     */
    private static double sysLoadSum = 0;

    /**
     * Stores the local process data object used for collecting minimum and
     * maximum information.
     */
    private static ProcessData processData = ProcessData.getFromPool();
        
    /**
     * Stores the sum of all JVM loads.
     */
    private static double jvmLoadSum = 0;

    /**
     * Stores the sum of all JVM memory usages.
     */
    private static long jvmMemUseSum = 0;

    /**
     * Stores the sum of all system memory usages.
     */
    private static long sysMemUseSum = 0;
    
    /**
     * Stores the number of load ticks (probes) taken.
     */
    private static long loadTickCount = 0;
    
    /**
     * Stores the number of elapsed out interval counts.
     * Initialized to <code>-1</code> to force output
     * on first opportunity depending on {@link Configuration#getOutInterval()}.
     */
    private static int outIntervalCount = -1;
    
    /**
     * Stores the load and statistics collecting thread.
     */
    private static final LoadCounterTask LOAD_COUNTER 
        = new LoadCounterTask();

    /**
     * Stores the load and statistics collecting thread.
     */
    private static LogEventTask logEventTask = new LogEventTask();
    
    /**
     * Stores the thread timings.
     */
    //private static final Map<Long, Long> THREADS = new HashMap<Long, Long>();
    
    /**
     * Prevents instance creation from outside.
     * 
     * @since 1.00
     */
    private SystemMonitoring() {
    }
    
    /**
     * A runnable for periodically collecting measurements on the system.
     * 
     * @author <NAME>
     * @since 1.00
     * @version 1.00
     */
    private static class LoadCounterTask extends TimerTask {
        
        /**
         * Stores if this runnable should keep on running and if it was
         * started (<b>null</b> not started, <code>true</code> started and
         * running, <b>false</b> should stop).
         */
        private Boolean run = null;
        
        /**
         * {@inheritDoc}
         * 
         * @since 1.00
         */
        @Override
        public boolean cancel() {
            run = false;
            return super.cancel();
        }
        
        /**
         * Returns if it is running (better if it should not stop).
         * 
         * @return <code>true</code> if it is running, <code>false</code> if
         * it should stop or if it was stopped
         * 
         * @since 1.00
         */
        public boolean isRunning() {
            return null != run;
        }
        
        /**
         * Execute the data collection by calling {@link #collectOnce()}.
         */
        public void run() {
            run = true;
            collectOnce();
        }
        
        /**
         * Collect the data.
         * 
         * @since 1.00
         */
        public void collectOnce() {
            synchronized (processData) {
                IThisProcessDataGatherer pdg = 
                    GathererFactory.getThisProcessDataGatherer();
    
                Measurements jvm = processData.getJvm();
                Measurements sys = processData.getSystem();
                
                double load = pdg.getCurrentProcessProcessorLoad();
                jvmLoadSum += load;
                jvm.setMinMaxLoad(load);

                load = GathererFactory.getProcessorDataGatherer()
                    .getCurrentSystemLoad();
                sysLoadSum += load;
                sys.setMinMaxLoad(load);

                long memUse = pdg.getCurrentProcessMemoryUse();
                jvmMemUseSum += memUse;
                jvm.setMinMaxMemUse(memUse);
    
                memUse = GathererFactory.getMemoryDataGatherer()
                    .getCurrentMemoryUse();
                sysMemUseSum += memUse;
                sys.setMinMaxMemUse(memUse);
                
                int maxOutInterval = Configuration.INSTANCE.getOutInterval();
                // start legacy
                if (maxOutInterval > 0) {
                    outIntervalCount++;
                    ElschaLogger.info("CollectOnce with outIntervalCount = " + outIntervalCount + ", maxOutInterval = " + maxOutInterval);
                    if (outIntervalCount >= maxOutInterval) {
                        outIntervalCount = 0;
                    }
                    if (0 == outIntervalCount) {
                        RecorderFrontend.instance.printCurrentState();
                    }
                }
                // end legacy
                loadTickCount++;
                /*
                if (loadTickCount % 10 == 0) {
                    IFactory.getInstance().cleanup();
                }*/
                RecorderFrontend.instance.clearTemporaryData();
                /*
                Cleanup clean = InternalPluginRegistry.getInstrumenterCleanup();
                if (null != clean) {
                    clean.cleanupIfRequired();
                }*/
                //IFactory.getInstance().cleanupIfRequired();

            }
        }
        
    }
    
{'fraction_non_alphanumeric': 0.08986340762041696, 'fraction_numerical': 0.005966930265995687, 'mean_word_length': 1.7601190476190476, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 39, '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': '5715705', 'n_tokens_mistral': 3916, 'n_tokens_neox': 3740, 'n_words': 899}