package benchmarking;


import converters.JsonConverter;
import datamodel.PerformanceSelfMonitoring;
import mongo.MongoManager;

public class Monitoring {
    PerformanceMonitoring performanceMonitoring = new PerformanceMonitoring();
    long startTime = -1, endTime = -1, totalTime = -1;

    public void startMonitoring() {
        performanceMonitoring.startMonitoring();
        startTime = System.currentTimeMillis();
    }

    public void stopMonitoring() {
        performanceMonitoring.stopMonitoring();
        endTime = System.currentTimeMillis();
        totalTime = endTime - startTime;
    }

    public PerformanceSelfMonitoring getResults(long pid) {
        PerformanceSelfMonitoring perfSelf = new PerformanceSelfMonitoring();
        perfSelf.setCpuUsageResults(performanceMonitoring.parseForPid(pid));
        perfSelf.setExecutionTime(totalTime);

        return perfSelf;
    }

    public void saveResultsInDb (long pid, MongoManager mm) {
        Thread writeRestuls = new Thread(new Runnable() {
            @Override
            public void run() {
                PerformanceSelfMonitoring perfSelf = new PerformanceSelfMonitoring();
                perfSelf.setCpuUsageResults(performanceMonitoring.parseForPid(pid));
                perfSelf.setExecutionTime(totalTime);
                mm.pushJson(JsonConverter.objectToJsonString(perfSelf), "selfPerformance");            }
        });
        writeRestuls.start();
    }

}

@@ -67,16 +67,27 @@
 tamodel.
+monitoring.
 Performa
@@ -81,36 +81,32 @@
 ring.Performance
-Self
 Monitoring;%0Aimpo
@@ -99,16 +99,23 @@
 nitoring
+Results
 ;%0Aimport
@@ -618,302 +618,8 @@
  %7D%0A%0A
-    public PerformanceSelfMonitoring getResults(long pid) %7B%0A        PerformanceSelfMonitoring perfSelf = new PerformanceSelfMonitoring();%0A        perfSelf.setCpuUsageResults(performanceMonitoring.parseForPid(pid));%0A        perfSelf.setExecutionTime(totalTime);%0A%0A        return perfSelf;%0A    %7D%0A%0A
     
@@ -807,36 +807,32 @@
      Performance
-Self
 Monitoring perfS
@@ -825,25 +825,52 @@
 nitoring
- perfSelf
+Results performanceMonitoringResults
  = new P
@@ -879,20 +879,16 @@
 formance
-Self
 Monitori
@@ -881,32 +881,39 @@
 rmanceMonitoring
+Results
 ();%0A            
@@ -924,29 +924,47 @@
 perf
-Self.setCpuUsageResul
+ormanceMonitoringResults.setSubcomponen
 ts(p
@@ -1007,62 +1007,8 @@
 ));%0A
-                perfSelf.setExecutionTime(totalTime);%0A
     
@@ -1072,12 +1072,32 @@
 perf
-Self
+ormanceMonitoringResults
 ), %22
@@ -1115,11 +1115,22 @@
 ance
+Monitoring
 %22);
+%0A
     

Use PerformanceMontoringResults as a datamodel.