use of com.cisco.trex.stl.gui.services.UtilizationService in project trex-stateless-gui by cisco-system-traffic-generator.
the class UtilizationStorage method handleUtilizationReceived.
private void handleUtilizationReceived(final WorkerStateEvent event) {
final UtilizationService service = (UtilizationService) event.getSource();
final Utilization receivedUtilization = service.getValue();
if (receivedUtilization == null) {
return;
}
synchronized (utilizationStatsMonitor) {
synchronized (dataLock) {
List<UtilizationCPU> cpuUtilizationStats = receivedUtilization.getCpu();
int idx = 0;
for (UtilizationCPU cpuUtilizationStat : cpuUtilizationStats) {
String ports = cpuUtilizationStat.getPorts().stream().map(Objects::toString).collect(joining(", "));
String key = String.format("Socket %s (%s)", idx, ports);
String socketKey = String.format("Socket %s", idx);
Optional<Map.Entry<String, ArrayHistory<CpuUtilStatPoint>>> entryOptional = cpuUtilizationHistoryMap.entrySet().stream().filter(entry -> entry.getKey().startsWith(socketKey)).findFirst();
ArrayHistory<CpuUtilStatPoint> history;
if (entryOptional.isPresent()) {
history = entryOptional.get().getValue();
cpuUtilizationHistoryMap.remove(entryOptional.get().getKey());
} else {
history = new ArrayHistory<>(303);
}
int value = cpuUtilizationStat.getHistory().get(0);
double time = System.currentTimeMillis() / 1000.0;
history.add(new CpuUtilStatPoint(value, time));
cpuUtilizationHistoryMap.put(key, history);
idx++;
}
}
cpuUtilsModels = toCPUUtilModel(receivedUtilization.getCpu());
memUtilsModels.clear();
memUtilsModels.add(totalMemUtilization(receivedUtilization.getMbufStats()));
memUtilsModels.addAll(toMemUtilModel(receivedUtilization.getMbufStats()));
memUtilsModels.add(percentageMemUtilization(receivedUtilization.getMbufStats()));
}
handleUtilizationChanged();
}
Aggregations