<commit_before>package kg.apc.perfmon.metrics;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
import org.hyperic.sigar.SigarException;

/**
 *
 * @author undera
 */
class ExecMetric extends AbstractPerfMonMetric {

    private static final Logger log = LoggingManager.getLoggerForClass();
    private String[] command;

    public ExecMetric(MetricParams params) {
        super(null);
        if (params.params.length == 0) {
            throw new IllegalArgumentException("Params cannot be null");
        }

        command = params.params;
    }

    public void getValue(StringBuffer res) throws SigarException {
        log.debug("Executing custom script: " + MetricParamsSigar.join(null, command, " "));

        try {
            Process p = Runtime.getRuntime().exec(command);

            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

            BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
            String e;
            while ((e = stdErr.readLine()) != null) {
                log.error("Error: " + e);
            }

            // read the output from the command
            String s, lastStr = "";
            while ((s = stdInput.readLine()) != null) {
                log.debug("Read proc out line: " + s);
                lastStr = s;
            }
            res.append(lastStr);<commit_msg>Fixed issue 125<commit_after>package kg.apc.perfmon.metrics;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
import org.hyperic.sigar.SigarException;

/**
 *
 * @author undera
 */
class ExecMetric extends AbstractPerfMonMetric {

    private static final Logger log = LoggingManager.getLoggerForClass();
    private String[] command;

    public ExecMetric(MetricParams params) {
        super(null);
        if (params.params.length == 0) {
            throw new IllegalArgumentException("Params cannot be null");
        }

        command = params.params;
    }

    public void getValue(StringBuffer res) throws SigarException {
        log.debug("Executing custom script: " + MetricParamsSigar.join(null, command, " "));

        try {
            Process p = Runtime.getRuntime().exec(command);

            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

            BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
            String e;
            while ((e = stdErr.readLine()) != null) {
                log.error("Error: " + e);
            }

            // read the output from the command
            String s, lastStr = "";
            while ((s = stdInput.readLine()) != null) {
                log.debug("Read proc out line: " + s);
                lastStr = s;
            }
            res.append(lastStr);
            
            stdErr.close();
            stdInput.close();
            p.destroy();
{'fraction_non_alphanumeric': 0.11019632678910703, 'fraction_numerical': 0.0015832805573147563, 'mean_word_length': 2.3322784810126582, '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': '7142946', 'n_tokens_mistral': 864, 'n_tokens_neox': 832, 'n_words': 202}