-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMetricsCalculator.txt
118 lines (99 loc) · 3.24 KB
/
MetricsCalculator.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package org.bangash.metricsCalculator;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class MetricsCalculator {
static String folderPath = "C:\\Users\\HP\\Desktop\\Hareem\\BeheExplorer\\";
static String testcaseFolderName = "version9\\";
public static void main(String[] args) {
final File folder = new File(folderPath + testcaseFolderName);
listFilesForFolder(folder); //own function
}
public static void listFilesForFolder(final File folder) {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listFilesForFolder(fileEntry);
} else {
System.out.println(fileEntry.getName());
readLogFiles(folderPath + testcaseFolderName + fileEntry.getName());
System.out.println("===================================");
}
}
}
public static void readLogFiles(String path) {
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(
new FileReader(path));
boolean flag = false;
String associatedId = "";
ArrayList<Float> powerConsumptions = new ArrayList<Float>(0);
float totalTime;
while ((sCurrentLine = br.readLine()) != null) {
if (sCurrentLine.contains("associate")
&& sCurrentLine.contains("com.vlath.beheexplorer")) {
String[] chunks = sCurrentLine.split(" ");
associatedId = chunks[1];
System.out.println(associatedId);
flag = true;
}
if (sCurrentLine.contains("CPU-" + associatedId)
&& flag == true) { // Caculating power consumption per
// second
String[] chunks = sCurrentLine.split(" ");
powerConsumptions.add(Float.parseFloat(chunks[1]));
}
}
totalTime = powerConsumptions.size();
float powerChunk = 0;
ArrayList<Float> powerChunks = new ArrayList<Float>(0);
for(int i=0; i<powerConsumptions.size(); i+=5){
for(int j=i,k=0; (k<5 && j<powerConsumptions.size()); j++,k++){
powerChunk+=powerConsumptions.get(j);
}
powerChunks.add(powerChunk);
powerChunk = 0;
}
//displayPowerConsumptions(powerConsumptions);
displayPowerChunks(powerChunks,powerConsumptions.size());
System.out.println("Total time in seconds: " + totalTime);
float totalEnergyConsumption=0;
for(float chunks: powerChunks){
totalEnergyConsumption+=chunks;
}
System.out.println("Total energy consumption: " + totalEnergyConsumption + "mW");
System.out.println("Average power consumption: " + totalEnergyConsumption/totalTime + "mW");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
private static void displayPowerChunks(ArrayList<Float> powerChunks, float numberOfPowerConsumptions) {
System.out.println("Displaying power chunks");
float second = 0;
float iteration = 0;
for(float temp: powerChunks){
second+=5;
iteration++;
if(iteration == powerChunks.size()){
if(numberOfPowerConsumptions%5 != 0){
float dividend = numberOfPowerConsumptions/5;
dividend++;
temp/=dividend;
}
}else{
temp/=5;
}
System.out.println(second + " seconds average consumption: " + temp + " mW");
}
}
}