-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathParseLog.java
More file actions
209 lines (180 loc) · 7.35 KB
/
ParseLog.java
File metadata and controls
209 lines (180 loc) · 7.35 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package sem2proj;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class ParseLog {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter mode (A, B, C, D, E): ");
String mode = scanner.nextLine();
String filePath = "extracted_log";
switch (mode) {
case "A":
countDoneStrings(filePath);
break;
case "B":
countPartitions(filePath);
break;
case "C":
countUserErrors(filePath);
break;
case "D":
calculateAverageExecutionTime(filePath);
break;
case "E":
jobSubmissionStats(filePath);
break;
default:
System.out.println("Invalid mode. Available modes are: A, B, C, D, E");
}
}
private static void countDoneStrings(String filePath) {
int jobCompleteCount = 0;
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
if (line.contains("done")) {
jobCompleteCount++;
}
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Total number of completed jobs: " + jobCompleteCount);
}
private static void calculateAverageExecutionTime(String logFilePath) {
List<Integer> Ids = new ArrayList<>();
List<Date> StartTimes = new ArrayList<>();
List<Date> EndTimes = new ArrayList<>();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
try (BufferedReader br = new BufferedReader(new FileReader(logFilePath))) {
String line;
while ((line = br.readLine()) != null) {
if (line.contains("_slurm_rpc_submit_batch_job")) {
int jobId = extractId(line);
Date startTime = parseTime(line, dateFormat);
Ids.add(jobId);
StartTimes.add(startTime);
EndTimes.add(null);
} else if (line.contains("job_complete")) {
int jobId = extractId(line);
Date endTime = parseTime(line, dateFormat);
int index = Ids.indexOf(jobId);
if (index != -1) {
EndTimes.set(index, endTime);
}
}
}
} catch (IOException | ParseException e) {
e.printStackTrace();
}
long totalExecutionTime = 0;
int Count = 0;
for (int i = 0; i < Ids.size(); i++) {
Date startTime = StartTimes.get(i);
Date endTime = EndTimes.get(i);
if (endTime != null) {
long executionTime = endTime.getTime() - startTime.getTime();
totalExecutionTime += executionTime;
Count++;
}
}
if (Count > 0) {
long averageExecutionTime = totalExecutionTime / Count;
System.out.println("Average Execution Time: " + averageExecutionTime + " milliseconds");
} else {
System.out.println("No jobs found.");
}
}
private static int extractId(String logLine) {
String[] parts = logLine.split(" ");
for (String part : parts) {
if (part.startsWith("JobId=")) {
return Integer.parseInt(part.substring(6));
}
}
return -1;
}
private static Date parseTime(String logLine, SimpleDateFormat dateFormat) throws ParseException {
String timestampStr = logLine.substring(1, 24);
return dateFormat.parse(timestampStr);
}
public static void countPartitions(String filePath) {
String[] partitions = {
"cpu-opteron",
"gpu-v100s",
"gpu-k10",
"gpu-titan",
"cpu-epyc",
"gpu-k40c"
};
Map<String, Integer> counts = new HashMap<>();
for (String partition : partitions) {
counts.put(partition, 0);
}
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
for (String partition : partitions) {
if (line.contains("sched: Allocate JobId=") && line.contains(" Partition=" + partition)) {
counts.put(partition, counts.get(partition) + 1);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
for (String partition : partitions) {
System.out.println("Total number of '" + partition + "' strings: " + counts.get(partition));
}
}
private static void countUserErrors(String filePath) {
Map<String, Integer> userErrorCount = new HashMap<>();
int totalErrors = 0;
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
if (line.contains("error: ")) {
int userIndex = line.indexOf("user='");
if (userIndex != -1) {
int userIdStart = userIndex + 6;
int userIdEnd = line.indexOf("'", userIdStart);
String userId = line.substring(userIdStart, userIdEnd);
userErrorCount.put(userId, userErrorCount.getOrDefault(userId, 0) + 1);
totalErrors++;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Total number of errors: " + totalErrors);
System.out.println("Error count per user:");
for (Map.Entry<String, Integer> entry : userErrorCount.entrySet()) {
System.out.println("User " + entry.getKey() + ": " + entry.getValue() + " errors");
}
}
private static void jobSubmissionStats(String filePath) {
int totalJobs = 0;
int successfulJobs = 0;
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
if (line.contains("_slurm_rpc_submit_batch_job")) {
totalJobs++;
} else if (line.contains("job_complete")) {
if (line.contains("done")) {
successfulJobs++;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
int failedJobs = totalJobs - successfulJobs;
System.out.println("Total number of job submissions: " + totalJobs);
System.out.println("Number of successful job submissions: " + successfulJobs);
System.out.println("Number of failed job submissions: " + failedJobs);
}
}