@@ -0,0 +1,2974 @@
+package benchmarking;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.lang.reflect.Field;%0Aimport java.util.Date;%0A%0Apublic class CpuMonitor %7B%0A    private boolean continueMonitoring = true;%0A    private StringBuilder commandOutput;%0A    private Date date;%0A%0A    public void startMonitoring()%7B%0A        boolean firstAppearance = true;%0A%0A        Thread cpuMonit = new Thread(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                String line;%0A                Process process;%0A                commandOutput = new StringBuilder();%0A%0A                String processPid = getPid();%0A                String%5B%5D cmd = %7B%0A                        %22/bin/sh%22,%0A                        %22-c%22,%0A                        %22 atop 1 -a %7C unbuffer -p awk '/%22 + processPid + %22%7Cnmap/ %7Bprint $1 %5C%22 %5C%22 $11%7D'%22%0A                %7D;%0A%0A                try %7B%0A                    process = Runtime.getRuntime().exec(cmd);%0A                    Field pid = process.getClass().getDeclaredField(%22pid%22);%0A                    pid.setAccessible(true);%0A                    BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));%0A%0A                    while ( continueMonitoring && (line = br.readLine()) != null) %7B%0A                        if (firstAppearance  && line.contains(processPid)) %7B%0A                            date = new Date();%0A                        %7D%0A                        commandOutput.append(line + %22%5Cn%22);%0A                    %7D%0A                    process.destroy();%0A                %7D catch (IOException e) %7B%0A                    System.err.println(e.getStackTrace());%0A                %7D catch (NoSuchFieldException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A%0A                //System.out.println(%22Command output: %22 + commandOutput.toString());%0A            %7D%0A        %7D);%0A        cpuMonit.start();%0A    %7D%0A%0A    public String parseForPid(long pid) %7B%0A        stopMonitoring();%0A        String cmdOut = commandOutput.toString();%0A        StringBuilder parsedResultsAfterPid = new StringBuilder();%0A%0A        String%5B%5D outputLines = cmdOut.split(System.getProperty(%22line.separator%22));%0A        for (String line : outputLines) %7B%0A            String%5B%5D processData = line.split(%22 %22);%0A            try %7B%0A                long resultsPid = Long.parseLong(processData%5B0%5D);%0A                String cpuUsage = processData%5B1%5D;%0A                if (resultsPid == pid) %7B%0A                    parsedResultsAfterPid.append(resultsPid + %22,%22 + cpuUsage + %22%5Cn%22);%0A                %7D%0A            %7D catch (NumberFormatException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D%0A%0A        return parsedResultsAfterPid.toString();%0A    %7D%0A%0A    private static String getPid() %7B%0A        String processName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName();%0A        return processName.split(%22@%22)%5B0%5D;%0A    %7D%0A%0A    public void stopMonitoring() %7B%0A        continueMonitoring = false;%0A    %7D%0A%7D%0A

Add monitoring class for CPU usage.