<commit_before>var childProcess = require('child_process');
var spawn = childProcess.spawn;
var fs = require('fs');

var scriptsDir = './scripts';

var services = {};
var childProcesses = {};
var debugServerChild = null;

var ServiceManager = {
  listProcesses: function() {
    return services;
  },
  createScript: function(scriptName, fileContent, cb) {
    if (!fs.existsSync(scriptsDir)){
      fs.mkdirSync(scriptsDir);
    }

    fs.writeFile(scriptsDir + "/" + scriptName, fileContent, function(err) {
      if (err) {
        return console.error(err);
      }

      if (cb) {
        cb();
      }
    });
  },
  spawnProcess: function(scriptName) {
    console.log("spawn the shell");
    var scriptPath = scriptsDir + "/" + scriptName;
    var logFile = scriptPath + ".out";
    var child = spawn("node", ["--debug", scriptPath], {
      detached: true
    });

    child.stdout.on('data', function (data) {
      fs.appendFile(logFile, data.toString(), function (err) {
        if (err) throw err;
      });
      console.log(child.pid, data.toString());
    });

    child.stderr.on('data', function (data) {
      fs.appendFile(logFile, data.toString(), function (err) {
        if (err) throw err;
      });
      console.log(child.pid, data.toString());
    });

    child.on('close', function(exit_code) {
      console.log('Closed before stop: Closing code: ', exit_code);
    });
    childProcesses[child.pid] = child;
    services[child.pid] = {
      name: scriptName,
      status: 1
    };
    return child.pid;
  },
  killProcess: function(pid) {
    var child = childProcesses[pid];
    if (child) {
      console.log("kill process");
      child.kill('SIGKILL');
      if (pid in services) {
        services[pid].status = 0;
      }
    }
  },
  startDebugServer: function() {
    if (debugServerChild) {
      console.log("Debug server was already started.");
      return;
    }
    console.log("run inspectorPath");
    var inspectorPath = "./node_modules/node-inspector/bin/inspector.js";
    debugServerChild = spawn("node", [inspectorPath, "--debug-port", "9008"]);
    var child = debugServerChild;
    child.stdout.on('data', function (data) {
      console.log(child.pid, data.toString());
    });

    child.stderr.on('data', function (data) {
      console.log(child.pid, data.toString());
    });

    child.on('close', function(exit_code) {
      console.log('Closed before stop: Closing code: ', exit_code);
    });
  },
  shutdownDebugServer: function() {
    if (debugServerChild) {
      console.log("kill debug server");
      debugServerChild.kill('SIGKILL');
      debugServerChild = null;
    }
  }
};

module.exports = ServiceManager;<commit_msg>Add start/kill time<commit_after>var childProcess = require('child_process');
var spawn = childProcess.spawn;
var fs = require('fs');

var scriptsDir = './scripts';

var services = {};
var childProcesses = {};
var debugServerChild = null;

var ServiceManager = {
  listProcesses: function() {
    return services;
  },
  createScript: function(scriptName, fileContent, cb) {
    if (!fs.existsSync(scriptsDir)){
      fs.mkdirSync(scriptsDir);
    }

    fs.writeFile(scriptsDir + "/" + scriptName, fileContent, function(err) {
      if (err) {
        return console.error(err);
      }

      if (cb) {
        cb();
      }
    });
  },
  spawnProcess: function(scriptName) {
    console.log("spawn the shell");
    var scriptPath = scriptsDir + "/" + scriptName;
    var logFile = scriptPath + ".out";
    var child = spawn("node", ["--debug", scriptPath], {
      detached: true
    });

    child.stdout.on('data', function (data) {
      fs.appendFile(logFile, data.toString(), function (err) {
        if (err) throw err;
      });
      console.log(child.pid, data.toString());
    });

    child.stderr.on('data', function (data) {
      fs.appendFile(logFile, data.toString(), function (err) {
        if (err) throw err;
      });
      console.log(child.pid, data.toString());
    });

    child.on('close', function(exit_code) {
      console.log('Closed before stop: Closing code: ', exit_code);
    });
    childProcesses[child.pid] = child;
    services[child.pid] = {
      name: scriptName,
      status: 1,
      start: new Date().getTime(),
      kill: -1
    };
    return child.pid;
  },
  killProcess: function(pid) {
    var child = childProcesses[pid];
    if (child) {
      console.log("kill process");
      child.kill('SIGKILL');
      if (pid in services) {
        services[pid].status = 0;
        services[pid].kill = new Date().getTime();
      }
    }
  },
  startDebugServer: function() {
    if (debugServerChild) {
      console.log("Debug server was already started.");
      return;
    }
    console.log("run inspectorPath");
    var inspectorPath = "./node_modules/node-inspector/bin/inspector.js";
    debugServerChild = spawn("node", [inspectorPath, "--debug-port", "9008"]);
    var child = debugServerChild;
    child.stdout.on('data', function (data) {
      console.log(child.pid, data.toString());
    });

    child.stderr.on('data', function (data) {
      console.log(child.pid, data.toString());
    });

    child.on('close', function(exit_code) {
      console.log('Closed before stop: Closing code: ', exit_code);
    });
  },
  shutdownDebugServer: function() {
    if (debugServerChild) {
      console.log("kill debug server");
      debugServerChild.kill('SIGKILL');
      debugServerChild = null;
    }
  }
};

module.exports = ServiceManager;
{'fraction_non_alphanumeric': 0.15903307888040713, 'fraction_numerical': 0.002362777171937477, 'mean_word_length': 2.8188757807078417, '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': '3555476', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1694, 'n_words': 359}