Search in sources :

Example 1 with InvalidMapException

use of es.bsc.compss.nio.worker.exceptions.InvalidMapException in project compss by bsc-wdc.

the class BindToMap method getLsCpuOutput.

private static String getLsCpuOutput() throws InvalidMapException {
    // **************************************************************************************
    // Get LSCPU output
    // **************************************************************************************
    String cmdOutput = null;
    ProcessBuilder pb = new ProcessBuilder("lscpu");
    try {
        pb.environment().remove(Tracer.LD_PRELOAD);
        Process process = pb.start();
        // Disable inputs to process
        process.getOutputStream().close();
        // Wait and retrieve exit value
        int exitValue = process.waitFor();
        if (exitValue != 0) {
            throw new InvalidMapException("ERROR: LSCPU command failed with exitValue " + exitValue);
        }
        // Retrieve command output
        StringBuilder sb = new StringBuilder();
        try (BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
            String line = null;
            while ((line = br.readLine()) != null) {
                sb.append(line).append("\n");
            }
        } catch (IOException ioe) {
            throw new InvalidMapException("ERROR: Cannot retrieve LSCPU command output", ioe);
        }
        cmdOutput = sb.toString();
    } catch (IOException ioe) {
        throw new InvalidMapException("ERROR: Cannot start LSCPU ProcessBuilder", ioe);
    } catch (InterruptedException ie) {
        throw new InvalidMapException("ERROR: LSCPU command interrupted", ie);
    }
    return cmdOutput;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) InvalidMapException(es.bsc.compss.nio.worker.exceptions.InvalidMapException)

Aggregations

InvalidMapException (es.bsc.compss.nio.worker.exceptions.InvalidMapException)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1