index int64 0 0 | repo_id stringlengths 26 205 | file_path stringlengths 51 246 | content stringlengths 8 433k | __index_level_0__ int64 0 10k |
|---|---|---|---|---|
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/util/TypeFactory.java | /********************************************************************************
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
/**
* @plasma147 provided this solution:
* https://stackoverflow.com/a/11385215/813561
* https://creativecommons.org/licenses/by-sa/3.0/
*/
package org.eclipse.jifa.common.util;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
public class TypeFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> type) {
Class<? super T> t = type.getRawType();
if(t.isAnnotationPresent(UseAccessor.class)) {
return (TypeAdapter<T>) new AccessorBasedTypeAdaptor(gson);
} else {
return null;
}
}
} | 6,700 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/util/FileUtil.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.util;
import org.eclipse.jifa.common.Constant;
import java.io.*;
import static org.eclipse.jifa.common.util.ErrorUtil.throwEx;
public class FileUtil {
public static String content(File f) {
String result = null;
try {
result = content(new FileInputStream(f));
} catch (FileNotFoundException e) {
throwEx(e);
}
return result;
}
public static String content(InputStream in) {
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append(Constant.LINE_SEPARATOR);
}
} catch (IOException e) {
throwEx(e);
}
return sb.toString();
}
public static void write(File f, String msg, boolean append) {
try (FileWriter fw = new FileWriter(f, append)) {
fw.write(msg);
} catch (IOException e) {
throwEx(e);
}
}
}
| 6,701 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/util/Assertion.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.util;
import org.eclipse.jifa.common.ErrorCode;
import org.eclipse.jifa.common.JifaException;
import java.util.Objects;
import java.util.function.Supplier;
public abstract class Assertion {
public static final Assertion ASSERT = new Assertion() {
};
protected Assertion() {
}
public Assertion isTrue(boolean expression, ErrorCode errorCode, Supplier<String> message) {
if (!expression) {
throwEx(errorCode, message.get());
}
return self();
}
public Assertion isTrue(boolean expression, ErrorCode errorCode, String message) {
return isTrue(expression, errorCode, () -> message);
}
public Assertion isTrue(boolean expression, Supplier<String> message) {
return isTrue(expression, ErrorCode.SANITY_CHECK, message);
}
public Assertion isTrue(boolean expression, String message) {
return isTrue(expression, ErrorCode.SANITY_CHECK, message);
}
public Assertion isTrue(boolean expression, ErrorCode errorCode) {
return isTrue(expression, errorCode, errorCode.name());
}
public Assertion isTrue(boolean expression) {
return isTrue(expression, ErrorCode.SANITY_CHECK);
}
public Assertion equals(Object expected, Object actual, ErrorCode errorCode, String message) {
return isTrue(Objects.equals(expected, actual), errorCode, message);
}
public Assertion equals(Object expected, Object actual, ErrorCode errorCode) {
return equals(expected, actual, errorCode, errorCode.name());
}
public Assertion equals(Object expected, Object actual, String message) {
return equals(expected, actual, ErrorCode.SANITY_CHECK, message);
}
public Assertion equals(Object expected, Object actual) {
return equals(expected, actual, ErrorCode.SANITY_CHECK);
}
public Assertion notNull(Object object, ErrorCode errorCode, Supplier<String> message) {
return isTrue(object != null, errorCode, message);
}
public Assertion notNull(Object object, Supplier<String> message) {
return notNull(object, ErrorCode.SANITY_CHECK, message);
}
public Assertion notNull(Object object, String message) {
return notNull(object, ErrorCode.SANITY_CHECK, () -> message);
}
public Assertion notNull(Object object) {
return notNull(object, ErrorCode.SANITY_CHECK, ErrorCode.SANITY_CHECK::name);
}
private Assertion self() {
return this;
}
protected void throwEx(ErrorCode errorCode, String message) {
throw new JifaException(errorCode, message);
}
}
| 6,702 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/util/GsonHolder.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class GsonHolder {
public static final Gson GSON = new GsonBuilder().registerTypeAdapterFactory(new TypeFactory())
.serializeSpecialFloatingPointValues()
.create();
}
| 6,703 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/util/UseAccessor.java | /********************************************************************************
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.util;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface UseAccessor {
} | 6,704 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/util/ReflectionUtil.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.util;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class ReflectionUtil {
@SuppressWarnings("unchecked")
public static <T> T getFieldValueOrNull(Object node, String fieldName) {
try {
Field field = node.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
return (T) field.get(node);
} catch (NoSuchFieldException | IllegalAccessException ignored) {
}
return null;
}
} | 6,705 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/util/ErrorUtil.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.util;
import org.eclipse.jifa.common.ErrorCode;
import org.eclipse.jifa.common.JifaException;
import java.io.PrintWriter;
import java.io.StringWriter;
public class ErrorUtil {
public static String toString(Throwable t) {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
public static void throwEx(Exception e) {
throw new JifaException(e);
}
public static <T> T shouldNotReachHere() {
throw new JifaException(ErrorCode.SHOULD_NOT_REACH_HERE);
}
public static void errorWith(ErrorCode code, String detail) {
throw new JifaException(code, detail);
}
}
| 6,706 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/util/CollectionUtil.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.util;
import java.util.Collection;
import java.util.function.Consumer;
public class CollectionUtil {
@SafeVarargs
public static <T> void forEach(Consumer<T> action, Collection<? extends T>... cs) {
for (Collection<? extends T> c : cs) {
c.forEach(action);
}
}
}
| 6,707 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/util/HTTPRespGuarder.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.util;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.RoutingContext;
import io.vertx.serviceproxy.ServiceException;
import org.eclipse.jifa.common.Constant;
import org.eclipse.jifa.common.ErrorCode;
import org.eclipse.jifa.common.JifaException;
import org.eclipse.jifa.common.vo.ErrorResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import static org.eclipse.jifa.common.util.GsonHolder.GSON;
public class HTTPRespGuarder implements Constant {
private static final Logger LOGGER = LoggerFactory.getLogger(HTTPRespGuarder.class);
public static void ok(io.vertx.reactivex.ext.web.RoutingContext context) {
ok(context.getDelegate());
}
public static void ok(io.vertx.reactivex.ext.web.RoutingContext context, int statusCode, Object content) {
ok(context.getDelegate(), statusCode, content);
}
public static void ok(io.vertx.reactivex.ext.web.RoutingContext context, Object content) {
ok(context.getDelegate(), content);
}
public static void fail(io.vertx.reactivex.ext.web.RoutingContext context, Throwable t) {
fail(context.getDelegate(), t);
}
public static void ok(RoutingContext context) {
ok(context, commonStatusCodeOf(context.request().method()), null);
}
public static void ok(RoutingContext context, Object content) {
ok(context, commonStatusCodeOf(context.request().method()), content);
}
private static void ok(RoutingContext context, int statusCode, Object content) {
HttpServerResponse response = context.response();
response.putHeader(Constant.HEADER_CONTENT_TYPE_KEY, Constant.CONTENT_TYPE_JSON_FORM).setStatusCode(statusCode);
if (content != null) {
response.end((content instanceof String) ? (String) content : GSON.toJson(content));
} else {
response.end();
}
}
public static void fail(RoutingContext context, Throwable t) {
if (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
log(t);
context.response()
.putHeader(Constant.HEADER_CONTENT_TYPE_KEY, Constant.CONTENT_TYPE_JSON_FORM)
.setStatusCode(statusCodeOf(t))
.end(GSON.toJson(new ErrorResult(t)));
}
private static int statusCodeOf(Throwable t) {
ErrorCode errorCode = ErrorCode.UNKNOWN_ERROR;
if (t instanceof JifaException) {
errorCode = ((JifaException) t).getCode();
}
if (t instanceof IllegalArgumentException) {
errorCode = ErrorCode.ILLEGAL_ARGUMENT;
}
if (errorCode == ErrorCode.ILLEGAL_ARGUMENT) {
return HTTP_BAD_REQUEST_STATUS_CODE;
}
return HTTP_INTERNAL_SERVER_ERROR_STATUS_CODE;
}
private static void log(Throwable t) {
boolean shouldLogError = true;
if (t instanceof JifaException) {
shouldLogError = ((JifaException) t).getCode().isFatal();
}
if ( t instanceof ServiceException) {
// FIXME: should we use ServiceException.failureCode?
ServiceException se = (ServiceException) t;
shouldLogError = se.failureCode() != ErrorCode.RETRY.ordinal();
LOGGER.debug("Starting worker for target {}", se.getMessage());
}
if (shouldLogError) {
LOGGER.error("Handle http request failed", t);
}
}
private static int commonStatusCodeOf(HttpMethod method) {
if (method == HttpMethod.POST) {
return Constant.HTTP_POST_CREATED_STATUS_CODE;
}
return Constant.HTTP_GET_OK_STATUS_CODE;
}
}
| 6,708 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/util/AccessorBasedTypeAdaptor.java | /********************************************************************************
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
/**
* @plasma147 provided this solution:
* https://stackoverflow.com/a/11385215/813561
* https://creativecommons.org/licenses/by-sa/3.0/
*/
package org.eclipse.jifa.common.util;
import java.io.IOException;
import java.lang.reflect.Method;
import com.google.common.base.CaseFormat;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import org.eclipse.jifa.common.JifaException;
public class AccessorBasedTypeAdaptor<T> extends TypeAdapter<T> {
private Gson gson;
public AccessorBasedTypeAdaptor(Gson gson) {
this.gson = gson;
}
@SuppressWarnings("unchecked")
@Override
public void write(JsonWriter out, T value) throws IOException {
out.beginObject();
for (Method method : value.getClass().getMethods()) {
boolean nonBooleanAccessor = method.getName().startsWith("get");
boolean booleanAccessor = method.getName().startsWith("is");
if ((nonBooleanAccessor || booleanAccessor) && !method.getName().equals("getClass") && method.getParameterTypes().length == 0) {
try {
String name = method.getName().substring(nonBooleanAccessor ? 3 : 2);
name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, name);
Object returnValue = method.invoke(value);
if(returnValue != null) {
TypeToken<?> token = TypeToken.get(returnValue.getClass());
TypeAdapter adapter = gson.getAdapter(token);
out.name(name);
adapter.write(out, returnValue);
}
} catch (Exception e) {
throw new JifaException(e);
}
}
}
out.endObject();
}
@Override
public T read(JsonReader in) throws IOException {
throw new UnsupportedOperationException("Only supports writes.");
}
} | 6,709 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/enums/FileType.java | /********************************************************************************
* Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.enums;
import static org.eclipse.jifa.common.util.ErrorUtil.shouldNotReachHere;
public enum FileType {
HEAP_DUMP("heap-dump"),
GC_LOG("gc-log"),
THREAD_DUMP("thread-dump")
;
private String tag;
FileType(String tag) {
this.tag = tag;
}
public static FileType getByTag(String tag) {
for (FileType type : FileType.values()) {
if (type.tag.equals(tag)) {
return type;
}
}
return shouldNotReachHere();
}
public String getTag() {
return tag;
}
}
| 6,710 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/enums/FileTransferState.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.enums;
public enum FileTransferState {
NOT_STARTED,
IN_PROGRESS,
SUCCESS,
ERROR;
public static FileTransferState fromProgressState(ProgressState progress) {
switch (progress) {
case NOT_STARTED:
return NOT_STARTED;
case IN_PROGRESS:
return IN_PROGRESS;
case SUCCESS:
return SUCCESS;
case ERROR:
return ERROR;
}
throw new IllegalStateException();
}
public boolean isFinal() {
return this == SUCCESS || this == ERROR;
}
public ProgressState toProgressState() {
switch (this) {
case NOT_STARTED:
return ProgressState.NOT_STARTED;
case IN_PROGRESS:
return ProgressState.IN_PROGRESS;
case SUCCESS:
return ProgressState.SUCCESS;
case ERROR:
return ProgressState.ERROR;
}
throw new IllegalStateException();
}
}
| 6,711 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/enums/ProgressState.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.enums;
public enum ProgressState {
NOT_STARTED,
IN_PROGRESS,
SUCCESS,
ERROR,
;
public boolean isFinal() {
return this == SUCCESS || this == ERROR;
}
}
| 6,712 |
0 | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common | Create_ds/eclipse-jifa/backend/common/src/main/java/org/eclipse/jifa/common/request/PagingRequest.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.common.request;
import lombok.Data;
import static org.eclipse.jifa.common.util.Assertion.ASSERT;
@Data
public class PagingRequest {
// start with 1
private int page;
private int pageSize;
public PagingRequest(int page, int pageSize) {
ASSERT.isTrue(page >= 1 && pageSize >= 1);
this.page = page;
this.pageSize = pageSize;
}
public int from() {
return (page - 1) * pageSize;
}
public int to(int totalSize) {
return Math.min(from() + pageSize, totalSize);
}
}
| 6,713 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa/gclog/TestParser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog;
import org.eclipse.jifa.common.listener.DefaultProgressListener;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.ThreadEvent;
import org.eclipse.jifa.gclog.event.Safepoint;
import org.eclipse.jifa.gclog.model.*;
import org.eclipse.jifa.gclog.model.modeInfo.GCLogMetadata;
import org.eclipse.jifa.gclog.parser.*;
import org.eclipse.jifa.gclog.event.evnetInfo.GCMemoryItem;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.parser.GCLogParsingMetadata;
import org.eclipse.jifa.gclog.model.modeInfo.GCLogStyle;
import org.eclipse.jifa.gclog.vo.PauseStatistics;
import org.eclipse.jifa.gclog.vo.TimeRange;
import org.junit.Assert;
import org.junit.Test;
import java.util.List;
import static org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType.YOUNG_GC_BECOME_FULL_GC;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
import static org.eclipse.jifa.gclog.event.evnetInfo.GCCause.*;
import static org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType.TO_SPACE_EXHAUSTED;
import static org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea.*;
import static org.eclipse.jifa.gclog.TestUtil.stringToBufferedReader;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
public class TestParser {
public static final double DELTA = 1e-6;
@Test
public void testJDK11G1Parser() throws Exception {
String log =
"[0.015s][info][gc,heap] Heap region size: 1M\n" +
"[0.017s][info][gc ] Using G1\n" +
"[0.017s][info][gc,heap,coops] Heap address: 0x00000007fc000000, size: 64 MB, Compressed Oops mode: Zero based, Oop shift amount: 3\n" +
"[0.050s][info ][gc ] Periodic GC enabled with interval 100 ms" +
"[1.000s][info][safepoint ] Application time: 0.0816788 seconds\n" +
"[1.000s][info][safepoint ] Entering safepoint region: G1CollectForAllocation\n" +
"[1.000s][info][gc,start ] GC(0) Pause Young (Normal) (Metadata GC Threshold)\n" +
"[1.000s][info][gc,task ] GC(0) Using 8 workers of 8 for evacuation\n" +
"[1.010s][info][gc ] GC(0) To-space exhausted\n" +
"[1.010s][info][gc,phases ] GC(0) Pre Evacuate Collection Set: 0.0ms\n" +
"[1.010s][info][gc,phases ] GC(0) Evacuate Collection Set: 9.5ms\n" +
"[1.010s][info][gc,phases ] GC(0) Post Evacuate Collection Set: 0.6ms\n" +
"[1.010s][info][gc,phases ] GC(0) Other: 0.5ms\n" +
"[1.010s][info][gc,heap ] GC(0) Eden regions: 19->0(33)\n" +
"[1.010s][info][gc,heap ] GC(0) Survivor regions: 0->3(3)\n" +
"[1.010s][info][gc,heap ] GC(0) Old regions: 0->2\n" +
"[1.010s][info][gc,heap ] GC(0) Humongous regions: 4->3\n" +
"[1.010s][info][gc,metaspace ] GC(0) Metaspace: 20679K->20679K(45056K)\n" +
"[1.010s][info][gc ] GC(0) Pause Young (Concurrent Start) (Metadata GC Threshold) 19M->4M(64M) 10.709ms\n" +
"[1.010s][info][gc,cpu ] GC(0) User=0.02s Sys=0.01s Real=0.01s\n" +
"[1.010s][info][safepoint ] Leaving safepoint region\n" +
"[1.010s][info][safepoint ] Total time for which application threads were stopped: 0.0101229 seconds, Stopping threads took: 0.0000077 seconds\n" +
"[3.000s][info][gc ] GC(1) Concurrent Cycle\n" +
"[3.000s][info][gc,marking ] GC(1) Concurrent Clear Claimed Marks\n" +
"[3.000s][info][gc,marking ] GC(1) Concurrent Clear Claimed Marks 0.057ms\n" +
"[3.000s][info][gc,marking ] GC(1) Concurrent Scan Root Regions\n" +
"[3.002s][info][gc,marking ] GC(1) Concurrent Scan Root Regions 2.709ms\n" +
"[3.002s][info][gc,marking ] GC(1) Concurrent Mark (3.002s)\n" +
"[3.002s][info][gc,marking ] GC(1) Concurrent Mark From Roots\n" +
"[3.002s][info][gc,task ] GC(1) Using 2 workers of 2 for marking\n" +
"[3.005s][info][gc,marking ] GC(1) Concurrent Mark From Roots 3.109ms\n" +
"[3.005s][info][gc,marking ] GC(1) Concurrent Preclean\n" +
"[3.005s][info][gc,marking ] GC(1) Concurrent Preclean 0.040ms\n" +
"[3.005s][info][gc,marking ] GC(1) Concurrent Mark (2.391s, 2.394s) 3.251ms\n" +
"[3.005s][info][gc,start ] GC(1) Pause Remark\n" +
"[3.005s][info][gc,stringtable] GC(1) Cleaned string and symbol table, strings: 9850 processed, 0 removed, symbols: 69396 processed, 29 removed\n" +
"[3.008s][info][gc ] GC(1) Pause Remark 5M->5M(64M) 2.381ms\n" +
"[3.008s][info][gc,cpu ] GC(1) User=0.01s Sys=0.00s Real=0.01s\n" +
"[3.008s][info][gc,marking ] GC(1) Concurrent Rebuild Remembered Sets\n" +
"[3.010s][info][gc,marking ] GC(1) Concurrent Rebuild Remembered Sets 2.151ms\n" +
"[3.010s][info][gc,start ] GC(1) Pause Cleanup\n" +
"[3.010s][info][gc ] GC(1) Pause Cleanup 6M->6M(64M) 0.094ms\n" +
"[3.010s][info][gc,cpu ] GC(1) User=0.00s Sys=0.00s Real=0.00s\n" +
"[3.010s][info][gc,marking ] GC(1) Concurrent Cleanup for Next Mark\n" +
"[3.012s][info][gc,marking ] GC(1) Concurrent Cleanup for Next Mark 2.860ms\n" +
"[3.012s][info][gc ] GC(1) Concurrent Cycle 14.256ms\n" +
"[7.055s][info ][gc,task ] GC(2) Using 8 workers of 8 for full compaction\n" +
"[7.055s][info ][gc,start ] GC(2) Pause Full (G1 Evacuation Pause)\n" +
"[7.056s][info ][gc,phases,start] GC(2) Phase 1: Mark live objects\n" +
"[7.058s][info ][gc,stringtable ] GC(2) Cleaned string and symbol table, strings: 1393 processed, 0 removed, symbols: 17391 processed, 0 removed\n" +
"[7.058s][info ][gc,phases ] GC(2) Phase 1: Mark live objects 2.650ms\n" +
"[7.058s][info ][gc,phases,start] GC(2) Phase 2: Prepare for compaction\n" +
"[7.061s][info ][gc,phases ] GC(2) Phase 2: Prepare for compaction 2.890ms\n" +
"[7.061s][info ][gc,phases,start] GC(2) Phase 3: Adjust pointers\n" +
"[7.065s][info ][gc,phases ] GC(2) Phase 3: Adjust pointers 3.890ms\n" +
"[7.065s][info ][gc,phases,start] GC(2) Phase 4: Compact heap\n" +
"[7.123s][info ][gc,phases ] GC(2) Phase 4: Compact heap 57.656ms\n" +
"[7.123s][info ][gc,heap ] GC(2) Eden regions: 0->0(680)\n" +
"[7.123s][info ][gc,heap ] GC(2) Survivor regions: 0->0(85)\n" +
"[7.123s][info ][gc,heap ] GC(2) Old regions: 1700->1089\n" +
"[7.123s][info ][gc,heap ] GC(2) Humongous regions: 0->0\n" +
"[7.123s][info ][gc,metaspace ] GC(2) Metaspace: 3604K->3604K(262144K)\n" +
"[7.123s][info ][gc ] GC(2) Pause Full (G1 Evacuation Pause) 1700M->1078M(1700M) 67.806ms\n" +
"[7.123s][info ][gc,cpu ] GC(2) User=0.33s Sys=0.00s Real=0.07s";
UnifiedG1GCLogParser parser = (UnifiedG1GCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
G1GCModel model = (G1GCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
// assert parsing success
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 3);
// assert model info
Assert.assertEquals(model.getStartTime(), 0.0 * 1000, DELTA);
Assert.assertEquals(model.getEndTime(), 7.123 * 1000, DELTA);
Assert.assertEquals(model.getCollectorType(), GCCollectorType.G1);
Assert.assertEquals(model.getHeapRegionSize(), 1024 * 1024);
Assert.assertNull(model.getVmOptions());
Assert.assertEquals(model.getParallelThread(), 8);
Assert.assertEquals(model.getConcurrentThread(), 2);
// assert events correct
Assert.assertEquals(model.getSafepoints().size(), 1);
Safepoint safepoint = model.getSafepoints().get(0);
Assert.assertEquals(safepoint.getStartTime(), 1010 - 10.1229, DELTA);
Assert.assertEquals(safepoint.getDuration(), 10.1229, DELTA);
Assert.assertEquals(safepoint.getTimeToEnter(), 0.0077, DELTA);
List<GCEvent> event = model.getGcEvents();
GCEvent youngGC = event.get(0);
Assert.assertEquals(youngGC.getGcid(), 0);
Assert.assertTrue(youngGC.isTrue(TO_SPACE_EXHAUSTED));
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getStartTime(), 1.0 * 1000, DELTA);
Assert.assertEquals(youngGC.getPause(), 10.709, DELTA);
Assert.assertEquals(youngGC.getDuration(), 10.709, DELTA);
Assert.assertEquals(youngGC.getCause(), METADATA_GENERATION_THRESHOLD);
Assert.assertEquals(youngGC.getCpuTime().getReal(), 0.01 * 1000, DELTA);
Assert.assertEquals(youngGC.getPhases().size(), 4);
Assert.assertEquals(youngGC.getPhases().get(1).getEventType(), GCEventType.G1_COLLECT_EVACUATION);
Assert.assertEquals(youngGC.getPhases().get(1).getDuration(), 9.5, DELTA);
Assert.assertEquals(youngGC.getMemoryItem(SURVIVOR)
, new GCMemoryItem(SURVIVOR, 0 * 1024, 3 * 1024 * 1024, 3 * 1024 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(METASPACE)
, new GCMemoryItem(METASPACE, 20679 * 1024, 20679 * 1024, 45056 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(HEAP)
, new GCMemoryItem(HEAP, 19 * 1024 * 1024, 4 * 1024 * 1024, 64 * 1024 * 1024));
Assert.assertTrue(youngGC.toString().contains("To-space Exhausted"));
GCEvent concurrentMark = event.get(1);
Assert.assertEquals(concurrentMark.getGcid(), 1);
Assert.assertEquals(concurrentMark.getEventType(), GCEventType.G1_CONCURRENT_CYCLE);
Assert.assertEquals(concurrentMark.getDuration(), 14.256, DELTA);
Assert.assertEquals(concurrentMark.getPause(), 2.381 + 0.094, DELTA);
Assert.assertEquals(concurrentMark.getPhases().get(0).getEventType(), GCEventType.G1_CONCURRENT_CLEAR_CLAIMED_MARKS);
Assert.assertEquals(concurrentMark.getPhases().get(0).getDuration(), 0.057, DELTA);
GCEvent fullGC = event.get(2);
Assert.assertEquals(fullGC.getGcid(), 2);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getStartTime(), 7.055 * 1000, DELTA);
Assert.assertEquals(fullGC.getPause(), 67.806, DELTA);
Assert.assertEquals(fullGC.getDuration(), 67.806, DELTA);
Assert.assertEquals(fullGC.getCause(), G1_EVACUATION_PAUSE);
Assert.assertEquals(fullGC.getPhases().size(), 4);
Assert.assertEquals(fullGC.getPhases().get(3).getEventType(), GCEventType.G1_COMPACT_HEAP);
Assert.assertEquals(fullGC.getPhases().get(3).getDuration(), 57.656, DELTA);
GCLogMetadata metadata = model.getGcModelMetadata();
Assert.assertTrue(metadata.getImportantEventTypes().contains(GCEventType.G1_CONCURRENT_REBUILD_REMEMBERED_SETS.getName()));
Assert.assertFalse(metadata.getImportantEventTypes().contains(GCEventType.G1_CONCURRENT_UNDO_CYCLE.getName()));
}
@Test
public void testJDK11G1ParserDetectHeapRegionSize() throws Exception {
String log = "[3.865s][info][gc,start ] GC(14) Pause Young (Normal) (G1 Evacuation Pause)\n" +
"[3.865s][info][gc,task ] GC(14) Using 2 workers of 2 for evacuation\n" +
"[3.982s][info][gc,phases ] GC(14) Pre Evacuate Collection Set: 0.0ms\n" +
"[3.982s][info][gc,phases ] GC(14) Evacuate Collection Set: 116.2ms\n" +
"[3.982s][info][gc,phases ] GC(14) Post Evacuate Collection Set: 0.3ms\n" +
"[3.982s][info][gc,phases ] GC(14) Other: 0.2ms\n" +
"[3.982s][info][gc,heap ] GC(14) Eden regions: 5->0(5)\n" +
"[3.982s][info][gc,heap ] GC(14) Survivor regions: 1->1(1)\n" +
"[3.982s][info][gc,heap ] GC(14) Old regions: 32->37\n" +
"[3.982s][info][gc,heap ] GC(14) Humongous regions: 2->2\n" +
"[3.982s][info][gc,metaspace ] GC(14) Metaspace: 21709K->21707K(1069056K)\n" +
"[3.982s][info][gc ] GC(14) Pause Young (Normal) (G1 Evacuation Pause) 637M->630M(2048M) 116.771ms";
UnifiedG1GCLogParser parser = new UnifiedG1GCLogParser();
parser.setMetadata(new GCLogParsingMetadata(GCCollectorType.G1, GCLogStyle.UNIFIED));
G1GCModel model = (G1GCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
// should infer region size 16m
Assert.assertEquals(model.getHeapRegionSize(), 16 * 1024 * 1024);
Assert.assertEquals(model.getGcEvents().get(0).getMemoryItem(OLD)
, new GCMemoryItem(OLD, 32 * 16 * 1024 * 1024, 37 * 16 * 1024 * 1024, 1952L * 1024 * 1024));
Assert.assertEquals(model.getGcEvents().get(0).getMemoryItem(METASPACE)
, new GCMemoryItem(METASPACE, 21709 * 1024, 21707 * 1024, 1069056 * 1024));
}
@Test
public void testJDK11ParseDecoration() throws Exception {
String log = "[2021-05-06T11:25:16.508+0800][info][gc ] GC(0) Pause Young (Concurrent Start) (Metadata GC Threshold)\n" +
"[2021-05-06T11:25:16.510+0800][info][gc ] GC(1) Pause Young (Concurrent Start) (Metadata GC Threshold)\n";
UnifiedG1GCLogParser parser = new UnifiedG1GCLogParser();
parser.setMetadata(new GCLogParsingMetadata(GCCollectorType.G1, GCLogStyle.UNIFIED));
GCModel model = parser.parse(stringToBufferedReader(log));
Assert.assertEquals(model.getReferenceTimestamp(), 1620271516508d, DELTA);
Assert.assertEquals(model.getGcEvents().get(1).getStartTime(), 2, DELTA);
log = "[1000000000800ms][info][gc ] GC(0) Pause Young (Concurrent Start) (Metadata GC Threshold)\n" +
"[1000000000802ms][info][gc ] GC(1) Pause Young (Concurrent Start) (Metadata GC Threshold)\n";
parser = new UnifiedG1GCLogParser();
parser.setMetadata(new GCLogParsingMetadata(GCCollectorType.G1, GCLogStyle.UNIFIED));
model = parser.parse(stringToBufferedReader(log));
Assert.assertEquals(model.getReferenceTimestamp(), 1000000000800D, DELTA);
Assert.assertEquals(model.getGcEvents().get(1).getStartTime(), 2, DELTA);
}
@Test
public void testJDK11ZGCParser() throws Exception {
String log =
"[7.000s] GC(374) Garbage Collection (Proactive)\n" +
"[7.006s] GC(374) Pause Mark Start 4.459ms\n" +
"[7.312s] GC(374) Concurrent Mark 306.720ms\n" +
"[7.312s] GC(374) Pause Mark End 0.606ms\n" +
"[7.313s] GC(374) Concurrent Process Non-Strong References 1.290ms\n" +
"[7.314s] GC(374) Concurrent Reset Relocation Set 0.550ms\n" +
"[7.314s] GC(374) Concurrent Destroy Detached Pages 0.001ms\n" +
"[7.316s] GC(374) Concurrent Select Relocation Set 2.418ms\n" +
"[7.321s] GC(374) Concurrent Prepare Relocation Set 5.719ms\n" +
"[7.324s] GC(374) Pause Relocate Start 3.791ms\n" +
"[7.356s] GC(374) Concurrent Relocate 32.974ms\n" +
"[7.356s] GC(374) Load: 1.68/1.99/2.04\n" +
"[7.356s] GC(374) MMU: 2ms/0.0%, 5ms/0.0%, 10ms/0.0%, 20ms/0.0%, 50ms/0.0%, 100ms/0.0%\n" +
"[7.356s] GC(374) Mark: 8 stripe(s), 2 proactive flush(es), 1 terminate flush(es), 0 completion(s), 0 continuation(s)\n" +
"[7.356s] GC(374) Relocation: Successful, 359M relocated\n" +
"[7.356s] GC(374) NMethods: 21844 registered, 609 unregistered\n" +
"[7.356s] GC(374) Metaspace: 125M used, 127M capacity, 128M committed, 130M reserved\n" +
"[7.356s] GC(374) Soft: 18634 encountered, 0 discovered, 0 enqueued\n" +
"[7.356s] GC(374) Weak: 56186 encountered, 18454 discovered, 3112 enqueued\n" +
"[7.356s] GC(374) Final: 64 encountered, 16 discovered, 7 enqueued\n" +
"[7.356s] GC(374) Phantom: 1882 encountered, 1585 discovered, 183 enqueued\n" +
"[7.356s] GC(374) Mark Start Mark End Relocate Start Relocate End High Low\n" +
"[7.356s] GC(374) Capacity: 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%)\n" +
"[7.356s] GC(374) Reserve: 96M (0%) 96M (0%) 96M (0%) 96M (0%) 96M (0%) 96M (0%)\n" +
"[7.356s] GC(374) Free: 35250M (86%) 35210M (86%) 35964M (88%) 39410M (96%) 39410M (96%) 35210M (86%)\n" +
"[7.356s] GC(374) Used: 5614M (14%) 5654M (14%) 4900M (12%) 1454M (4%) 5654M (14%) 1454M (4%)\n" +
"[7.356s] GC(374) Live: - 1173M (3%) 1173M (3%) 1173M (3%) - -\n" +
"[7.356s] GC(374) Allocated: - 40M (0%) 40M (0%) 202M (0%) - -\n" +
"[7.356s] GC(374) Garbage: - 4440M (11%) 3686M (9%) 240M (1%) - -\n" +
"[7.356s] GC(374) Reclaimed: - - 754M (2%) 4200M (10%) - -\n" +
"[7.356s] GC(374) Garbage Collection (Proactive) 5614M(14%)->1454M(4%)\n" +
"[7.555s] === Garbage Collection Statistics =======================================================================================================================\n" +
"[7.555s] Last 10s Last 10m Last 10h Total\n" +
"[7.555s] Avg / Max Avg / Max Avg / Max Avg / Max\n" +
"[7.555s] Collector: Garbage Collection Cycle 362.677 / 362.677 365.056 / 529.211 315.229 / 868.961 315.229 / 868.961 ms\n" +
"[7.555s] Contention: Mark Segment Reset Contention 0 / 0 1 / 106 0 / 238 0 / 238 ops/s\n" +
"[7.555s] Contention: Mark SeqNum Reset Contention 0 / 0 0 / 1 0 / 1 0 / 1 ops/s\n" +
"[7.555s] Contention: Relocation Contention 1 / 10 0 / 52 0 / 87 0 / 87 ops/s\n" +
"[7.555s] Critical: Allocation Stall 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[7.555s] Critical: Allocation Stall 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[7.555s] Critical: GC Locker Stall 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[7.555s] Critical: GC Locker Stall 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[7.555s] Memory: Allocation Rate 85 / 210 104 / 826 54 / 2628 54 / 2628 MB/s\n" +
"[7.555s] Memory: Heap Used After Mark 5654 / 5654 5727 / 6416 5588 / 14558 5588 / 14558 MB\n" +
"[7.555s] Memory: Heap Used After Relocation 1454 / 1454 1421 / 1814 1224 / 2202 1224 / 2202 MB\n" +
"[7.555s] Memory: Heap Used Before Mark 5614 / 5614 5608 / 6206 5503 / 14268 5503 / 14268 MB\n" +
"[7.555s] Memory: Heap Used Before Relocation 4900 / 4900 4755 / 5516 4665 / 11700 4665 / 11700 MB\n" +
"[7.555s] Memory: Out Of Memory 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[7.555s] Memory: Page Cache Flush 0 / 0 0 / 0 0 / 0 0 / 0 MB/s\n" +
"[7.555s] Memory: Page Cache Hit L1 49 / 105 53 / 439 27 / 1353 27 / 1353 ops/s\n" +
"[7.555s] Memory: Page Cache Hit L2 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[7.555s] Memory: Page Cache Miss 0 / 0 0 / 0 0 / 551 0 / 551 ops/s\n" +
"[7.555s] Memory: Undo Object Allocation Failed 0 / 0 0 / 0 0 / 8 0 / 8 ops/s\n" +
"[7.555s] Memory: Undo Object Allocation Succeeded 1 / 10 0 / 52 0 / 87 0 / 87 ops/s\n" +
"[7.555s] Memory: Undo Page Allocation 0 / 0 0 / 1 0 / 16 0 / 16 ops/s\n" +
"[7.555s] Phase: Concurrent Destroy Detached Pages 0.001 / 0.001 0.001 / 0.001 0.001 / 0.012 0.001 / 0.012 ms\n" +
"[7.555s] Phase: Concurrent Mark 306.720 / 306.720 303.979 / 452.112 255.790 / 601.718 255.790 / 601.718 ms\n" +
"[7.555s] Phase: Concurrent Mark Continue 0.000 / 0.000 0.000 / 0.000 189.372 / 272.607 189.372 / 272.607 ms\n" +
"[7.555s] Phase: Concurrent Prepare Relocation Set 5.719 / 5.719 6.314 / 14.492 6.150 / 36.507 6.150 / 36.507 ms\n" +
"[7.555s] Phase: Concurrent Process Non-Strong References 1.290 / 1.290 1.212 / 1.657 1.179 / 2.334 1.179 / 2.334 ms\n" +
"[7.555s] Phase: Concurrent Relocate 32.974 / 32.974 35.964 / 86.278 31.599 / 101.253 31.599 / 101.253 ms\n" +
"[7.555s] Phase: Concurrent Reset Relocation Set 0.550 / 0.550 0.615 / 0.937 0.641 / 5.411 0.641 / 5.411 ms\n" +
"[7.555s] Phase: Concurrent Select Relocation Set 2.418 / 2.418 2.456 / 3.131 2.509 / 4.753 2.509 / 4.753 ms\n" +
"[7.555s] Phase: Pause Mark End 0.606 / 0.606 0.612 / 0.765 0.660 / 5.543 0.660 / 5.543 ms\n" +
"[7.555s] Phase: Pause Mark Start 4.459 / 4.459 4.636 / 6.500 6.160 / 547.572 6.160 / 547.572 ms\n" +
"[7.555s] Phase: Pause Relocate Start 3.791 / 3.791 3.970 / 5.443 4.047 / 8.993 4.047 / 8.993 ms\n" +
"[7.555s] Subphase: Concurrent Mark 306.253 / 306.593 303.509 / 452.030 254.759 / 601.564 254.759 / 601.564 ms\n" +
"[7.555s] Subphase: Concurrent Mark Idle 1.069 / 1.110 1.527 / 18.317 1.101 / 18.317 1.101 / 18.317 ms\n" +
"[7.555s] Subphase: Concurrent Mark Try Flush 0.554 / 0.685 0.872 / 18.247 0.507 / 18.247 0.507 / 18.247 ms\n" +
"[7.555s] Subphase: Concurrent Mark Try Terminate 0.978 / 1.112 1.386 / 18.318 0.998 / 18.318 0.998 / 18.318 ms\n" +
"[7.555s] Subphase: Concurrent References Enqueue 0.007 / 0.007 0.008 / 0.013 0.009 / 0.037 0.009 / 0.037 ms\n" +
"[7.555s] Subphase: Concurrent References Process 0.628 / 0.628 0.638 / 1.153 0.596 / 1.789 0.596 / 1.789 ms\n" +
"[7.555s] Subphase: Concurrent Weak Roots 0.497 / 0.618 0.492 / 0.670 0.502 / 1.001 0.502 / 1.001 ms\n" +
"[7.555s] Subphase: Concurrent Weak Roots JNIWeakHandles 0.001 / 0.001 0.001 / 0.006 0.001 / 0.007 0.001 / 0.007 ms\n" +
"[7.555s] Subphase: Concurrent Weak Roots StringTable 0.476 / 0.492 0.402 / 0.523 0.400 / 0.809 0.400 / 0.809 ms\n" +
"[7.555s] Subphase: Concurrent Weak Roots VMWeakHandles 0.105 / 0.123 0.098 / 0.150 0.103 / 0.903 0.103 / 0.903 ms\n" +
"[7.555s] Subphase: Pause Mark Try Complete 0.000 / 0.000 0.001 / 0.004 0.156 / 1.063 0.156 / 1.063 ms\n" +
"[7.555s] Subphase: Pause Remap TLABS 0.040 / 0.040 0.046 / 0.073 0.050 / 0.140 0.050 / 0.140 ms\n" +
"[7.555s] Subphase: Pause Retire TLABS 0.722 / 0.722 0.835 / 1.689 0.754 / 1.919 0.754 / 1.919 ms\n" +
"[7.555s] Subphase: Pause Roots 1.581 / 2.896 1.563 / 3.787 1.592 / 545.902 1.592 / 545.902 ms\n" +
"[7.555s] Subphase: Pause Roots ClassLoaderDataGraph 1.461 / 2.857 1.549 / 3.782 1.554 / 6.380 1.554 / 6.380 ms\n" +
"[7.555s] Subphase: Pause Roots CodeCache 1.130 / 1.312 0.999 / 1.556 0.988 / 6.322 0.988 / 6.322 ms\n" +
"[7.555s] Subphase: Pause Roots JNIHandles 0.010 / 0.015 0.004 / 0.028 0.005 / 1.709 0.005 / 1.709 ms\n" +
"[7.555s] Subphase: Pause Roots JNIWeakHandles 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[7.555s] Subphase: Pause Roots JRFWeak 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[7.555s] Subphase: Pause Roots JVMTIExport 0.001 / 0.001 0.001 / 0.003 0.001 / 0.005 0.001 / 0.005 ms\n" +
"[7.555s] Subphase: Pause Roots JVMTIWeakExport 0.001 / 0.001 0.001 / 0.001 0.001 / 0.012 0.001 / 0.012 ms\n" +
"[7.555s] Subphase: Pause Roots Management 0.002 / 0.002 0.003 / 0.006 0.003 / 0.305 0.003 / 0.305 ms\n" +
"[7.555s] Subphase: Pause Roots ObjectSynchronizer 0.000 / 0.000 0.000 / 0.001 0.000 / 0.006 0.000 / 0.006 ms\n" +
"[7.555s] Subphase: Pause Roots Setup 0.474 / 0.732 0.582 / 1.791 0.526 / 2.610 0.526 / 2.610 ms\n" +
"[7.555s] Subphase: Pause Roots StringTable 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[7.555s] Subphase: Pause Roots SystemDictionary 0.028 / 0.039 0.027 / 0.075 0.033 / 2.777 0.033 / 2.777 ms\n" +
"[7.555s] Subphase: Pause Roots Teardown 0.003 / 0.005 0.003 / 0.009 0.003 / 0.035 0.003 / 0.035 ms\n" +
"[7.555s] Subphase: Pause Roots Threads 0.262 / 1.237 0.309 / 1.791 0.358 / 544.610 0.358 / 544.610 ms\n" +
"[7.555s] Subphase: Pause Roots Universe 0.003 / 0.004 0.003 / 0.009 0.003 / 0.047 0.003 / 0.047 ms\n" +
"[7.555s] Subphase: Pause Roots VMWeakHandles 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[7.555s] Subphase: Pause Weak Roots 0.000 / 0.003 0.000 / 0.007 0.000 / 0.020 0.000 / 0.020 ms\n" +
"[7.555s] Subphase: Pause Weak Roots JFRWeak 0.001 / 0.001 0.001 / 0.002 0.001 / 0.012 0.001 / 0.012 ms\n" +
"[7.555s] Subphase: Pause Weak Roots JNIWeakHandles 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[7.555s] Subphase: Pause Weak Roots JVMTIWeakExport 0.001 / 0.001 0.001 / 0.001 0.001 / 0.008 0.001 / 0.008 ms\n" +
"[7.555s] Subphase: Pause Weak Roots Setup 0.000 / 0.000 0.000 / 0.000 0.000 / 0.001 0.000 / 0.001 ms\n" +
"[7.555s] Subphase: Pause Weak Roots StringTable 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[7.555s] Subphase: Pause Weak Roots SymbolTable 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[7.555s] Subphase: Pause Weak Roots Teardown 0.001 / 0.001 0.001 / 0.001 0.001 / 0.015 0.001 / 0.015 ms\n" +
"[7.555s] Subphase: Pause Weak Roots VMWeakHandles 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[7.555s] System: Java Threads 911 / 911 910 / 911 901 / 913 901 / 913 threads\n" +
"[7.555s] =========================================================================================================================================================\n" +
"[7.777s] Allocation Stall (ThreadPoolTaskScheduler-1) 0.204ms\n" +
"[7.888s] Allocation Stall (NioProcessor-2) 0.391ms\n" +
"[7.889s] Out Of Memory (thread 8)";
UnifiedZGCLogParser parser = (UnifiedZGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
ZGCModel model = (ZGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 1);
GCEvent gc = model.getGcEvents().get(0);
Assert.assertEquals(gc.getGcid(), 374);
Assert.assertEquals(gc.getStartTime(), 7000, DELTA);
Assert.assertEquals(gc.getEndTime(), 7356, DELTA);
Assert.assertEquals(gc.getDuration(), 356, DELTA);
Assert.assertEquals(gc.getEventType(), GCEventType.ZGC_GARBAGE_COLLECTION);
Assert.assertEquals(gc.getCause(), PROACTIVE);
Assert.assertEquals(gc.getLastPhaseOfType(GCEventType.ZGC_PAUSE_MARK_START).getEndTime(), 7006, DELTA);
Assert.assertEquals(gc.getLastPhaseOfType(GCEventType.ZGC_PAUSE_MARK_START).getDuration(), 4.459, DELTA);
Assert.assertEquals(gc.getMemoryItem(METASPACE).getPostCapacity(), 128 * 1024 * 1024);
Assert.assertEquals(gc.getMemoryItem(METASPACE).getPostUsed(), 125 * 1024 * 1024);
Assert.assertEquals(gc.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 5614L * 1024 * 1024, 40960L * 1024 * 1024, 1454 * 1024 * 1024, 40960L * 1024 * 1024));
Assert.assertEquals(gc.getAllocation(), 202 * 1024 * 1024);
Assert.assertEquals(gc.getReclamation(), 4200L * 1024 * 1024);
List<ZGCModel.ZStatistics> statistics = model.getStatistics();
Assert.assertEquals(statistics.size(), 1);
Assert.assertEquals(72, statistics.get(0).getStatisticItems().size());
Assert.assertEquals(statistics.get(0).getStartTime(), 7555, DELTA);
Assert.assertEquals(statistics.get(0).get("System: Java Threads threads").getMax10s(), 911, DELTA);
Assert.assertEquals(statistics.get(0).get("System: Java Threads threads").getMax10h(), 913, DELTA);
List<GCEvent> allocationStalls = model.getAllocationStalls();
Assert.assertEquals(allocationStalls.size(), 2);
Assert.assertEquals(allocationStalls.get(1).getEndTime(), 7888, DELTA);
Assert.assertEquals(allocationStalls.get(1).getDuration(), 0.391, DELTA);
Assert.assertEquals(((ThreadEvent) (allocationStalls.get(1))).getThreadName(), "NioProcessor-2");
Assert.assertEquals(model.getOoms().size(), 1);
ThreadEvent oom = model.getOoms().get(0);
Assert.assertEquals(oom.getStartTime(), 7889, DELTA);
Assert.assertEquals(oom.getThreadName(), "thread 8");
}
@Test
public void testJDK8CMSParser() throws Exception {
String log =
"OpenJDK 64-Bit Server VM (25.212-b469) for linux-amd64 JRE (1.8.0_212-b469), built on Jun 16 2019 15:54:49 by \"admin\" with gcc 4.8.2\n" +
"Memory: 4k page, physical 8388608k(5632076k free), swap 0k(0k free)\n" +
"610.956: [Full GC (Heap Dump Initiated GC) 610.956: [CMS[YG occupancy: 1212954 K (1843200 K)]611.637: [weak refs processing, 0.0018945 secs]611.639: [class unloading, 0.0454119 secs]611.684: [scrub symbol table, 0.0248340 secs]611.709: [scrub string table, 0.0033967 secs]: 324459K->175339K(3072000K), 1.0268069 secs] 1537414K->1388294K(4915200K), [Metaspace: 114217K->113775K(1153024K)], 1.0277002 secs] [Times: user=1.71 sys=0.05, real=1.03 secs]\n" +
"674.686: [GC (Allocation Failure) 674.687: [ParNew: 1922432K->174720K(1922432K), 0.1691241 secs] 3557775K->1858067K(4019584K), 0.1706065 secs] [Times: user=0.54 sys=0.04, real=0.17 secs]\n" +
"675.110: Total time for which application threads were stopped: 0.0001215 seconds, Stopping threads took: 0.0000271 seconds\n" +
"675.111: Application time: 0.0170944 seconds\n" +
"675.164: [GC (CMS Initial Mark) [1 CMS-initial-mark: 1683347K(2097152K)] 1880341K(4019584K), 0.0714398 secs] [Times: user=0.19 sys=0.05, real=0.07 secs]" +
"675.461: [CMS-concurrent-mark-start]\n" +
"705.287: [GC (Allocation Failure) 705.288: [ParNew: 1922432K->174720K(1922432K), 0.2481441 secs] 3680909K->2051729K(4019584K), 0.2502404 secs] [Times: user=0.93 sys=0.10, real=0.25 secs]\n" +
"709.876: [CMS-concurrent-mark: 17.528/34.415 secs] [Times: user=154.39 sys=4.20, real=34.42 secs]\n" +
"709.959: [CMS-concurrent-preclean-start]\n" +
"710.570: [CMS-concurrent-preclean: 0.576/0.611 secs] [Times: user=3.08 sys=0.05, real=0.69 secs]\n" +
"710.571: [CMS-concurrent-abortable-preclean-start]\n" +
"715.691: [GC (Allocation Failure) 715.692: [ParNew: 1922432K->174720K(1922432K), 0.1974709 secs] 3799441K->2119132K(4019584K), 0.1992381 secs] [Times: user=0.61 sys=0.04, real=0.20 secs]\n" +
"717.759: [CMS-concurrent-abortable-preclean: 5.948/7.094 secs] [Times: user=32.21 sys=0.66, real=7.19 secs]\n" +
"717.792: [GC (CMS Final Remark) [YG occupancy: 438765 K (1922432 K)]717.792: [Rescan (parallel) , 0.1330457 secs]717.925: [weak refs processing, 0.0007103 secs]717.926: [class unloading, 0.2074917 secs]718.134: [scrub symbol table, 0.0751664 secs]718.209: [scrub string table, 0.0137015 secs][1 CMS-remark: 1944412K(2097152K)] 2383178K(4019584K), 0.4315000 secs] [Times: user=0.77 sys=0.01, real=0.43 secs]\n" +
"718.226: [CMS-concurrent-sweep-start]\n" +
"724.991: [GC (Allocation Failure) 724.992: [ParNew: 1922432K->174720K(1922432K), 0.2272846 secs] 3377417K->1710595K(4019584K), 0.2289948 secs] [Times: user=0.70 sys=0.01, real=0.23 secs]\n" +
"728.865: [CMS-concurrent-sweep: 8.279/10.639 secs] [Times: user=48.12 sys=1.21, real=10.64 secs]\n" +
"731.570: [CMS-concurrent-reset-start]\n" +
"731.806: [CMS-concurrent-reset: 0.205/0.237 secs] [Times: user=1.43 sys=0.04, real=0.34 secs]\n" +
"778.294: [GC (Allocation Failure) 778.295: [ParNew: 1922432K->163342K(1922432K), 0.2104952 secs] 3570857K->1917247K(4019584K), 0.2120639 secs] [Times: user=0.63 sys=0.00, real=0.21 secs]\n" +
"778.534: [GC (CMS Initial Mark) [1 CMS-initial-mark: 1753905K(2097152K)] 1917298K(4019584K), 0.0645754 secs] [Times: user=0.20 sys=0.01, real=0.06 secs]\n" +
"778.601: [CMS-concurrent-mark-start]\n" +
"792.762: [CMS-concurrent-mark: 11.404/14.161 secs] [Times: user=61.30 sys=2.27, real=14.17 secs]\n" +
"792.763: [CMS-concurrent-preclean-start]\n" +
"795.862: [CMS-concurrent-preclean: 2.148/3.100 secs] [Times: user=12.43 sys=0.91, real=3.10 secs]\n" +
"795.864: [CMS-concurrent-abortable-preclean-start]\n" +
"795.864: [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.03 sys=0.00, real=0.00 secs]\n" +
"795.886: [GC (CMS Final Remark) [YG occupancy: 1619303 K (1922432 K)]795.887: [Rescan (parallel) , 0.2995817 secs]796.186: [weak refs processing, 0.0001985 secs]796.187: [class unloading, 0.1856105 secs]796.372: [scrub symbol table, 0.0734544 secs]796.446: [scrub string table, 0.0079670 secs][1 CMS-remark: 2048429K(2097152K)] 3667732K(4019584K), 0.5676600 secs] [Times: user=1.34 sys=0.01, real=0.57 secs]\n" +
"796.456: [CMS-concurrent-sweep-start]\n" +
"796.991: [GC (Allocation Failure) 796.992: [ParNew: 1922432K->1922432K(1922432K), 0.0000267 secs]796.992: [CMS797.832: [CMS-concurrent-sweep: 1.180/1.376 secs] [Times: user=3.42 sys=0.14, real=1.38 secs]\n" +
" (concurrent mode failure): 2034154K->1051300K(2097152K), 4.6146919 secs] 3956586K->1051300K(4019584K), [Metaspace: 296232K->296083K(1325056K)], 4.6165192 secs] [Times: user=4.60 sys=0.05, real=4.62 secs]\n" +
"813.396: [GC (Allocation Failure) 813.396: [ParNew813.404: [SoftReference, 4 refs, 0.0000260 secs]813.405: [WeakReference, 59 refs, 0.0000110 secs]813.406: [FinalReference, 1407 refs, 0.0025979 secs]813.407: [PhantomReference, 11 refs, 10 refs, 0.0000131 secs]813.408: [JNI Weak Reference, 0.0000088 secs]: 69952K->8704K(78656K), 0.0104509 secs] 69952K->11354K(253440K), 0.0105137 secs] [Times: user=0.04 sys=0.01, real=0.01 secs]\n";
PreUnifiedGenerationalGCLogParser parser = (PreUnifiedGenerationalGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
CMSGCModel model = (CMSGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 10);
Assert.assertEquals(model.getSafepoints().size(), 1);
Safepoint safepoint = model.getSafepoints().get(0);
Assert.assertEquals(safepoint.getStartTime(), 675110 - 0.1215, DELTA);
Assert.assertEquals(safepoint.getDuration(), 0.1215, DELTA);
Assert.assertEquals(safepoint.getTimeToEnter(), 0.0271, DELTA);
GCEvent fullgc = model.getGcEvents().get(0);
Assert.assertEquals(fullgc.getStartTime(), 610956, DELTA);
Assert.assertEquals(fullgc.getDuration(), 1027.7002, DELTA);
Assert.assertEquals(fullgc.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullgc.getCause(), HEAP_DUMP);
Assert.assertEquals(fullgc.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 114217 * 1024, 113775 * 1024, 1153024 * 1024));
Assert.assertEquals(fullgc.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 1537414 * 1024, 1388294 * 1024, 4915200L * 1024));
Assert.assertEquals(fullgc.getMemoryItem(OLD), new GCMemoryItem(OLD, 324459 * 1024, 175339 * 1024, 3072000L * 1024));
Assert.assertEquals(fullgc.getPhases().size(), 4);
Assert.assertEquals(fullgc.getLastPhaseOfType(GCEventType.WEAK_REFS_PROCESSING).getStartTime(), 611637, DELTA);
Assert.assertEquals(fullgc.getLastPhaseOfType(GCEventType.WEAK_REFS_PROCESSING).getDuration(), 1.8945, DELTA);
Assert.assertEquals(fullgc.getCpuTime().getUser(), 1710, DELTA);
Assert.assertEquals(fullgc.getCpuTime().getSys(), 50, DELTA);
Assert.assertEquals(fullgc.getCpuTime().getReal(), 1030, DELTA);
fullgc = model.getGcEvents().get(8);
Assert.assertEquals(fullgc.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullgc.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 3956586L * 1024, 1051300 * 1024, 4019584L * 1024));
GCEvent youngGC = model.getGcEvents().get(9);
Assert.assertEquals(youngGC.getStartTime(), 813396, DELTA);
Assert.assertEquals(youngGC.getDuration(), 10.5137, DELTA);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(youngGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 69952 * 1024, 11354 * 1024, 253440 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 69952 * 1024, 8704 * 1024, 78656 * 1024));
Assert.assertNull(youngGC.getPhases());
Assert.assertEquals(youngGC.getReferenceGC().getSoftReferenceStartTime(), 813404, DELTA);
Assert.assertEquals(youngGC.getReferenceGC().getSoftReferencePauseTime(), 0.0260, DELTA);
Assert.assertEquals(youngGC.getReferenceGC().getSoftReferenceCount(), 4);
Assert.assertEquals(youngGC.getReferenceGC().getWeakReferenceStartTime(), 813405, DELTA);
Assert.assertEquals(youngGC.getReferenceGC().getWeakReferencePauseTime(), 0.0110, DELTA);
Assert.assertEquals(youngGC.getReferenceGC().getWeakReferenceCount(), 59);
Assert.assertEquals(youngGC.getReferenceGC().getFinalReferenceStartTime(), 813406, DELTA);
Assert.assertEquals(youngGC.getReferenceGC().getFinalReferencePauseTime(), 2.5979, DELTA);
Assert.assertEquals(youngGC.getReferenceGC().getFinalReferenceCount(), 1407);
Assert.assertEquals(youngGC.getReferenceGC().getPhantomReferenceStartTime(), 813407, DELTA);
Assert.assertEquals(youngGC.getReferenceGC().getPhantomReferencePauseTime(), 0.0131, DELTA);
Assert.assertEquals(youngGC.getReferenceGC().getPhantomReferenceCount(), 11);
Assert.assertEquals(youngGC.getReferenceGC().getPhantomReferenceFreedCount(), 10);
Assert.assertEquals(youngGC.getReferenceGC().getJniWeakReferenceStartTime(), 813408, DELTA);
Assert.assertEquals(youngGC.getReferenceGC().getJniWeakReferencePauseTime(), 0.0088, DELTA);
Assert.assertEquals(youngGC.getCpuTime().getUser(), 40, DELTA);
Assert.assertEquals(youngGC.getCpuTime().getSys(), 10, DELTA);
Assert.assertEquals(youngGC.getCpuTime().getReal(), 10, DELTA);
GCEvent cms = model.getGcEvents().get(2);
Assert.assertEquals(cms.getEventType(), GCEventType.CMS_CONCURRENT_MARK_SWEPT);
Assert.assertEquals(cms.getStartTime(), 675164, DELTA);
Assert.assertEquals(cms.getPhases().size(), 12, DELTA);
for (GCEvent phase : cms.getPhases()) {
Assert.assertTrue(phase.getStartTime() != UNKNOWN_DOUBLE);
Assert.assertTrue(phase.getDuration() != UNKNOWN_DOUBLE);
}
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_INITIAL_MARK).getStartTime(), 675164, DELTA);
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_CONCURRENT_MARK).getDuration(), 34415, DELTA);
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_CONCURRENT_MARK).getCpuTime().getUser(), 154390, DELTA);
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_FINAL_REMARK).getCpuTime().getUser(), 770, DELTA);
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_FINAL_REMARK).getDuration(), 431.5, DELTA);
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_CONCURRENT_RESET).getDuration(), 237, DELTA);
}
@Test
public void testJDK8CMSCPUTime() throws Exception {
String log = "2022-11-28T14:57:05.217+0800: 6.216: [GC (CMS Initial Mark) [1 CMS-initial-mark: 0K(3584000K)] 619320K(5519360K), 0.1236090 secs] [Times: user=0.08 sys=0.08, real=0.13 secs] \n" +
"2022-11-28T14:57:05.341+0800: 6.340: [CMS-concurrent-mark-start]\n" +
"2022-11-28T14:57:05.342+0800: 6.340: [CMS-concurrent-mark: 0.001/0.001 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] \n" +
"2022-11-28T14:57:05.342+0800: 6.340: [CMS-concurrent-preclean-start]\n" +
"2022-11-28T14:57:05.347+0800: 6.345: [CMS-concurrent-preclean: 0.005/0.005 secs] [Times: user=0.01 sys=0.00, real=0.03 secs] \n" +
"2022-11-28T14:57:05.347+0800: 6.346: [CMS-concurrent-abortable-preclean-start]\n" +
"2022-11-28T14:57:09.974+0800: 10.973: [GC (Allocation Failure) 2022-11-28T14:57:09.974+0800: 10.973: [ParNew2022-11-28T14:57:09.997+0800: 10.996: [CMS-concurrent-abortable-preclean: 0.335/4.650 secs] [Times: user=10.64 sys=0.72, real=4.65 secs] \n" +
": 1720320K->36032K(1935360K), 0.0395605 secs] 1720320K->36032K(5519360K), 0.0397919 secs] [Times: user=0.18 sys=0.03, real=0.05 secs] \n" +
"2022-11-28T14:57:10.015+0800: 11.013: [GC (CMS Final Remark) [YG occupancy: 70439 K (1935360 K)]2022-11-28T14:57:10.015+0800: 11.013: [Rescan (parallel) , 0.0049504 secs]2022-11-28T14:57:10.020+0800: 11.018: [weak refs processing, 0.0001257 secs]2022-11-28T14:57:10.020+0800: 11.018: [class unloading, 0.0154147 secs]2022-11-28T14:57:10.035+0800: 11.034: [scrub symbol table, 0.0077166 secs]2022-11-28T14:57:10.043+0800: 11.042: [scrub string table, 0.0006843 secs][1 CMS-remark: 0K(3584000K)] 70439K(5519360K), 0.0301977 secs] [Times: user=0.15 sys=0.00, real=0.03 secs] \n" +
"2022-11-28T14:57:10.046+0800: 11.044: [CMS-concurrent-sweep-start]\n" +
"2022-11-28T14:57:10.046+0800: 11.044: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.02 secs] \n" +
"2022-11-28T14:57:10.047+0800: 11.045: [CMS-concurrent-reset-start]\n" +
"2022-11-28T14:57:10.074+0800: 11.072: [CMS-concurrent-reset: 0.027/0.027 secs] [Times: user=0.25 sys=0.04, real=0.04 secs] ";
PreUnifiedGenerationalGCLogParser parser = (PreUnifiedGenerationalGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
CMSGCModel model = (CMSGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getLastEventOfType(GCEventType.CMS_INITIAL_MARK).getCpuTime().getReal(),130, DELTA);
Assert.assertEquals(model.getLastEventOfType(GCEventType.CMS_CONCURRENT_MARK).getCpuTime().getUser(),10, DELTA);
Assert.assertEquals(model.getLastEventOfType(GCEventType.CMS_CONCURRENT_PRECLEAN).getCpuTime().getReal(),30, DELTA);
Assert.assertEquals(model.getLastEventOfType(GCEventType.CMS_CONCURRENT_ABORTABLE_PRECLEAN).getCpuTime().getReal(),4650, DELTA);
Assert.assertEquals(model.getLastEventOfType(GCEventType.CMS_FINAL_REMARK).getCpuTime().getReal(),30, DELTA);
Assert.assertEquals(model.getLastEventOfType(GCEventType.CMS_CONCURRENT_SWEEP).getCpuTime().getReal(),20, DELTA);
Assert.assertEquals(model.getLastEventOfType(GCEventType.CMS_CONCURRENT_RESET).getCpuTime().getReal(),40, DELTA);
Assert.assertEquals(model.getLastEventOfType(GCEventType.YOUNG_GC).getCpuTime().getReal(),50, DELTA);
}
@Test
public void testJDK8G1GCParser() throws Exception {
String log = "3.960: [GC pause (G1 Evacuation Pause) (young)4.000: [SoftReference, 0 refs, 0.0000435 secs]4.000: [WeakReference, 374 refs, 0.0002082 secs]4.001: [FinalReference, 5466 refs, 0.0141707 secs]4.015: [PhantomReference, 0 refs, 0 refs, 0.0000253 secs]4.015: [JNI Weak Reference, 0.0000057 secs], 0.0563085 secs]\n" +
" [Parallel Time: 39.7 ms, GC Workers: 4]\n" +
" [GC Worker Start (ms): Min: 3959.8, Avg: 3959.9, Max: 3960.1, Diff: 0.2]\n" +
" [Ext Root Scanning (ms): Min: 2.6, Avg: 10.1, Max: 17.9, Diff: 15.2, Sum: 40.4]\n" +
" [Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]\n" +
" [Processed Buffers: Min: 0, Avg: 0.0, Max: 0, Diff: 0, Sum: 0]\n" +
" [Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]\n" +
" [Code Root Scanning (ms): Min: 0.0, Avg: 0.5, Max: 2.1, Diff: 2.1, Sum: 2.1]\n" +
" [Object Copy (ms): Min: 18.1, Avg: 26.2, Max: 33.7, Diff: 15.6, Sum: 104.9]\n" +
" [Termination (ms): Min: 0.0, Avg: 1.5, Max: 3.5, Diff: 3.5, Sum: 6.2]\n" +
" [Termination Attempts: Min: 1, Avg: 21.8, Max: 51, Diff: 50, Sum: 87]\n" +
" [GC Worker Other (ms): Min: 0.0, Avg: 0.1, Max: 0.1, Diff: 0.0, Sum: 0.2]\n" +
" [GC Worker Total (ms): Min: 38.0, Avg: 38.5, Max: 39.5, Diff: 1.5, Sum: 153.8]\n" +
" [GC Worker End (ms): Min: 3998.0, Avg: 3998.4, Max: 3999.4, Diff: 1.4]\n" +
" [Code Root Fixup: 0.2 ms]\n" +
" [Code Root Purge: 0.2 ms]\n" +
" [Clear CT: 0.2 ms]\n" +
" [Other: 16.0 ms]\n" +
" [Choose CSet: 0.0 ms]\n" +
" [Ref Proc: 15.1 ms]\n" +
" [Ref Enq: 0.2 ms]\n" +
" [Redirty Cards: 0.1 ms]\n" +
" [Humongous Register: 0.0 ms]\n" +
" [Humongous Reclaim: 0.0 ms]\n" +
" [Free CSet: 0.3 ms]\n" +
" [Eden: 184.0M(184.0M)->0.0B(160.0M) Survivors: 0.0B->24.0M Heap: 184.0M(3800.0M)->19.3M(3800.0M)]\n" +
" [Times: user=0.07 sys=0.01, real=0.06 secs]\n" +
"4.230: [GC concurrent-root-region-scan-start]\n" +
"4.391: [GC concurrent-root-region-scan-end, 0.1608430 secs]\n" +
"4.391: [GC concurrent-mark-start]\n" +
"7.101: [GC concurrent-mark-reset-for-overflow]\n" +
"19.072: [GC concurrent-mark-end, 14.6803750 secs]\n" +
"19.078: [GC remark 19.078: [Finalize Marking, 0.1774665 secs] 19.255: [GC ref-proc, 0.1648116 secs] 19.420: [Unloading, 0.1221964 secs], 0.4785858 secs]\n" +
" [Times: user=1.47 sys=0.31, real=0.48 secs]\n" +
"19.563: [GC cleanup 11G->9863M(20G), 0.0659638 secs]\n" +
" [Times: user=0.20 sys=0.01, real=0.07 secs]\n" +
"19.630: [GC concurrent-cleanup-start]\n" +
"19.631: [GC concurrent-cleanup-end, 0.0010377 secs]\n" +
"23.346: [Full GC (Metadata GC Threshold) 7521M->7002M(46144M), 1.9242692 secs]\n" +
" [Eden: 0.0B(1760.0M)->0.0B(2304.0M) Survivors: 544.0M->0.0B Heap: 7521.7M(46144.0M)->7002.8M(46144.0M)], [Metaspace: 1792694K->291615K(698368K)]\n" +
" [Times: user=2.09 sys=0.19, real=1.92 secs]\n" +
"79.619: [GC pause (G1 Evacuation Pause) (mixed)79.636: [SoftReference, 1 refs, 0.0000415 secs]79.636: [WeakReference, 2 refs, 0.0000061 secs]79.636: [FinalReference, 3 refs, 0.0000049 secs]79.636: [PhantomReference, 4 refs, 5 refs, 0.0000052 secs]79.636: [JNI Weak Reference, 0.0000117 secs] (to-space exhausted), 0.0264971 secs]\n" +
" [Parallel Time: 20.5 ms, GC Workers: 4]\n" +
" [GC Worker Start (ms): Min: 1398294.3, Avg: 1398294.4, Max: 1398294.5, Diff: 0.2]\n" +
" [Ext Root Scanning (ms): Min: 1.8, Avg: 2.0, Max: 2.2, Diff: 0.4, Sum: 15.7]\n" +
" [Update RS (ms): Min: 1.2, Avg: 1.5, Max: 1.7, Diff: 0.5, Sum: 11.8]\n" +
" [Processed Buffers: Min: 21, Avg: 27.0, Max: 30, Diff: 9, Sum: 216]\n" +
" [Scan RS (ms): Min: 1.8, Avg: 1.9, Max: 2.2, Diff: 0.4, Sum: 15.5]\n" +
" [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]\n" +
" [Object Copy (ms): Min: 14.5, Avg: 14.7, Max: 14.9, Diff: 0.4, Sum: 118.0]\n" +
" [Termination (ms): Min: 0.0, Avg: 0.1, Max: 0.1, Diff: 0.1, Sum: 0.5]\n" +
" [Termination Attempts: Min: 1, Avg: 148.2, Max: 181, Diff: 180, Sum: 1186]\n" +
" [GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.1, Diff: 0.0, Sum: 0.3]\n" +
" [GC Worker Total (ms): Min: 20.1, Avg: 20.2, Max: 20.3, Diff: 0.2, Sum: 161.9]\n" +
" [GC Worker End (ms): Min: 1398314.7, Avg: 1398314.7, Max: 1398314.7, Diff: 0.0]\n" +
" [Code Root Fixup: 0.0 ms]\n" +
" [Code Root Purge: 0.0 ms]\n" +
" [Clear CT: 0.5 ms]\n" +
" [Other: 10.4 ms]\n" +
" [Choose CSet: 0.0 ms]\n" +
" [Ref Proc: 8.8 ms]\n" +
" [Ref Enq: 0.3 ms]\n" +
" [Redirty Cards: 0.2 ms]\n" +
" [Free CSet: 0.1 ms]\n" +
" [Eden: 2304.0M(2304.0M)->0.0B(2304.0M) Survivors: 192.0M->192.0M Heap: 15.0G(19.8G)->12.8G(19.8G)]\n" +
" [Times: user=0.17 sys=0.00, real=0.03 secs]";
PreUnifiedG1GCLogParser parser = (PreUnifiedG1GCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
G1GCModel model = (G1GCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 4);
Assert.assertEquals(model.getParallelThread(), 4);
GCEvent youngGC = model.getGcEvents().get(0);
Assert.assertEquals(youngGC.getStartTime(), 3960, DELTA);
Assert.assertEquals(youngGC.getDuration(), 56.3085, DELTA);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getCause(), G1_EVACUATION_PAUSE);
Assert.assertEquals(youngGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 184 * 1024 * 1024, 3800L * 1024 * 1024, (int) (19.3 * 1024 * 1024), 3800L * 1024 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(EDEN), new GCMemoryItem(EDEN, 184 * 1024 * 1024, 184 * 1024 * 1024, 0, 160 * 1024 * 1024));
Assert.assertNotNull(youngGC.getPhases());
for (GCEvent phase : youngGC.getPhases()) {
Assert.assertTrue(phase.getDuration() != UNKNOWN_DOUBLE);
}
Assert.assertEquals(youngGC.getLastPhaseOfType(GCEventType.G1_GC_REFPROC).getDuration(), 15.1, DELTA);
Assert.assertEquals(youngGC.getLastPhaseOfType(GCEventType.G1_CODE_ROOT_SCANNING).getDuration(), 0.5, DELTA);
Assert.assertEquals(youngGC.getReferenceGC().getSoftReferenceStartTime(), 4000, DELTA);
Assert.assertEquals(youngGC.getReferenceGC().getJniWeakReferencePauseTime(), 0.0057, DELTA);
Assert.assertEquals(youngGC.getCpuTime().getUser(), 70, DELTA);
Assert.assertEquals(youngGC.getCpuTime().getSys(), 10, DELTA);
Assert.assertEquals(youngGC.getCpuTime().getReal(), 60, DELTA);
GCEvent concurrentCycle = model.getGcEvents().get(1);
Assert.assertEquals(concurrentCycle.getStartTime(), 4230, DELTA);
Assert.assertEquals(concurrentCycle.getPhases().size(), 9);
for (GCEvent phase : concurrentCycle.getPhases()) {
if (phase.getEventType() != GCEventType.G1_CONCURRENT_MARK_RESET_FOR_OVERFLOW) {
Assert.assertTrue(phase.getDuration() != UNKNOWN_DOUBLE);
}
Assert.assertTrue(phase.getStartTime() != UNKNOWN_DOUBLE);
}
Assert.assertEquals(concurrentCycle.getLastPhaseOfType(GCEventType.G1_CONCURRENT_SCAN_ROOT_REGIONS).getStartTime(), 4230, DELTA);
Assert.assertEquals(concurrentCycle.getLastPhaseOfType(GCEventType.G1_CONCURRENT_SCAN_ROOT_REGIONS).getDuration(), 160.8430, DELTA);
Assert.assertEquals(concurrentCycle.getLastPhaseOfType(GCEventType.G1_REMARK).getStartTime(), 19078, DELTA);
Assert.assertEquals(concurrentCycle.getLastPhaseOfType(GCEventType.G1_REMARK).getDuration(), 478.5858, DELTA);
Assert.assertEquals(concurrentCycle.getLastPhaseOfType(GCEventType.G1_PAUSE_CLEANUP).getMemoryItem(HEAP).getPostUsed(), 9863L * 1024 * 1024, DELTA);
Assert.assertEquals(concurrentCycle.getLastPhaseOfType(GCEventType.G1_REMARK).getCpuTime().getUser(), 1470, DELTA);
Assert.assertEquals(concurrentCycle.getLastPhaseOfType(GCEventType.G1_PAUSE_CLEANUP).getCpuTime().getSys(), 10, DELTA);
GCEvent fullGC = model.getGcEvents().get(2);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getStartTime(), 23346, DELTA);
Assert.assertEquals(fullGC.getDuration(), 1924.2692, DELTA);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getCause(), METADATA_GENERATION_THRESHOLD);
Assert.assertEquals(fullGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 1792694 * 1024, 291615 * 1024, 698368 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, (long) (7521.7 * 1024 * 1024), (long) (46144.0 * 1024 * 1024), (long) (7002.8 * 1024 * 1024), (long) (46144.0 * 1024 * 1024)));
Assert.assertEquals(fullGC.getCpuTime().getUser(), 2090, DELTA);
Assert.assertEquals(fullGC.getCpuTime().getSys(), 190, DELTA);
Assert.assertEquals(fullGC.getCpuTime().getReal(), 1920, DELTA);
GCEvent mixedGC = model.getGcEvents().get(3);
Assert.assertEquals(mixedGC.getStartTime(), 79619, DELTA);
Assert.assertEquals(mixedGC.getDuration(), 26.4971, DELTA);
Assert.assertEquals(mixedGC.getEventType(), GCEventType.G1_MIXED_GC);
Assert.assertEquals(mixedGC.getCause(), G1_EVACUATION_PAUSE);
Assert.assertTrue(mixedGC.isTrue(TO_SPACE_EXHAUSTED));
Assert.assertEquals(mixedGC.getMemoryItem(HEAP).getPostCapacity(), (long) (19.8 * 1024 * 1024 * 1024));
Assert.assertEquals(mixedGC.getMemoryItem(EDEN).getPreUsed(), 2304L * 1024 * 1024);
Assert.assertNotNull(mixedGC.getPhases());
for (GCEvent phase : mixedGC.getPhases()) {
Assert.assertTrue(phase.getDuration() != UNKNOWN_DOUBLE);
}
GCLogMetadata metadata = model.getGcModelMetadata();
Assert.assertFalse(metadata.getImportantEventTypes().contains(GCEventType.G1_CONCURRENT_REBUILD_REMEMBERED_SETS.getName()));
Assert.assertFalse(metadata.getImportantEventTypes().contains(GCEventType.G1_CONCURRENT_UNDO_CYCLE.getName()));
}
@Test
public void testJDK8G1GCParserAdaptiveSize() throws Exception {
// although we don't read anything from options like -XX:+PrintAdaptiveSizePolicy, they should not
// affect parsing
String log = "2022-02-09T15:55:55.807+0800: 0.683: [GC pause (G1 Evacuation Pause) (young)\n" +
"Desired survivor size 3670016 bytes, new threshold 15 (max 15)\n" +
" 0.683: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 0, predicted base time: 10.00 ms, remaining time: 240.00 ms, target pause time: 250.00 ms]\n" +
" 0.683: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 51 regions, survivors: 0 regions, predicted young region time: 1298.76 ms]\n" +
" 0.683: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 51 regions, survivors: 0 regions, old: 0 regions, predicted pause time: 1308.76 ms, target pause time: 250.00 ms]\n" +
", 0.0085898 secs]\n" +
" [Parallel Time: 5.5 ms, GC Workers: 4]\n" +
" [GC Worker Start (ms): Min: 682.6, Avg: 682.6, Max: 682.7, Diff: 0.0]\n" +
" [Ext Root Scanning (ms): Min: 0.8, Avg: 1.2, Max: 1.6, Diff: 0.8, Sum: 4.8]\n" +
" [Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]\n" +
" [Processed Buffers: Min: 0, Avg: 0.0, Max: 0, Diff: 0, Sum: 0]\n" +
" [Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]\n" +
" [Code Root Scanning (ms): Min: 0.0, Avg: 0.2, Max: 0.9, Diff: 0.9, Sum: 0.9]\n" +
" [Object Copy (ms): Min: 3.5, Avg: 3.9, Max: 4.5, Diff: 1.0, Sum: 15.7]\n" +
" [Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]\n" +
" [Termination Attempts: Min: 1, Avg: 6.8, Max: 9, Diff: 8, Sum: 27]\n" +
" [GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]\n" +
" [GC Worker Total (ms): Min: 5.4, Avg: 5.4, Max: 5.4, Diff: 0.0, Sum: 21.6]\n" +
" [GC Worker End (ms): Min: 688.1, Avg: 688.1, Max: 688.1, Diff: 0.0]\n" +
" [Code Root Fixup: 0.0 ms]\n" +
" [Code Root Purge: 0.0 ms]\n" +
" [Clear CT: 0.1 ms]\n" +
" [Other: 3.0 ms]\n" +
" [Choose CSet: 0.0 ms]\n" +
" [Ref Proc: 2.6 ms]\n" +
" [Ref Enq: 0.0 ms]\n" +
" [Redirty Cards: 0.1 ms]\n" +
" [Humongous Register: 0.0 ms]\n" +
" [Humongous Reclaim: 0.0 ms]\n" +
" [Free CSet: 0.1 ms]\n" +
" [Eden: 52224.0K(52224.0K)->0.0B(45056.0K) Survivors: 0.0B->7168.0K Heap: 52224.0K(1024.0M)->8184.0K(1024.0M)]\n" +
" [Times: user=0.02 sys=0.01, real=0.01 secs] ";
PreUnifiedG1GCLogParser parser = (PreUnifiedG1GCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
G1GCModel model = (G1GCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 1);
GCEvent youngGC = model.getGcEvents().get(0);
Assert.assertEquals(youngGC.getStartTime(), 683, DELTA);
Assert.assertEquals(youngGC.getDuration(), 8.5898, DELTA);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getCause(), G1_EVACUATION_PAUSE);
Assert.assertEquals(youngGC.getMemoryItem(HEAP).getPreUsed(), 52224 * 1024);
}
@Test
public void testJDK11SerialGCParser() throws Exception {
String log = "[0.486s][info][gc,start ] GC(0) Pause Young (Allocation Failure)\n" +
"[0.511s][info][gc,heap ] GC(0) DefNew: 69952K->8704K(78656K)\n" +
"[0.511s][info][gc,heap ] GC(0) Tenured: 0K->24185K(174784K)\n" +
"[0.511s][info][gc,metaspace ] GC(0) Metaspace: 6529K->6519K(1056768K)\n" +
"[0.511s][info][gc ] GC(0) Pause Young (Allocation Failure) 68M->32M(247M) 25.164ms\n" +
"[0.511s][info][gc,cpu ] GC(0) User=0.02s Sys=0.00s Real=0.02s\n" +
"[5.614s][info][gc,start ] GC(1) Pause Full (Allocation Failure)\n" +
"[5.614s][info][gc,phases,start] GC(1) Phase 1: Mark live objects\n" +
"[5.662s][info][gc,phases ] GC(1) Phase 1: Mark live objects 47.589ms\n" +
"[5.662s][info][gc,phases,start] GC(1) Phase 2: Compute new object addresses\n" +
"[5.688s][info][gc,phases ] GC(1) Phase 2: Compute new object addresses 26.097ms\n" +
"[5.688s][info][gc,phases,start] GC(1) Phase 3: Adjust pointers\n" +
"[5.743s][info][gc,phases ] GC(1) Phase 3: Adjust pointers 55.459ms\n" +
"[5.743s][info][gc,phases,start] GC(1) Phase 4: Move objects\n" +
"[5.760s][info][gc,phases ] GC(1) Phase 4: Move objects 17.259ms\n" +
"[5.761s][info][gc ] GC(1) Pause Full (Allocation Failure) 215M->132M(247M) 146.617ms";
UnifiedGenerationalGCLogParser parser = (UnifiedGenerationalGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
SerialGCModel model = (SerialGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 2);
GCEvent youngGC = model.getGcEvents().get(0);
Assert.assertEquals(youngGC.getGcid(), 0);
Assert.assertEquals(youngGC.getStartTime(), 486, DELTA);
Assert.assertEquals(youngGC.getDuration(), 25.164, DELTA);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(youngGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 69952 * 1024, 8704 * 1024, 78656 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 0, 24185 * 1024, 174784 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 6529 * 1024, 6519 * 1024, 1056768 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 68 * 1024 * 1024, 32 * 1024 * 1024, 247 * 1024 * 1024));
Assert.assertEquals(youngGC.getCpuTime().getReal(), 20, DELTA);
GCEvent fullGC = model.getGcEvents().get(1);
Assert.assertEquals(fullGC.getGcid(), 1);
Assert.assertEquals(fullGC.getStartTime(), 5614, DELTA);
Assert.assertEquals(fullGC.getDuration(), 146.617, DELTA);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(fullGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 215 * 1024 * 1024, 132 * 1024 * 1024, 247 * 1024 * 1024));
Assert.assertEquals(fullGC.getPhases().size(), 4);
for (GCEvent phase : fullGC.getPhases()) {
Assert.assertTrue(phase.getStartTime() != UNKNOWN_DOUBLE);
Assert.assertTrue(phase.getDuration() != UNKNOWN_DOUBLE);
}
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.SERIAL_COMPUTE_NEW_OBJECT_ADDRESSES).getDuration(), 26.097, DELTA);
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.SERIAL_MOVE_OBJECTS).getDuration(), 17.259, DELTA);
}
@Test
public void testJDK11ParallelGCParser() throws Exception {
String log = "[0.455s][info][gc,start ] GC(0) Pause Young (Allocation Failure)\n" +
"[0.466s][info][gc,heap ] GC(0) PSYoungGen: 65536K->10720K(76288K)\n" +
"[0.466s][info][gc,heap ] GC(0) ParOldGen: 0K->20800K(175104K)\n" +
"[0.466s][info][gc,metaspace ] GC(0) Metaspace: 6531K->6531K(1056768K)\n" +
"[0.466s][info][gc ] GC(0) Pause Young (Allocation Failure) 64M->30M(245M) 11.081ms\n" +
"[0.466s][info][gc,cpu ] GC(0) User=0.03s Sys=0.02s Real=0.01s\n" +
"[2.836s][info][gc,start ] GC(1) Pause Full (Ergonomics)\n" +
"[2.836s][info][gc,phases,start] GC(1) Marking Phase\n" +
"[2.857s][info][gc,phases ] GC(1) Marking Phase 21.145ms\n" +
"[2.857s][info][gc,phases,start] GC(1) Summary Phase\n" +
"[2.857s][info][gc,phases ] GC(1) Summary Phase 0.006ms\n" +
"[2.857s][info][gc,phases,start] GC(1) Adjust Roots\n" +
"[2.859s][info][gc,phases ] GC(1) Adjust Roots 1.757ms\n" +
"[2.859s][info][gc,phases,start] GC(1) Compaction Phase\n" +
"[2.881s][info][gc,phases ] GC(1) Compaction Phase 22.465ms\n" +
"[2.881s][info][gc,phases,start] GC(1) Post Compact\n" +
"[2.882s][info][gc,phases ] GC(1) Post Compact 1.054ms\n" +
"[2.882s][info][gc,heap ] GC(1) PSYoungGen: 10729K->0K(76288K)\n" +
"[2.882s][info][gc,heap ] GC(1) ParOldGen: 141664K->94858K(175104K)\n" +
"[2.882s][info][gc,metaspace ] GC(1) Metaspace: 7459K->7459K(1056768K)\n" +
"[2.882s][info][gc ] GC(1) Pause Full (Ergonomics) 148M->92M(245M) 46.539ms\n" +
"[2.882s][info][gc,cpu ] GC(1) User=0.17s Sys=0.00s Real=0.05s";
UnifiedGenerationalGCLogParser parser = (UnifiedGenerationalGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
ParallelGCModel model = (ParallelGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 2);
GCEvent youngGC = model.getGcEvents().get(0);
Assert.assertEquals(youngGC.getGcid(), 0);
Assert.assertEquals(youngGC.getStartTime(), 455, DELTA);
Assert.assertEquals(youngGC.getDuration(), 11.081, DELTA);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(youngGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 65536 * 1024, 10720 * 1024, 76288 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 0, 20800 * 1024, 175104 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 6531 * 1024, 6531 * 1024, 1056768 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 64 * 1024 * 1024, 30 * 1024 * 1024, 245 * 1024 * 1024));
Assert.assertEquals(youngGC.getCpuTime().getReal(), 10, DELTA);
GCEvent fullGC = model.getGcEvents().get(1);
Assert.assertEquals(fullGC.getGcid(), 1);
Assert.assertEquals(fullGC.getStartTime(), 2836, DELTA);
Assert.assertEquals(fullGC.getDuration(), 46.539, DELTA);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getCause(), ERGONOMICS);
Assert.assertEquals(fullGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 10729 * 1024, 0, 76288 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 141664 * 1024, 94858 * 1024, 175104 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 7459 * 1024, 7459 * 1024, 1056768 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 148 * 1024 * 1024, 92 * 1024 * 1024, 245 * 1024 * 1024));
Assert.assertEquals(fullGC.getPhases().size(), 5);
for (GCEvent phase : fullGC.getPhases()) {
Assert.assertTrue(phase.getStartTime() != UNKNOWN_DOUBLE);
Assert.assertTrue(phase.getDuration() != UNKNOWN_DOUBLE);
}
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.PARALLEL_PHASE_SUMMARY).getDuration(), 0.006, DELTA);
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.PARALLEL_PHASE_COMPACTION).getDuration(), 22.465, DELTA);
Assert.assertEquals(fullGC.getCpuTime().getReal(), 50, DELTA);
}
@Test
public void testJDK11CMSGCParser() throws Exception {
String log = "[0.479s][info][gc,start ] GC(0) Pause Young (Allocation Failure)\n" +
"[0.480s][info][gc,task ] GC(0) Using 5 workers of 8 for evacuation\n" +
"[0.510s][info][gc,heap ] GC(0) ParNew: 69952K->8703K(78656K)\n" +
"[0.510s][info][gc,heap ] GC(0) CMS: 0K->24072K(174784K)\n" +
"[0.510s][info][gc,metaspace ] GC(0) Metaspace: 6531K->6530K(1056768K)\n" +
"[0.510s][info][gc ] GC(0) Pause Young (Allocation Failure) 68M->32M(247M) 31.208ms\n" +
"[0.510s][info][gc,cpu ] GC(0) User=0.06s Sys=0.03s Real=0.03s\n" +
"[3.231s][info][gc,start ] GC(1) Pause Initial Mark\n" +
"[3.235s][info][gc ] GC(1) Pause Initial Mark 147M->147M(247M) 3.236ms\n" +
"[3.235s][info][gc,cpu ] GC(1) User=0.01s Sys=0.02s Real=0.03s\n" +
"[3.235s][info][gc ] GC(1) Concurrent Mark\n" +
"[3.235s][info][gc,task ] GC(1) Using 2 workers of 2 for marking\n" +
"[3.257s][info][gc ] GC(1) Concurrent Mark 22.229ms\n" +
"[3.257s][info][gc,cpu ] GC(1) User=0.07s Sys=0.00s Real=0.03s\n" +
"[3.257s][info][gc ] GC(1) Concurrent Preclean\n" +
"[3.257s][info][gc ] GC(1) Concurrent Preclean 0.264ms\n" +
"[3.257s][info][gc,cpu ] GC(1) User=0.00s Sys=0.00s Real=0.00s\n" +
"[3.257s][info][gc,start ] GC(1) Pause Remark\n" +
"[3.259s][info][gc ] GC(1) Pause Remark 149M->149M(247M) 1.991ms\n" +
"[3.259s][info][gc,cpu ] GC(1) User=0.02s Sys=0.03s Real=0.01s\n" +
"[3.259s][info][gc ] GC(1) Concurrent Sweep\n" +
"[3.279s][info][gc ] GC(1) Concurrent Sweep 19.826ms\n" +
"[3.279s][info][gc,cpu ] GC(1) User=0.03s Sys=0.00s Real=0.02s\n" +
"[3.279s][info][gc ] GC(1) Concurrent Reset\n" +
"[3.280s][info][gc ] GC(1) Concurrent Reset 0.386ms\n" +
"[3.280s][info][gc,cpu ] GC(1) User=0.00s Sys=0.00s Real=0.00s\n" +
"[3.280s][info][gc,heap ] GC(1) Old: 142662K->92308K(174784K)\n" +
"[8.970s][info][gc,start ] GC(2) Pause Full (Allocation Failure)\n" +
"[8.970s][info][gc,phases,start] GC(2) Phase 1: Mark live objects\n" +
"[9.026s][info][gc,phases ] GC(2) Phase 1: Mark live objects 55.761ms\n" +
"[9.026s][info][gc,phases,start] GC(2) Phase 2: Compute new object addresses\n" +
"[9.051s][info][gc,phases ] GC(2) Phase 2: Compute new object addresses 24.761ms\n" +
"[9.051s][info][gc,phases,start] GC(2) Phase 3: Adjust pointers\n" +
"[9.121s][info][gc,phases ] GC(2) Phase 3: Adjust pointers 69.678ms\n" +
"[9.121s][info][gc,phases,start] GC(2) Phase 4: Move objects\n" +
"[9.149s][info][gc,phases ] GC(2) Phase 4: Move objects 28.069ms\n" +
"[9.149s][info][gc ] GC(2) Pause Full (Allocation Failure) 174M->166M(247M) 178.617ms\n" +
"[9.149s][info][gc,cpu ] GC(2) User=0.17s Sys=0.00s Real=0.18s";
UnifiedGenerationalGCLogParser parser = (UnifiedGenerationalGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
CMSGCModel model = (CMSGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 3);
Assert.assertEquals(model.getParallelThread(), 8);
Assert.assertEquals(model.getConcurrentThread(), 2);
GCEvent youngGC = model.getGcEvents().get(0);
Assert.assertEquals(youngGC.getGcid(), 0);
Assert.assertEquals(youngGC.getStartTime(), 479, DELTA);
Assert.assertEquals(youngGC.getDuration(), 31.208, DELTA);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(youngGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 69952 * 1024, 8703 * 1024, 78656 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 0, 24072 * 1024, 174784 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 6531 * 1024, 6530 * 1024, 1056768 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 68 * 1024 * 1024, 32 * 1024 * 1024, 247 * 1024 * 1024));
Assert.assertEquals(youngGC.getCpuTime().getReal(), 30, DELTA);
GCEvent cms = model.getGcEvents().get(1);
Assert.assertEquals(cms.getGcid(), 1);
Assert.assertEquals(cms.getEventType(), GCEventType.CMS_CONCURRENT_MARK_SWEPT);
Assert.assertEquals(cms.getStartTime(), 3231, DELTA);
Assert.assertEquals(cms.getPhases().size(), 6);
for (GCEvent phase : cms.getPhases()) {
Assert.assertTrue(phase.getStartTime() != UNKNOWN_DOUBLE);
Assert.assertTrue(phase.getDuration() != UNKNOWN_DOUBLE);
Assert.assertNotNull(phase.getCpuTime());
if (phase.getEventType() == GCEventType.CMS_INITIAL_MARK || phase.getEventType() == GCEventType.CMS_FINAL_REMARK) {
Assert.assertNotNull(phase.getMemoryItem(HEAP));
}
}
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_INITIAL_MARK).getStartTime(), 3231, DELTA);
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_CONCURRENT_MARK).getDuration(), 22.229, DELTA);
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_CONCURRENT_MARK).getCpuTime().getUser(), 70, DELTA);
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_FINAL_REMARK).getCpuTime().getUser(), 20, DELTA);
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_FINAL_REMARK).getDuration(), 1.991, DELTA);
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_CONCURRENT_RESET).getDuration(), 0.386, DELTA);
Assert.assertEquals(cms.getLastPhaseOfType(GCEventType.CMS_CONCURRENT_SWEEP).getMemoryItem(OLD), new GCMemoryItem(OLD, 142662 * 1024, 92308 * 1024, 174784 * 1024));
GCEvent fullGC = model.getGcEvents().get(2);
Assert.assertEquals(fullGC.getGcid(), 2);
Assert.assertEquals(fullGC.getStartTime(), 8970, DELTA);
Assert.assertEquals(fullGC.getDuration(), 178.617, DELTA);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(fullGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 174 * 1024 * 1024, 166 * 1024 * 1024, 247 * 1024 * 1024));
Assert.assertEquals(fullGC.getCpuTime().getReal(), 180, DELTA);
Assert.assertEquals(fullGC.getPhases().size(), 4);
for (GCEvent phase : fullGC.getPhases()) {
Assert.assertTrue(phase.getStartTime() != UNKNOWN_DOUBLE);
Assert.assertTrue(phase.getDuration() != UNKNOWN_DOUBLE);
}
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.SERIAL_COMPUTE_NEW_OBJECT_ADDRESSES).getDuration(), 24.761, DELTA);
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.SERIAL_MOVE_OBJECTS).getDuration(), 28.069, DELTA);
}
@Test
public void testJDK8ParallelGCParser() throws Exception {
String log =
"0.141: [GC (Allocation Failure) [PSYoungGen: 25145K->4077K(29696K)] 25145K->16357K(98304K), 0.0225874 secs] [Times: user=0.10 sys=0.01, real=0.03 secs]\n" +
"0.269: [Full GC (Ergonomics) [PSYoungGen: 4096K->0K(55296K)] [ParOldGen: 93741K->67372K(174592K)] 97837K->67372K(229888K), [Metaspace: 3202K->3202K(1056768K)], 0.6862093 secs] [Times: user=2.60 sys=0.02, real=0.69 secs]\n" +
"0.962: [GC (Allocation Failure) [PSYoungGen: 51200K->4096K(77824K)] 118572K->117625K(252416K), 0.0462864 secs] [Times: user=0.29 sys=0.01, real=0.05 secs]\n" +
"1.872: [Full GC (Ergonomics) [PSYoungGen: 4096K->0K(103936K)] [ParOldGen: 169794K->149708K(341504K)] 173890K->149708K(445440K), [Metaspace: 3202K->3202K(1056768K)], 1.3724621 secs] [Times: user=8.33 sys=0.01, real=1.38 secs]\n" +
"3.268: [GC (Allocation Failure) [PSYoungGen: 99840K->56802K(113664K)] 249548K->302089K(455168K), 0.1043993 secs] [Times: user=0.75 sys=0.06, real=0.10 secs]\n" +
"14.608: [Full GC (Ergonomics) [PSYoungGen: 65530K->0K(113664K)] [ParOldGen: 341228K->720K(302592K)] 406759K->720K(416256K), [Metaspace: 3740K->3737K(1056768K)], 0.0046781 secs] [Times: user=0.02 sys=0.01, real=0.00 secs]\n";
PreUnifiedGenerationalGCLogParser parser = (PreUnifiedGenerationalGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
ParallelGCModel model = (ParallelGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 6);
GCEvent youngGC = model.getGcEvents().get(2);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(youngGC.getStartTime(), 962, DELTA);
Assert.assertEquals(youngGC.getDuration(), 46.2864, DELTA);
GCMemoryItem youngGen = youngGC.getMemoryItem(YOUNG);
Assert.assertEquals(youngGen.getPreUsed(), 51200 * 1024);
Assert.assertEquals(youngGen.getPostUsed(), 4096 * 1024);
Assert.assertEquals(youngGen.getPostCapacity(), 77824 * 1024);
GCMemoryItem total = youngGC.getMemoryItem(HEAP);
Assert.assertEquals(total.getPreUsed(), 118572 * 1024);
Assert.assertEquals(total.getPostUsed(), 117625 * 1024);
Assert.assertEquals(total.getPostCapacity(), 252416 * 1024);
Assert.assertEquals(youngGC.getCpuTime().getUser(), 290, DELTA);
GCEvent fullGC = model.getGcEvents().get(5);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getCause(), ERGONOMICS);
Assert.assertEquals(fullGC.getStartTime(), 14608, DELTA);
Assert.assertEquals(fullGC.getDuration(), 4.6781, DELTA);
youngGen = fullGC.getMemoryItem(YOUNG);
Assert.assertEquals(youngGen.getPreUsed(), 65530 * 1024);
Assert.assertEquals(youngGen.getPostUsed(), 0);
Assert.assertEquals(youngGen.getPostCapacity(), 113664 * 1024);
GCMemoryItem oldGen = fullGC.getMemoryItem(OLD);
Assert.assertEquals(oldGen.getPreUsed(), 341228 * 1024);
Assert.assertEquals(oldGen.getPostUsed(), 720 * 1024);
Assert.assertEquals(oldGen.getPostCapacity(), 302592 * 1024);
GCMemoryItem metaspace = fullGC.getMemoryItem(METASPACE);
Assert.assertEquals(metaspace.getPreUsed(), 3740 * 1024);
Assert.assertEquals(metaspace.getPostUsed(), 3737 * 1024);
Assert.assertEquals(metaspace.getPostCapacity(), 1056768 * 1024);
total = fullGC.getMemoryItem(HEAP);
Assert.assertEquals(total.getPreUsed(), 406759 * 1024);
Assert.assertEquals(total.getPostUsed(), 720 * 1024);
Assert.assertEquals(total.getPostCapacity(), 416256 * 1024);
Assert.assertEquals(fullGC.getCpuTime().getUser(), 20, DELTA);
}
@Test
public void testJDK8SerialGCParser() throws Exception {
String log =
"2021-12-07T11:18:11.688+0800: #0: [GC (Allocation Failure) 2021-12-07T11:18:11.688+0800: #0: [DefNew: 69952K->8704K(78656K), 0.0591895 secs] 69952K->56788K(253440K), 0.0592437 secs] [Times: user=0.05 sys=0.02, real=0.06 secs] \n" +
"2021-12-07T11:18:11.756+0800: #1: [GC (Allocation Failure) 2021-12-07T11:18:11.756+0800: #1: [DefNew: 78656K->8703K(78656K), 0.0700624 secs] 126740K->114869K(253440K), 0.0701086 secs] [Times: user=0.05 sys=0.01, real=0.07 secs] \n" +
"2021-12-07T11:18:11.833+0800: #2: [GC (Allocation Failure) 2021-12-07T11:18:11.833+0800: #2: [DefNew: 78655K->8703K(78656K), 0.0837783 secs]2021-12-07T11:18:11.917+0800: #3: [Tenured: 176115K->174136K(176128K), 0.1988447 secs] 184821K->174136K(254784K), [Metaspace: 3244K->3244K(1056768K)], 0.2828418 secs] [Times: user=0.27 sys=0.02, real=0.28 secs] \n" +
"2021-12-07T11:18:12.140+0800: #4: [GC (Allocation Failure) 2021-12-07T11:18:12.140+0800: #4: [DefNew: 116224K->14463K(130688K), 0.1247689 secs] 290360K->290358K(420916K), 0.1248360 secs] [Times: user=0.10 sys=0.03, real=0.12 secs] \n" +
"2021-12-07T11:18:12.273+0800: #5: [GC (Allocation Failure) 2021-12-07T11:18:12.273+0800: #5: [DefNew: 102309K->14463K(130688K), 0.1181527 secs]2021-12-07T11:18:12.391+0800: #6: [Tenured: 362501K->362611K(362612K), 0.3681604 secs] 378203K->376965K(493300K), [Metaspace: 3244K->3244K(1056768K)], 0.4867024 secs] [Times: user=0.46 sys=0.03, real=0.49 secs] \n" +
"2021-12-07T11:18:12.809+0800: #7: [GC (Allocation Failure) 2021-12-07T11:18:12.809+0800: #7: [DefNew: 227109K->30207K(272000K), 0.3180977 secs] 589721K->581277K(876356K), 0.3181286 secs] [Times: user=0.27 sys=0.05, real=0.32 secs] \n" +
"2021-12-07T11:18:13.160+0800: #8: [GC (Allocation Failure) 2021-12-07T11:18:13.160+0800: #8: [DefNew: 271999K->30207K(272000K), 0.2782985 secs]2021-12-07T11:18:13.438+0800: #9: [Tenured: 785946K->756062K(786120K), 0.8169720 secs] 823069K->756062K(1058120K), [Metaspace: 3782K->3782K(1056768K)], 1.0959870 secs] [Times: user=1.03 sys=0.07, real=1.09 secs] \n" +
"2021-12-07T11:18:14.386+0800: #10: [GC (Allocation Failure) 2021-12-07T11:18:14.386+0800: #10: [DefNew: 504128K->62975K(567104K), 0.5169362 secs] 1260190K->1260189K(1827212K), 0.5169650 secs] [Times: user=0.40 sys=0.12, real=0.52 secs] ";
PreUnifiedGenerationalGCLogParser parser = (PreUnifiedGenerationalGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
SerialGCModel model = (SerialGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 8);
Assert.assertEquals(model.getReferenceTimestamp(), 1638847091688.0, DELTA);
GCEvent youngGC = model.getGcEvents().get(1);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(youngGC.getStartTime(), 68, DELTA);
Assert.assertEquals(youngGC.getDuration(), 70.1086, DELTA);
GCMemoryItem youngGen = youngGC.getMemoryItem(YOUNG);
Assert.assertEquals(youngGen.getPreUsed(), 78656 * 1024);
Assert.assertEquals(youngGen.getPostUsed(), 8703 * 1024);
Assert.assertEquals(youngGen.getPostCapacity(), 78656 * 1024);
GCMemoryItem total = youngGC.getMemoryItem(HEAP);
Assert.assertEquals(total.getPreUsed(), 126740 * 1024);
Assert.assertEquals(total.getPostUsed(), 114869 * 1024);
Assert.assertEquals(total.getPostCapacity(), 253440 * 1024);
Assert.assertEquals(youngGC.getCpuTime().getReal(), 70, DELTA);
GCEvent fullGC = model.getGcEvents().get(6);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(fullGC.getStartTime(), 1472, DELTA);
Assert.assertEquals(fullGC.getDuration(), 1095.987, DELTA);
youngGen = fullGC.getMemoryItem(YOUNG);
Assert.assertEquals(youngGen.getPreUsed(), 271999 * 1024);
Assert.assertEquals(youngGen.getPostUsed(), 0);
Assert.assertEquals(youngGen.getPostCapacity(), 272000 * 1024);
GCMemoryItem oldGen = fullGC.getMemoryItem(OLD);
Assert.assertEquals(oldGen.getPreUsed(), 785946 * 1024);
Assert.assertEquals(oldGen.getPostUsed(), 756062 * 1024);
Assert.assertEquals(oldGen.getPostCapacity(), 786120 * 1024);
GCMemoryItem metaspace = fullGC.getMemoryItem(METASPACE);
Assert.assertEquals(metaspace.getPreUsed(), 3782 * 1024);
Assert.assertEquals(metaspace.getPostUsed(), 3782 * 1024);
Assert.assertEquals(metaspace.getPostCapacity(), 1056768 * 1024);
total = fullGC.getMemoryItem(HEAP);
Assert.assertEquals(total.getPreUsed(), 823069 * 1024);
Assert.assertEquals(total.getPostUsed(), 756062 * 1024);
Assert.assertEquals(total.getPostCapacity(), 1058120 * 1024);
Assert.assertEquals(fullGC.getCpuTime().getSys(), 70, DELTA);
}
@Test
public void testJDK8GenerationalGCInterleave() throws Exception {
String log =
"2022-08-02T10:26:05.043+0800: 61988.328: [GC (Allocation Failure) 2022-08-02T10:26:05.043+0800: 61988.328: [ParNew: 2621440K->2621440K(2883584K), 0.0000519 secs]2022-08-02T10:26:05.043+0800: 61988.328: [CMS: 1341593K->1329988K(2097152K), 2.0152293 secs] 3963033K->1329988K(4980736K), [Metaspace: 310050K->309844K(1343488K)], 2.0160411 secs] [Times: user=1.98 sys=0.05, real=2.01 secs] ";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
GCModel model = parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 1);
GCEvent fullGC = model.getGcEvents().get(0);
Assert.assertEquals(fullGC.getStartTime(), 61988328, DELTA);
Assert.assertEquals(fullGC.getDuration(), 2016.0411, DELTA);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(fullGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 2621440L * 1024, 0, 2883584L * 1024));
Assert.assertEquals(fullGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 1341593L * 1024, 1329988L * 1024, 2097152L * 1024));
Assert.assertEquals(fullGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 3963033L * 1024, 1329988L * 1024, 4980736L * 1024));
Assert.assertEquals(fullGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 310050L * 1024, 309844L * 1024, 1343488L * 1024));
Assert.assertEquals(fullGC.getCpuTime().getReal(), 2010, DELTA);
}
@Test
public void testJDK11GenerationalGCInterleave() throws Exception {
String log =
"[5.643s][info][gc,start ] GC(3) Pause Young (Allocation Failure)\n" +
"[5.643s][info][gc,start ] GC(4) Pause Full (Allocation Failure)\n" +
"[5.643s][info][gc,phases,start] GC(4) Phase 1: Mark live objects\n" +
"[5.691s][info][gc,phases ] GC(4) Phase 1: Mark live objects 47.363ms\n" +
"[5.691s][info][gc,phases,start] GC(4) Phase 2: Compute new object addresses\n" +
"[5.715s][info][gc,phases ] GC(4) Phase 2: Compute new object addresses 24.314ms\n" +
"[5.715s][info][gc,phases,start] GC(4) Phase 3: Adjust pointers\n" +
"[5.771s][info][gc,phases ] GC(4) Phase 3: Adjust pointers 56.294ms\n" +
"[5.771s][info][gc,phases,start] GC(4) Phase 4: Move objects\n" +
"[5.789s][info][gc,phases ] GC(4) Phase 4: Move objects 17.974ms\n" +
"[5.789s][info][gc ] GC(4) Pause Full (Allocation Failure) 215M->132M(247M) 146.153ms\n" +
"[5.789s][info][gc,heap ] GC(3) DefNew: 78655K->0K(78656K)\n" +
"[5.789s][info][gc,heap ] GC(3) Tenured: 142112K->135957K(174784K)\n" +
"[5.789s][info][gc,metaspace ] GC(3) Metaspace: 7462K->7462K(1056768K)\n" +
"[5.789s][info][gc ] GC(3) Pause Young (Allocation Failure) 215M->132M(247M) 146.211ms\n" +
"[5.789s][info][gc,cpu ] GC(3) User=0.15s Sys=0.00s Real=0.15s";
UnifiedGenerationalGCLogParser parser = (UnifiedGenerationalGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
SerialGCModel model = (SerialGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 1);
GCEvent fullGC = model.getGcEvents().get(0);
Assert.assertEquals(fullGC.getGcid(), 3);
Assert.assertEquals(fullGC.getStartTime(), 5643, DELTA);
Assert.assertEquals(fullGC.getDuration(), 146.211, DELTA);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(fullGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 78655 * 1024, 0, 78656 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 142112 * 1024, 135957 * 1024, 174784 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 215 * 1024 * 1024, 132 * 1024 * 1024, 247 * 1024 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 7462 * 1024, 7462 * 1024, 1056768 * 1024));
Assert.assertEquals(fullGC.getPhases().size(), 4);
for (GCEvent phase : fullGC.getPhases()) {
Assert.assertTrue(phase.getStartTime() != UNKNOWN_DOUBLE);
Assert.assertTrue(phase.getDuration() != UNKNOWN_DOUBLE);
}
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.SERIAL_COMPUTE_NEW_OBJECT_ADDRESSES).getDuration(), 24.314, DELTA);
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.SERIAL_MOVE_OBJECTS).getDuration(), 17.974, DELTA);
Assert.assertTrue(fullGC.isTrue(YOUNG_GC_BECOME_FULL_GC));
}
@Test
public void TestIncompleteGCLog() throws Exception {
String log =
"[0.510s][info][gc,heap ] GC(0) CMS: 0K->24072K(174784K)\n" +
"[0.510s][info][gc,metaspace ] GC(0) Metaspace: 6531K->6530K(1056768K)\n" +
"[0.510s][info][gc ] GC(0) Pause Young (Allocation Failure) 68M->32M(247M) 31.208ms\n" +
"[0.510s][info][gc,cpu ] GC(0) User=0.06s Sys=0.03s Real=0.03s\n" +
"[3.231s][info][gc,start ] GC(1) Pause Initial Mark\n" +
"[3.235s][info][gc ] GC(1) Pause Initial Mark 147M->147M(247M) 3.236ms\n" +
"[3.235s][info][gc,cpu ] GC(1) User=0.01s Sys=0.02s Real=0.03s\n" +
"[3.235s][info][gc ] GC(1) Concurrent Mark\n" +
"[3.235s][info][gc,task ] GC(1) Using 2 workers of 2 for marking\n" +
"[3.257s][info][gc ] GC(1) Concurrent Mark 22.229ms\n" +
"[3.257s][info][gc,cpu ] GC(1) User=0.07s Sys=0.00s Real=0.03s\n" +
"[3.257s][info][gc ] GC(1) Concurrent Preclean\n" +
"[3.257s][info][gc ] GC(1) Concurrent Preclean 0.264ms\n" +
"[3.257s][info][gc,cpu ] GC(1) User=0.00s Sys=0.00s Real=0.00s\n" +
"[3.257s][info][gc,start ] GC(1) Pause Remark\n" +
"[3.259s][info][gc ] GC(1) Pause Remark 149M->149M(247M) 1.991ms\n" +
"[3.259s][info][gc,cpu ] GC(1) User=0.02s Sys=0.03s Real=0.01s\n" +
"[3.259s][info][gc ] GC(1) Concurrent Sweep\n" +
"[3.279s][info][gc ] GC(1) Concurrent Sweep 19.826ms\n" +
"[3.279s][info][gc,cpu ] GC(1) User=0.03s Sys=0.00s Real=0.02s\n" +
"[3.279s][info][gc ] GC(1) Concurrent Reset\n" +
"[3.280s][info][gc ] GC(1) Concurrent Reset 0.386ms\n" +
"[3.280s][info][gc,cpu ] GC(1) User=0.00s Sys=0.00s Real=0.00s\n" +
"[3.280s][info][gc,heap ] GC(1) Old: 142662K->92308K(174784K)\n" +
"[8.970s][info][gc,start ] GC(2) Pause Full (Allocation Failure)\n" +
"[8.970s][info][gc,phases,start] GC(2) Phase 1: Mark live objects\n" +
"[9.026s][info][gc,phases ] GC(2) Phase 1: Mark live objects 55.761ms\n" +
"[9.026s][info][gc,phases,start] GC(2) Phase 2: Compute new object addresses\n" +
"[9.051s][info][gc,phases ] GC(2) Phase 2: Compute new object addresses 24.761ms\n" +
"[9.051s][info][gc,phases,start] GC(2) Phase 3: Adjust pointers\n";
UnifiedGenerationalGCLogParser parser = (UnifiedGenerationalGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
CMSGCModel model = (CMSGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 2);
Assert.assertEquals(model.getAllEvents().size(), 8);
}
@Test
public void testJDK8ConcurrentPrintDateTimeStamp() throws Exception {
String log = "2022-04-25T11:38:47.548+0800: 725.062: [GC pause (G1 Evacuation Pause) (young) (initial-mark) 725.062: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 5369, predicted base time: 22.02 ms, remaining time: 177.98 ms, target pause time: 200.00 ms]\n" +
" 725.062: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 10 regions, survivors: 1 regions, predicted young region time: 2.34 ms]\n" +
" 725.062: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 10 regions, survivors: 1 regions, old: 0 regions, predicted pause time: 24.37 ms, target pause time: 200.00 ms]\n" +
", 0.0182684 secs]\n" +
" [Parallel Time: 17.4 ms, GC Workers: 4]\n" +
" [GC Worker Start (ms): Min: 725063.0, Avg: 725063.0, Max: 725063.0, Diff: 0.0]\n" +
" [Ext Root Scanning (ms): Min: 7.6, Avg: 7.9, Max: 8.4, Diff: 0.8, Sum: 31.6]\n" +
" [Update RS (ms): Min: 2.6, Avg: 2.7, Max: 2.9, Diff: 0.3, Sum: 10.8]\n" +
" [Processed Buffers: Min: 6, Avg: 6.8, Max: 7, Diff: 1, Sum: 27]\n" +
" [Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]\n" +
" [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]\n" +
" [Object Copy (ms): Min: 5.4, Avg: 6.1, Max: 6.5, Diff: 1.1, Sum: 24.5]\n" +
" [Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]\n" +
" [Termination Attempts: Min: 1, Avg: 4.8, Max: 8, Diff: 7, Sum: 19]\n" +
" [GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]\n" +
" [GC Worker Total (ms): Min: 16.8, Avg: 16.8, Max: 16.8, Diff: 0.0, Sum: 67.1]\n" +
" [GC Worker End (ms): Min: 725079.8, Avg: 725079.8, Max: 725079.8, Diff: 0.0]\n" +
" [Code Root Fixup: 0.0 ms]\n" +
" [Code Root Purge: 0.0 ms]\n" +
" [Clear CT: 0.1 ms]\n" +
" [Other: 0.7 ms]\n" +
" [Choose CSet: 0.0 ms]\n" +
" [Ref Proc: 0.1 ms]\n" +
" [Ref Enq: 0.0 ms]\n" +
" [Redirty Cards: 0.1 ms]\n" +
" [Humongous Register: 0.0 ms]\n" +
" [Humongous Reclaim: 0.0 ms]\n" +
" [Free CSet: 0.0 ms]\n" +
" [Eden: 320.0M(320.0M)->0.0B(320.0M) Survivors: 32768.0K->32768.0K Heap: 2223.9M(2560.0M)->1902.5M(2560.0M)]\n" +
" [Times: user=0.07 sys=0.00, real=0.02 secs]\n" +
/*
* This test mainly test the line below. The format here is:
* [DateStamp] [DateStamp] [TimeStamp] [TimeStamp] [Safepoint]
* [Concurrent cycle phase]
*/
"2022-04-25T11:38:47.567+0800: 2022-04-25T11:38:47.567+0800: 725.081: 725.081: Total time for which application threads were stopped: 0.0227079 seconds, Stopping threads took: 0.0000889 seconds\n" +
"[GC concurrent-root-region-scan-start]\n" +
"2022-04-25T11:38:47.581+0800: 725.095: Application time: 0.0138476 seconds\n" +
"2022-04-25T11:38:47.585+0800: 725.099: Total time for which application threads were stopped: 0.0042001 seconds, Stopping threads took: 0.0000809 seconds\n" +
"2022-04-25T11:38:47.613+0800: 725.127: [GC concurrent-root-region-scan-end, 0.0460720 secs]\n" +
"2022-04-25T11:38:47.613+0800: 725.127: [GC concurrent-mark-start]\n" +
"2022-04-25T11:38:51.924+0800: 729.438: [GC pause (G1 Evacuation Pause) (young) 729.438: [G1Ergonomics (CSet Construction) start choosing CSet, _pending_cards: 4375, predicted base time: 22.74 ms, remaining time: 177.26 ms, target pause time: 200.00 ms]\n" +
" 729.438: [G1Ergonomics (CSet Construction) add young regions to CSet, eden: 10 regions, survivors: 1 regions, predicted young region time: 4.90 ms]\n" +
" 729.438: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 10 regions, survivors: 1 regions, old: 0 regions, predicted pause time: 27.64 ms, target pause time: 200.00 ms]\n" +
", 0.0535660 secs]\n" +
" [Parallel Time: 52.5 ms, GC Workers: 4]\n" +
" [GC Worker Start (ms): Min: 729438.4, Avg: 729438.5, Max: 729438.5, Diff: 0.0]\n" +
" [Ext Root Scanning (ms): Min: 5.2, Avg: 5.9, Max: 6.9, Diff: 1.8, Sum: 23.7]\n" +
" [Update RS (ms): Min: 1.7, Avg: 2.5, Max: 3.3, Diff: 1.7, Sum: 10.0]\n" +
" [Processed Buffers: Min: 4, Avg: 6.0, Max: 7, Diff: 3, Sum: 24]\n" +
" [Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]\n" +
" [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]\n" +
" [Object Copy (ms): Min: 5.6, Avg: 5.7, Max: 6.1, Diff: 0.5, Sum: 22.9]\n" +
" [Termination (ms): Min: 37.2, Avg: 37.5, Max: 38.2, Diff: 1.0, Sum: 149.9]\n" +
" [Termination Attempts: Min: 1, Avg: 10.8, Max: 17, Diff: 16, Sum: 43]\n" +
" [GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]\n" +
" [GC Worker Total (ms): Min: 51.4, Avg: 51.7, Max: 52.4, Diff: 0.9, Sum: 206.7]\n" +
" [GC Worker End (ms): Min: 729489.9, Avg: 729490.1, Max: 729490.8, Diff: 0.9]\n" +
" [Code Root Fixup: 0.0 ms]\n" +
" [Code Root Purge: 0.0 ms]\n" +
" [Clear CT: 0.1 ms]\n" +
" [Other: 1.0 ms]\n" +
" [Choose CSet: 0.0 ms]\n" +
" [Ref Proc: 0.4 ms]\n" +
" [Ref Enq: 0.0 ms]\n" +
" [Redirty Cards: 0.0 ms]\n" +
" [Humongous Register: 0.0 ms]\n" +
" [Humongous Reclaim: 0.0 ms]\n" +
" [Free CSet: 0.0 ms]\n" +
" [Eden: 320.0M(320.0M)->0.0B(320.0M) Survivors: 32768.0K->32768.0K Heap: 2230.5M(2560.0M)->1906.2M(2560.0M)]\n" +
" [Times: user=0.06 sys=0.01, real=0.05 secs]\n" +
"2022-04-25T11:38:51.978+0800: 729.492: Total time for which application threads were stopped: 0.0578224 seconds, Stopping threads took: 0.0000709 seconds\n" +
"2022-04-25T11:38:52.409+0800: 729.923: Application time: 0.4310531 seconds\n" +
"2022-04-25T11:38:52.944+0800: 730.458: [GC concurrent-mark-end, 5.3312732 secs]\n" +
"2022-04-25T11:38:52.944+0800: 730.458: Application time: 0.1087156 seconds\n" +
"2022-04-25T11:38:52.949+0800: 730.463: [GC remark 2022-04-25T11:38:52.949+0800: 730.463: [Finalize Marking, 0.0014784 secs] 2022-04-25T11:38:52.950+0800: 730.464: [GC ref-proc, 0.0007278 secs] 2022-04-25T11:38:52.951+0800: 730.465: [Unloading, 0.1281692 secs], 0.1350560 secs]\n" +
" [Times: user=0.21 sys=0.01, real=0.13 secs]\n" +
"2022-04-25T11:38:53.084+0800: 730.598: Total time for which application threads were stopped: 0.1396855 seconds, Stopping threads took: 0.0000545 seconds\n" +
"2022-04-25T11:38:53.084+0800: 730.598: Application time: 0.0000928 seconds\n" +
"2022-04-25T11:38:53.089+0800: 730.603: [GC cleanup 1984M->1984M(2560M), 0.0016114 secs]\n" +
" [Times: user=0.01 sys=0.00, real=0.01 secs]\n";
PreUnifiedG1GCLogParser parser = (PreUnifiedG1GCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
G1GCModel model = (G1GCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertEquals(model.getGcEvents().size(), 3);
Assert.assertEquals(model.getGcEvents().get(0).getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(model.getGcEvents().get(1).getEventType(), GCEventType.G1_CONCURRENT_CYCLE);
Assert.assertEquals(model.getGcEvents().get(1).getPhases().get(0).getEventType(), GCEventType.G1_CONCURRENT_SCAN_ROOT_REGIONS);
Assert.assertEquals(model.getGcEvents().get(1).getPhases().get(0).getStartTime(), 725081, DELTA);
Assert.assertEquals(model.getGcEvents().get(2).getEventType(), GCEventType.YOUNG_GC);
}
@Test
public void TestJDK8CMSPromotionFailed() throws Exception {
String log = "2021-09-24T22:54:19.430+0800: 23501.549: [GC (Allocation Failure) 2021-09-24T22:54:19.430+0800: 23501.550: [ParNew (promotion failed): 7689600K->7689600K(7689600K), 5.2751800 secs]2021-09-24T22:54:24.705+0800: 23506.825: [CMS: 9258265K->5393434K(12582912K), 14.5693099 secs] 16878013K->5393434K(20272512K), [Metaspace: 208055K->203568K(1253376K)], 19.8476364 secs] [Times: user=19.95 sys=0.05, real=19.85 secs]";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
CMSGCModel model = (CMSGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertEquals(model.getGcEvents().size(), 1);
GCEvent fullGC = model.getGcEvents().get(0);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 7689600L * 1024, 0, 7689600L * 1024));
Assert.assertEquals(fullGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 9258265L * 1024, 5393434L * 1024, 12582912L * 1024));
Assert.assertEquals(fullGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 16878013L * 1024, 5393434L * 1024, 20272512L * 1024));
Assert.assertEquals(fullGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 208055 * 1024, 203568 * 1024, 1253376 * 1024));
Assert.assertEquals(fullGC.getCause(), PROMOTION_FAILED);
Assert.assertTrue(fullGC.isTrue(YOUNG_GC_BECOME_FULL_GC));
}
@Test
public void TestJDK8CMSScavengeBeforeRemark() throws Exception {
String log = "2022-10-14T14:28:44.426+0800: 165.382: [GC (CMS Initial Mark) [1 CMS-initial-mark: 1308232K(2097152K)] 2715777K(4019584K), 0.2266431 secs] [Times: user=0.85 sys=0.03, real=0.23 secs] \n" +
"2022-10-14T14:28:44.653+0800: 165.609: [CMS-concurrent-mark-start]\n" +
"2022-10-14T14:28:46.815+0800: 167.771: [CMS-concurrent-mark: 2.082/2.161 secs] [Times: user=4.22 sys=0.58, real=2.16 secs] \n" +
"2022-10-14T14:28:46.815+0800: 167.771: [CMS-concurrent-preclean-start]\n" +
"2022-10-14T14:28:46.854+0800: 167.810: [CMS-concurrent-preclean: 0.038/0.039 secs] [Times: user=0.12 sys=0.01, real=0.04 secs] \n" +
"2022-10-14T14:28:46.855+0800: 167.811: [CMS-concurrent-abortable-preclean-start]\n" +
"2022-10-14T14:28:47.937+0800: 168.893: [GC (Allocation Failure) 2022-10-14T14:28:47.937+0800: 168.893: [ParNew: 1922431K->174720K(1922432K), 0.2928759 secs] 3230664K->1560308K(4019584K), 0.2931600 secs] [Times: user=0.83 sys=0.06, real=0.29 secs] \n" +
"2022-10-14T14:28:50.764+0800: 171.720: [CMS-concurrent-abortable-preclean: 3.498/3.909 secs] [Times: user=10.64 sys=1.14, real=3.91 secs] \n" +
"2022-10-14T14:28:50.765+0800: 171.721: [GC (CMS Final Remark) [YG occupancy: 1056998 K (1922432 K)]2022-10-14T14:28:50.765+0800: 171.721: [GC (CMS Final Remark) 2022-10-14T14:28:50.765+0800: 171.721: [ParNew: 1056998K->151245K(1922432K), 0.1588173 secs] 2442587K->1615175K(4019584K), 0.1590607 secs] [Times: user=0.49 sys=0.05, real=0.16 secs] \n" +
"2022-10-14T14:28:50.924+0800: 171.880: [Rescan (parallel) , 0.0482726 secs]2022-10-14T14:28:50.973+0800: 171.929: [weak refs processing, 0.0000506 secs]2022-10-14T14:28:50.973+0800: 171.929: [class unloading, 0.0809186 secs]2022-10-14T14:28:51.054+0800: 172.010: [scrub symbol table, 0.0649216 secs]2022-10-14T14:28:51.118+0800: 172.075: [scrub string table, 0.0045311 secs][1 CMS-remark: 1463930K(2097152K)] 1615175K(4019584K), 0.3629243 secs] [Times: user=0.83 sys=0.06, real=0.36 secs] \n" +
"2022-10-14T14:28:51.129+0800: 172.085: [CMS-concurrent-sweep-start]\n" +
"2022-10-14T14:28:51.881+0800: 172.837: [CMS-concurrent-sweep: 0.727/0.752 secs] [Times: user=1.41 sys=0.20, real=0.75 secs] \n" +
"2022-10-14T14:28:51.881+0800: 172.837: [CMS-concurrent-reset-start]\n" +
"2022-10-14T14:28:51.895+0800: 172.851: [CMS-concurrent-reset: 0.014/0.014 secs] [Times: user=0.03 sys=0.01, real=0.02 secs] ";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
CMSGCModel model = (CMSGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertEquals(model.getGcEvents().size(), 3);
Assert.assertEquals(model.getLastEventOfType(GCEventType.CMS_FINAL_REMARK).getCpuTime().getUser(), 830, DELTA);
GCEvent youngGC = model.getGcEvents().get(1);
Assert.assertEquals(youngGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 1922431L * 1024L, 174720L * 1024L, 1922432L * 1024L));
youngGC = model.getGcEvents().get(2);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 1056998L * 1024L, 151245L * 1024L, 1922432L * 1024L));
Assert.assertEquals(youngGC.getCpuTime().getUser(), 490, DELTA);
Assert.assertEquals(youngGC.getCause(), CMS_FINAL_REMARK);
PauseStatistics pause = model.getPauseStatistics(new TimeRange(0, 99999999));
Assert.assertEquals(pause.getPauseAvg(), (226.6431 + 362.9243 + 293.1600) / 3.0, DELTA);
}
@Test
public void TestJDK11CMSScavengeBeforeRemark() throws Exception {
String log = "[0.600s][info][gc,start ] GC(1) Pause Young (Allocation Failure)\n" +
"[0.600s][info][gc,task ] GC(1) Using 2 workers of 8 for evacuation\n" +
"[0.632s][info][gc,heap ] GC(1) ParNew: 46079K->5120K(46080K)\n" +
"[0.632s][info][gc,heap ] GC(1) CMS: 14224K->48865K(51200K)\n" +
"[0.632s][info][gc,metaspace ] GC(1) Metaspace: 6590K->6590K(1056768K)\n" +
"[0.632s][info][gc ] GC(1) Pause Young (Allocation Failure) 58M->52M(95M) 32.662ms\n" +
"[0.632s][info][gc,cpu ] GC(1) User=0.05s Sys=0.01s Real=0.03s\n" +
"[0.632s][info][gc,start ] GC(2) Pause Initial Mark\n" +
"[0.635s][info][gc ] GC(2) Pause Initial Mark 53M->53M(95M) 2.784ms\n" +
"[0.635s][info][gc,cpu ] GC(2) User=0.03s Sys=0.00s Real=0.00s\n" +
"[0.635s][info][gc ] GC(2) Concurrent Mark\n" +
"[0.635s][info][gc,task ] GC(2) Using 2 workers of 2 for marking\n" +
"[0.642s][info][gc ] GC(2) Concurrent Mark 6.796ms\n" +
"[0.642s][info][gc,cpu ] GC(2) User=0.02s Sys=0.00s Real=0.01s\n" +
"[0.642s][info][gc ] GC(2) Concurrent Preclean\n" +
"[0.642s][info][gc ] GC(2) Concurrent Preclean 0.110ms\n" +
"[0.642s][info][gc,cpu ] GC(2) User=0.02s Sys=0.00s Real=0.00s\n" +
"[0.642s][info][gc,start ] GC(2) Pause Remark\n" +
"[0.642s][info][gc,start ] GC(3) Pause Young (CMS Final Remark)\n" +
"[0.642s][info][gc,task ] GC(3) Using 2 workers of 8 for evacuation\n" +
"[0.642s][info][gc,heap ] GC(3) ParNew: 5923K->5921K(46080K)\n" +
"[0.642s][info][gc,heap ] GC(3) CMS: 48865K->48865K(51200K)\n" +
"[0.642s][info][gc,metaspace ] GC(3) Metaspace: 6590K->6590K(1056768K)\n" +
"[0.642s][info][gc ] GC(3) Pause Young (CMS Final Remark) 53M->53M(95M) 0.040ms\n" +
"[0.642s][info][gc,cpu ] GC(3) User=0.07s Sys=0.00s Real=0.00s\n" +
"[0.646s][info][gc ] GC(2) Pause Remark 53M->53M(95M) 3.259ms\n" +
"[0.646s][info][gc,cpu ] GC(2) User=0.09s Sys=0.00s Real=0.00s\n" +
"[0.646s][info][gc ] GC(2) Concurrent Sweep\n" +
"[0.654s][info][gc ] GC(2) Concurrent Sweep 8.299ms\n" +
"[0.654s][info][gc,cpu ] GC(2) User=0.01s Sys=0.00s Real=0.01s\n" +
"[0.654s][info][gc ] GC(2) Concurrent Reset\n" +
"[0.654s][info][gc ] GC(2) Concurrent Reset 0.046ms\n" +
"[0.654s][info][gc,cpu ] GC(2) User=0.04s Sys=0.00s Real=0.00s\n" +
"[0.654s][info][gc,heap ] GC(2) Old: 48865K->34645K(51200K)";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
CMSGCModel model = (CMSGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertEquals(model.getGcEvents().size(), 3);
Assert.assertEquals(model.getLastEventOfType(GCEventType.CMS_FINAL_REMARK).getCpuTime().getUser(), 90, DELTA);
GCEvent youngGC = model.getGcEvents().get(0);
Assert.assertEquals(youngGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 46079 * 1024L, 5120 * 1024L, 46080 * 1024L));
youngGC = model.getGcEvents().get(2);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 5923 * 1024L, 5921 * 1024L, 46080 * 1024L));
Assert.assertEquals(youngGC.getCpuTime().getUser(), 70, DELTA);
Assert.assertEquals(youngGC.getCause(), CMS_FINAL_REMARK);
PauseStatistics pause = model.getPauseStatistics(new TimeRange(0, 99999999));
Assert.assertEquals(pause.getPauseAvg(), (32.662 + 3.259 + 2.784) / 3.0, DELTA);
}
@Test
public void TestJDK17SerialGCParser() throws Exception {
String log = "[0.008s][info][gc] Using Serial\n" +
"[0.008s][info][gc,init] Version: 17.0.1+12-39 (release)\n" +
"[0.008s][info][gc,init] CPUs: 8 total, 8 available\n" +
"[0.008s][info][gc,init] Memory: 16384M\n" +
"[0.008s][info][gc,init] Large Page Support: Disabled\n" +
"[0.008s][info][gc,init] NUMA Support: Disabled\n" +
"[0.008s][info][gc,init] Compressed Oops: Enabled (Zero based)\n" +
"[0.008s][info][gc,init] Heap Min Capacity: 100M\n" +
"[0.008s][info][gc,init] Heap Initial Capacity: 100M\n" +
"[0.008s][info][gc,init] Heap Max Capacity: 100M\n" +
"[0.008s][info][gc,init] Pre-touch: Disabled\n" +
"[0.008s][info][gc,metaspace] CDS archive(s) mapped at: [0x0000000800000000-0x0000000800bd4000-0x0000000800bd4000), size 12402688, SharedBaseAddress: 0x0000000800000000, ArchiveRelocationMode: 0.\n" +
"[0.008s][info][gc,metaspace] Compressed class space mapped at: 0x0000000800c00000-0x0000000840c00000, reserved size: 1073741824\n" +
"[0.008s][info][gc,metaspace] Narrow klass base: 0x0000000800000000, Narrow klass shift: 0, Narrow klass range: 0x100000000\n" +
"[0.173s][info][gc,start ] GC(0) Pause Young (Allocation Failure)\n" +
"[0.194s][info][gc,heap ] GC(0) DefNew: 40960K(46080K)->5120K(46080K) Eden: 40960K(40960K)->0K(40960K) From: 0K(5120K)->5120K(5120K)\n" +
"[0.194s][info][gc,heap ] GC(0) Tenured: 0K(51200K)->14524K(51200K)\n" +
"[0.194s][info][gc,metaspace] GC(0) Metaspace: 137K(384K)->138K(384K) NonClass: 133K(256K)->134K(256K) Class: 4K(128K)->4K(128K)\n" +
"[0.194s][info][gc ] GC(0) Pause Young (Allocation Failure) 40M->19M(95M) 21.766ms\n" +
"[0.194s][info][gc,cpu ] GC(0) User=0.01s Sys=0.00s Real=0.02s\n" +
"[2.616s][info][gc,start ] GC(1) Pause Full (Allocation Failure)\n" +
"[2.616s][info][gc,phases,start] GC(1) Phase 1: Mark live objects\n" +
"[2.665s][info][gc,phases ] GC(1) Phase 1: Mark live objects 49.316ms\n" +
"[2.665s][info][gc,phases,start] GC(1) Phase 2: Compute new object addresses\n" +
"[2.677s][info][gc,phases ] GC(1) Phase 2: Compute new object addresses 12.103ms\n" +
"[2.677s][info][gc,phases,start] GC(1) Phase 3: Adjust pointers\n" +
"[2.698s][info][gc,phases ] GC(1) Phase 3: Adjust pointers 20.186ms\n" +
"[2.698s][info][gc,phases,start] GC(1) Phase 4: Move objects\n" +
"[2.708s][info][gc,phases ] GC(1) Phase 4: Move objects 10.313ms\n" +
"[2.708s][info][gc,heap ] GC(1) DefNew: 46079K(46080K)->36798K(46080K) Eden: 40960K(40960K)->36798K(40960K) From: 5119K(5120K)->0K(5120K)\n" +
"[2.708s][info][gc,heap ] GC(1) Tenured: 51199K(51200K)->51199K(51200K)\n" +
"[2.708s][info][gc,metaspace ] GC(1) Metaspace: 137K(384K)->137K(384K) NonClass: 133K(256K)->133K(256K) Class: 4K(128K)->4K(128K)\n" +
"[2.708s][info][gc ] GC(1) Pause Full (Allocation Failure) 94M->85M(95M) 92.137ms\n" +
"[2.708s][info][gc,cpu ] GC(1) User=0.09s Sys=0.00s Real=0.09s";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
SerialGCModel model = (SerialGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
GCEvent youngGC = model.getGcEvents().get(0);
Assert.assertEquals(youngGC.getGcid(), 0);
Assert.assertEquals(youngGC.getStartTime(), 173, DELTA);
Assert.assertEquals(youngGC.getDuration(), 21.766, DELTA);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(youngGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 40960 * 1024, 46080 * 1024, 5120 * 1024, 46080 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(EDEN), new GCMemoryItem(EDEN, 40960 * 1024, 40960 * 1024, 0 * 1024, 40960 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(SURVIVOR), new GCMemoryItem(SURVIVOR, 0 * 1024, 5120 * 1024, 5120 * 1024, 5120 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 0, 51200 * 1024, 14524 * 1024, 51200 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 137 * 1024, 384 * 1024, 138 * 1024, 384 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(NONCLASS), new GCMemoryItem(NONCLASS, 133 * 1024, 256 * 1024, 134 * 1024, 256 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(CLASS), new GCMemoryItem(CLASS, 4 * 1024, 128 * 1024, 4 * 1024, 128 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 40 * 1024 * 1024, 95 * 1024 * 1024, 19 * 1024 * 1024, 95 * 1024 * 1024));
Assert.assertEquals(youngGC.getCpuTime().getReal(), 20, DELTA);
GCEvent fullGC = model.getGcEvents().get(1);
Assert.assertEquals(fullGC.getGcid(), 1);
Assert.assertEquals(fullGC.getStartTime(), 2616, DELTA);
Assert.assertEquals(fullGC.getDuration(), 92.137, DELTA);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(fullGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 46079 * 1024, 46080 * 1024, 36798 * 1024, 46080 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(EDEN), new GCMemoryItem(EDEN, 40960 * 1024, 40960 * 1024, 36798 * 1024, 40960 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(SURVIVOR), new GCMemoryItem(SURVIVOR, 5119 * 1024, 5120 * 1024, 0 * 1024, 5120 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 51199 * 1024, 51200 * 1024, 51199 * 1024, 51200 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 137 * 1024, 384 * 1024, 137 * 1024, 384 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(NONCLASS), new GCMemoryItem(NONCLASS, 133 * 1024, 256 * 1024, 133 * 1024, 256 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(CLASS), new GCMemoryItem(CLASS, 4 * 1024, 128 * 1024, 4 * 1024, 128 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 94 * 1024 * 1024, 95 * 1024 * 1024, 85 * 1024 * 1024, 95 * 1024 * 1024));
Assert.assertEquals(fullGC.getPhases().size(), 4);
for (GCEvent phase : fullGC.getPhases()) {
Assert.assertTrue(phase.getStartTime() != UNKNOWN_DOUBLE);
Assert.assertTrue(phase.getDuration() != UNKNOWN_DOUBLE);
}
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.SERIAL_COMPUTE_NEW_OBJECT_ADDRESSES).getDuration(), 12.103, DELTA);
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.SERIAL_MOVE_OBJECTS).getDuration(), 10.313, DELTA);
}
@Test
public void TestJDK17ParallelGCParser() throws Exception {
String log = "[0.017s][info][gc] Using Parallel\n" +
"[0.018s][info][gc,init] Version: 17.0.1+12-39 (release)\n" +
"[0.018s][info][gc,init] CPUs: 8 total, 8 available\n" +
"[0.018s][info][gc,init] Memory: 16384M\n" +
"[0.018s][info][gc,init] Large Page Support: Disabled\n" +
"[0.018s][info][gc,init] NUMA Support: Disabled\n" +
"[0.018s][info][gc,init] Compressed Oops: Enabled (Zero based)\n" +
"[0.018s][info][gc,init] Alignments: Space 512K, Generation 512K, Heap 2M\n" +
"[0.018s][info][gc,init] Heap Min Capacity: 100M\n" +
"[0.018s][info][gc,init] Heap Initial Capacity: 100M\n" +
"[0.018s][info][gc,init] Heap Max Capacity: 100M\n" +
"[0.018s][info][gc,init] Pre-touch: Disabled\n" +
"[0.018s][info][gc,init] Parallel Workers: 8\n" +
"[0.019s][info][gc,metaspace] CDS archive(s) mapped at: [0x0000000800000000-0x0000000800bd4000-0x0000000800bd4000), size 12402688, SharedBaseAddress: 0x0000000800000000, ArchiveRelocationMode: 0.\n" +
"[0.019s][info][gc,metaspace] Compressed class space mapped at: 0x0000000800c00000-0x0000000840c00000, reserved size: 1073741824\n" +
"[0.019s][info][gc,metaspace] Narrow klass base: 0x0000000800000000, Narrow klass shift: 0, Narrow klass range: 0x100000000\n" +
"[0.222s][info][gc,start ] GC(0) Pause Young (Allocation Failure)\n" +
"[0.232s][info][gc,heap ] GC(0) PSYoungGen: 38912K(45056K)->6137K(45056K) Eden: 38912K(38912K)->0K(38912K) From: 0K(6144K)->6137K(6144K)\n" +
"[0.232s][info][gc,heap ] GC(0) ParOldGen: 0K(51200K)->13208K(51200K)\n" +
"[0.232s][info][gc,metaspace] GC(0) Metaspace: 135K(384K)->135K(384K) NonClass: 131K(256K)->131K(256K) Class: 4K(128K)->4K(128K)\n" +
"[0.232s][info][gc ] GC(0) Pause Young (Allocation Failure) 38M->18M(94M) 10.085ms\n" +
"[0.232s][info][gc,cpu ] GC(0) User=0.02s Sys=0.01s Real=0.01s\n" +
"[0.547s][info][gc,start ] GC(1) Pause Full (Ergonomics)\n" +
"[0.548s][info][gc,phases,start] GC(1) Marking Phase\n" +
"[0.561s][info][gc,phases ] GC(1) Marking Phase 13.555ms\n" +
"[0.561s][info][gc,phases,start] GC(1) Summary Phase\n" +
"[0.561s][info][gc,phases ] GC(1) Summary Phase 0.006ms\n" +
"[0.561s][info][gc,phases,start] GC(1) Adjust Roots\n" +
"[0.561s][info][gc,phases ] GC(1) Adjust Roots 0.238ms\n" +
"[0.561s][info][gc,phases,start] GC(1) Compaction Phase\n" +
"[0.568s][info][gc,phases ] GC(1) Compaction Phase 6.917ms\n" +
"[0.568s][info][gc,phases,start] GC(1) Post Compact\n" +
"[0.568s][info][gc,phases ] GC(1) Post Compact 0.222ms\n" +
"[0.569s][info][gc,heap ] GC(1) PSYoungGen: 6128K(45056K)->0K(45056K) Eden: 0K(38912K)->0K(38912K) From: 6128K(6144K)->0K(6144K)\n" +
"[0.569s][info][gc,heap ] GC(1) ParOldGen: 46504K(51200K)->38169K(51200K)\n" +
"[0.569s][info][gc,metaspace ] GC(1) Metaspace: 135K(384K)->135K(384K) NonClass: 131K(256K)->131K(256K) Class: 4K(128K)->4K(128K)\n" +
"[0.569s][info][gc ] GC(1) Pause Full (Ergonomics) 51M->37M(94M) 21.046ms\n" +
"[0.569s][info][gc,cpu ] GC(1) User=0.04s Sys=0.00s Real=0.02s";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
ParallelGCModel model = (ParallelGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
GCEvent youngGC = model.getGcEvents().get(0);
Assert.assertEquals(youngGC.getGcid(), 0);
Assert.assertEquals(youngGC.getStartTime(), 222, DELTA);
Assert.assertEquals(youngGC.getDuration(), 10.085, DELTA);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getCause(), ALLOCATION_FAILURE);
Assert.assertEquals(youngGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 38912 * 1024, 45056 * 1024, 6137 * 1024, 45056 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(EDEN), new GCMemoryItem(EDEN, 38912 * 1024, 38912 * 1024, 0 * 1024, 38912 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(SURVIVOR), new GCMemoryItem(SURVIVOR, 0 * 1024, 6144 * 1024, 6137 * 1024, 6144 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 0, 51200 * 1024, 13208 * 1024, 51200 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 135 * 1024, 384 * 1024, 135 * 1024, 384 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(NONCLASS), new GCMemoryItem(NONCLASS, 131 * 1024, 256 * 1024, 131 * 1024, 256 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(CLASS), new GCMemoryItem(CLASS, 4 * 1024, 128 * 1024, 4 * 1024, 128 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 38 * 1024 * 1024, (45056 + 51200) * 1024, 18 * 1024 * 1024, 94 * 1024 * 1024));
Assert.assertEquals(youngGC.getCpuTime().getReal(), 10, DELTA);
GCEvent fullGC = model.getGcEvents().get(1);
Assert.assertEquals(fullGC.getGcid(), 1);
Assert.assertEquals(fullGC.getStartTime(), 547, DELTA);
Assert.assertEquals(fullGC.getDuration(), 21.046, DELTA);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getCause(), ERGONOMICS);
Assert.assertEquals(fullGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 6128 * 1024, 45056 * 1024, 0 * 1024, 45056 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(EDEN), new GCMemoryItem(EDEN, 0 * 1024, 38912 * 1024, 0 * 1024, 38912 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(SURVIVOR), new GCMemoryItem(SURVIVOR, 6128 * 1024, 6144 * 1024, 0 * 1024, 6144 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 46504 * 1024, 51200 * 1024, 38169 * 1024, 51200 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 135 * 1024, 384 * 1024, 135 * 1024, 384 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(NONCLASS), new GCMemoryItem(NONCLASS, 131 * 1024, 256 * 1024, 131 * 1024, 256 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(CLASS), new GCMemoryItem(CLASS, 4 * 1024, 128 * 1024, 4 * 1024, 128 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 51 * 1024 * 1024, (45056 + 51200) * 1024, 37 * 1024 * 1024, 94 * 1024 * 1024));
Assert.assertEquals(fullGC.getPhases().size(), 5);
for (GCEvent phase : fullGC.getPhases()) {
Assert.assertTrue(phase.getStartTime() != UNKNOWN_DOUBLE);
Assert.assertTrue(phase.getDuration() != UNKNOWN_DOUBLE);
}
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.PARALLEL_PHASE_SUMMARY).getDuration(), 0.006, DELTA);
Assert.assertEquals(fullGC.getLastPhaseOfType(GCEventType.PARALLEL_PHASE_COMPACTION).getDuration(), 6.917, DELTA);
Assert.assertEquals(fullGC.getCpuTime().getReal(), 20, DELTA);
}
@Test
public void testJDK17ZGCParser() throws Exception {
String log =
"[0.105s][info][gc,init] Initializing The Z Garbage Collector\n" +
"[0.105s][info][gc,init] Version: 17.0.1+12-39 (release)\n" +
"[0.105s][info][gc,init] NUMA Support: Disabled\n" +
"[0.105s][info][gc,init] CPUs: 8 total, 8 available\n" +
"[0.106s][info][gc,init] Memory: 16384M\n" +
"[0.106s][info][gc,init] Large Page Support: Disabled\n" +
"[0.106s][info][gc,init] GC Workers: 2 (dynamic)\n" +
"[0.107s][info][gc,init] Address Space Type: Contiguous/Unrestricted/Complete\n" +
"[0.107s][info][gc,init] Address Space Size: 16000M x 3 = 48000M\n" +
"[0.107s][info][gc,init] Min Capacity: 1000M\n" +
"[0.107s][info][gc,init] Initial Capacity: 1000M\n" +
"[0.107s][info][gc,init] Max Capacity: 1000M\n" +
"[0.107s][info][gc,init] Medium Page Size: 16M\n" +
"[0.107s][info][gc,init] Pre-touch: Disabled\n" +
"[0.107s][info][gc,init] Uncommit: Implicitly Disabled (-Xms equals -Xmx)\n" +
"[0.109s][info][gc,init] Runtime Workers: 5\n" +
"[0.111s][info][gc ] Using The Z Garbage Collector\n" +
"[0.114s][info][gc,metaspace] CDS archive(s) mapped at: [0x0000000800000000-0x0000000800bac000-0x0000000800bac000), size 12238848, SharedBaseAddress: 0x0000000800000000, ArchiveRelocationMode: 0.\n" +
"[0.114s][info][gc,metaspace] Compressed class space mapped at: 0x0000000800c00000-0x0000000840c00000, reserved size: 1073741824\n" +
"[0.114s][info][gc,metaspace] Narrow klass base: 0x0000000800000000, Narrow klass shift: 0, Narrow klass range: 0x100000000\n" +
"[0.918s][info][gc,start ] GC(0) Garbage Collection (Warmup)\n" +
"[0.918s][info][gc,task ] GC(0) Using 2 workers\n" +
"[0.918s][info][gc,phases ] GC(0) Pause Mark Start 0.007ms\n" +
"[0.939s][info][gc,phases ] GC(0) Concurrent Mark 20.975ms\n" +
"[0.939s][info][gc,phases ] GC(0) Pause Mark End 0.031ms\n" +
"[0.939s][info][gc,phases ] GC(0) Concurrent Mark Free 0.001ms\n" +
"[0.940s][info][gc,phases ] GC(0) Concurrent Process Non-Strong References 0.238ms\n" +
"[0.940s][info][gc,phases ] GC(0) Concurrent Reset Relocation Set 0.001ms\n" +
"[0.948s][info][gc,phases ] GC(0) Concurrent Select Relocation Set 8.843ms\n" +
"[0.949s][info][gc,phases ] GC(0) Pause Relocate Start 0.008ms\n" +
"[0.949s][info][gc,phases ] GC(0) Concurrent Relocate 0.811ms\n" +
"[0.950s][info][gc,load ] GC(0) Load: 3.83/4.68/5.15\n" +
"[0.950s][info][gc,mmu ] GC(0) MMU: 2ms/98.4%, 5ms/99.4%, 10ms/99.6%, 20ms/99.8%, 50ms/99.9%, 100ms/100.0%\n" +
"[0.950s][info][gc,marking ] GC(0) Mark: 2 stripe(s), 2 proactive flush(es), 1 terminate flush(es), 0 completion(s), 0 continuation(s)\n" +
"[0.950s][info][gc,marking ] GC(0) Mark Stack Usage: 32M\n" +
"[0.950s][info][gc,nmethod ] GC(0) NMethods: 91 registered, 0 unregistered\n" +
"[0.950s][info][gc,metaspace] GC(0) Metaspace: 0M used, 0M committed, 1032M reserved\n" +
"[0.950s][info][gc,ref ] GC(0) Soft: 5 encountered, 0 discovered, 0 enqueued\n" +
"[0.950s][info][gc,ref ] GC(0) Weak: 5 encountered, 0 discovered, 0 enqueued\n" +
"[0.950s][info][gc,ref ] GC(0) Final: 0 encountered, 0 discovered, 0 enqueued\n" +
"[0.950s][info][gc,ref ] GC(0) Phantom: 1 encountered, 0 discovered, 0 enqueued\n" +
"[0.950s][info][gc,reloc ] GC(0) Small Pages: 44 / 88M, Empty: 10M, Relocated: 1M, In-Place: 0\n" +
"[0.950s][info][gc,reloc ] GC(0) Medium Pages: 1 / 16M, Empty: 0M, Relocated: 0M, In-Place: 0\n" +
"[0.950s][info][gc,reloc ] GC(0) Large Pages: 0 / 0M, Empty: 0M, Relocated: 0M, In-Place: 0\n" +
"[0.950s][info][gc,reloc ] GC(0) Forwarding Usage: 0M\n" +
"[0.950s][info][gc,heap ] GC(0) Min Capacity: 1000M(100%)\n" +
"[0.950s][info][gc,heap ] GC(0) Max Capacity: 1000M(100%)\n" +
"[0.950s][info][gc,heap ] GC(0) Soft Max Capacity: 1000M(100%)\n" +
"[0.950s][info][gc,heap ] GC(0) Mark Start Mark End Relocate Start Relocate End High Low\n" +
"[0.950s][info][gc,heap ] GC(0) Capacity: 1000M (100%) 1000M (100%) 1000M (100%) 1000M (100%) 1000M (100%) 1000M (100%)\n" +
"[0.950s][info][gc,heap ] GC(0) Free: 896M (90%) 892M (89%) 902M (90%) 912M (91%) 912M (91%) 892M (89%)\n" +
"[0.950s][info][gc,heap ] GC(0) Used: 104M (10%) 108M (11%) 98M (10%) 88M (9%) 108M (11%) 88M (9%)\n" +
"[0.950s][info][gc,heap ] GC(0) Live: - 65M (7%) 65M (7%) 65M (7%) - -\n" +
"[0.950s][info][gc,heap ] GC(0) Allocated: - 4M (0%) 4M (0%) 3M (0%) - -\n" +
"[0.950s][info][gc,heap ] GC(0) Garbage: - 38M (4%) 28M (3%) 18M (2%) - -\n" +
"[0.950s][info][gc,heap ] GC(0) Reclaimed: - - 10M (1%) 19M (2%) - -\n" +
"[0.950s][info][gc ] GC(0) Garbage Collection (Warmup) 104M(10%)->88M(9%)\n" +
"[10.417s][info][gc,stats ] === Garbage Collection Statistics =======================================================================================================================\n" +
"[10.417s][info][gc,stats ] Last 10s Last 10m Last 10h Total\n" +
"[10.417s][info][gc,stats ] Avg / Max Avg / Max Avg / Max Avg / Max\n" +
"[10.417s][info][gc,stats ] Collector: Garbage Collection Cycle 52.097 / 71.589 52.097 / 71.589 52.097 / 71.589 52.097 / 71.589 ms\n" +
"[10.417s][info][gc,stats ] Contention: Mark Segment Reset Contention 0 / 1 0 / 1 0 / 1 0 / 1 ops/s\n" +
"[10.417s][info][gc,stats ] Contention: Mark SeqNum Reset Contention 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[10.417s][info][gc,stats ] Critical: Allocation Stall 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[10.417s][info][gc,stats ] Critical: Allocation Stall 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[10.418s][info][gc,stats ] Critical: GC Locker Stall 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[10.418s][info][gc,stats ] Critical: GC Locker Stall 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[10.418s][info][gc,stats ] Critical: Relocation Stall 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[10.418s][info][gc,stats ] Critical: Relocation Stall 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[10.418s][info][gc,stats ] Memory: Allocation Rate 48 / 162 48 / 162 48 / 162 48 / 162 MB/s\n" +
"[10.418s][info][gc,stats ] Memory: Out Of Memory 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[10.418s][info][gc,stats ] Memory: Page Cache Flush 0 / 0 0 / 0 0 / 0 0 / 0 MB/s\n" +
"[10.418s][info][gc,stats ] Memory: Page Cache Hit L1 4 / 15 4 / 15 4 / 15 4 / 15 ops/s\n" +
"[10.418s][info][gc,stats ] Memory: Page Cache Hit L2 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[10.418s][info][gc,stats ] Memory: Page Cache Hit L3 18 / 59 18 / 59 18 / 59 18 / 59 ops/s\n" +
"[10.418s][info][gc,stats ] Memory: Page Cache Miss 0 / 1 0 / 1 0 / 1 0 / 1 ops/s\n" +
"[10.418s][info][gc,stats ] Memory: Uncommit 0 / 0 0 / 0 0 / 0 0 / 0 MB/s\n" +
"[10.418s][info][gc,stats ] Memory: Undo Object Allocation Failed 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[10.418s][info][gc,stats ] Memory: Undo Object Allocation Succeeded 7 / 73 7 / 73 7 / 73 7 / 73 ops/s\n" +
"[10.418s][info][gc,stats ] Memory: Undo Page Allocation 0 / 0 0 / 0 0 / 0 0 / 0 ops/s\n" +
"[10.418s][info][gc,stats ] Phase: Concurrent Mark 45.361 / 66.984 45.361 / 66.984 45.361 / 66.984 45.361 / 66.984 ms\n" +
"[10.418s][info][gc,stats ] Phase: Concurrent Mark Continue 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[10.418s][info][gc,stats ] Phase: Concurrent Mark Free 0.001 / 0.001 0.001 / 0.001 0.001 / 0.001 0.001 / 0.001 ms\n" +
"[10.418s][info][gc,stats ] Phase: Concurrent Process Non-Strong References 0.423 / 0.697 0.423 / 0.697 0.423 / 0.697 0.423 / 0.697 ms\n" +
"[10.418s][info][gc,stats ] Phase: Concurrent Relocate 0.808 / 0.928 0.808 / 0.928 0.808 / 0.928 0.808 / 0.928 ms\n" +
"[10.418s][info][gc,stats ] Phase: Concurrent Reset Relocation Set 0.001 / 0.001 0.001 / 0.001 0.001 / 0.001 0.001 / 0.001 ms\n" +
"[10.418s][info][gc,stats ] Phase: Concurrent Select Relocation Set 4.461 / 8.843 4.461 / 8.843 4.461 / 8.843 4.461 / 8.843 ms\n" +
"[10.418s][info][gc,stats ] Phase: Pause Mark End 0.018 / 0.031 0.018 / 0.031 0.018 / 0.031 0.018 / 0.031 ms\n" +
"[10.418s][info][gc,stats ] Phase: Pause Mark Start 0.010 / 0.015 0.010 / 0.015 0.010 / 0.015 0.010 / 0.015 ms\n" +
"[10.418s][info][gc,stats ] Phase: Pause Relocate Start 0.007 / 0.008 0.007 / 0.008 0.007 / 0.008 0.007 / 0.008 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent Classes Purge 0.039 / 0.060 0.039 / 0.060 0.039 / 0.060 0.039 / 0.060 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent Classes Unlink 0.097 / 0.143 0.097 / 0.143 0.097 / 0.143 0.097 / 0.143 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent Mark 44.745 / 66.798 44.745 / 66.798 44.745 / 66.798 44.745 / 66.798 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent Mark Try Flush 0.185 / 0.349 0.185 / 0.349 0.185 / 0.349 0.185 / 0.349 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent Mark Try Terminate 0.558 / 1.293 0.558 / 1.293 0.558 / 1.293 0.558 / 1.293 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent References Enqueue 0.002 / 0.006 0.002 / 0.006 0.002 / 0.006 0.002 / 0.006 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent References Process 0.020 / 0.034 0.020 / 0.034 0.020 / 0.034 0.020 / 0.034 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent Roots ClassLoaderDataGraph 0.058 / 0.161 0.058 / 0.161 0.058 / 0.161 0.058 / 0.161 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent Roots CodeCache 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent Roots JavaThreads 0.100 / 0.147 0.100 / 0.147 0.100 / 0.147 0.100 / 0.147 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent Roots OopStorageSet 0.031 / 0.054 0.031 / 0.054 0.031 / 0.054 0.031 / 0.054 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Concurrent Weak Roots OopStorageSet 0.071 / 0.119 0.071 / 0.119 0.071 / 0.119 0.071 / 0.119 ms\n" +
"[10.418s][info][gc,stats ] Subphase: Pause Mark Try Complete 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms\n" +
"[10.418s][info][gc,stats ] System: Java Threads 11 / 11 11 / 11 11 / 11 11 / 11 threads\n" +
"[10.418s][info][gc,stats ] =========================================================================================================================================================";
UnifiedZGCLogParser parser = (UnifiedZGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
ZGCModel model = (ZGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 1);
Assert.assertTrue(model.getGcModelMetadata().isMetaspaceCapacityReliable());
GCEvent gc = model.getGcEvents().get(0);
Assert.assertEquals(gc.getGcid(), 0);
Assert.assertEquals(gc.getStartTime(), 918, DELTA);
Assert.assertEquals(gc.getEndTime(), 950, DELTA);
Assert.assertEquals(gc.getDuration(), 32, DELTA);
Assert.assertEquals(gc.getEventType(), GCEventType.ZGC_GARBAGE_COLLECTION);
Assert.assertEquals(gc.getCause(), WARMUP);
Assert.assertEquals(gc.getLastPhaseOfType(GCEventType.ZGC_PAUSE_MARK_START).getStartTime(), 918 - 0.007, DELTA);
Assert.assertEquals(gc.getLastPhaseOfType(GCEventType.ZGC_PAUSE_MARK_START).getDuration(), 0.007, DELTA);
Assert.assertEquals(gc.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, -1, -1, 0, 0));
Assert.assertEquals(gc.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 104L * 1024 * 1024, 1000L * 1024 * 1024, 88 * 1024 * 1024, 1000L * 1024 * 1024));
Assert.assertEquals(gc.getAllocation(), 3 * 1024 * 1024);
Assert.assertEquals(gc.getReclamation(), 19L * 1024 * 1024);
List<ZGCModel.ZStatistics> statistics = model.getStatistics();
Assert.assertEquals(statistics.size(), 1);
Assert.assertEquals(44, statistics.get(0).getStatisticItems().size());
Assert.assertEquals(statistics.get(0).getStartTime(), 10417, DELTA);
Assert.assertEquals(statistics.get(0).get("System: Java Threads threads").getMax10s(), 11, DELTA);
Assert.assertEquals(statistics.get(0).get("System: Java Threads threads").getMax10h(), 11, DELTA);
}
@Test
public void testJDK17G1Parser() throws Exception {
String log =
"[0.020s][info][gc] Using G1\n" +
"[0.022s][info][gc,init] Version: 17.0.1+12-39 (release)\n" +
"[0.022s][info][gc,init] CPUs: 8 total, 8 available\n" +
"[0.022s][info][gc,init] Memory: 16384M\n" +
"[0.022s][info][gc,init] Large Page Support: Disabled\n" +
"[0.022s][info][gc,init] NUMA Support: Disabled\n" +
"[0.022s][info][gc,init] Compressed Oops: Enabled (Zero based)\n" +
"[0.022s][info][gc,init] Heap Region Size: 1M\n" +
"[0.022s][info][gc,init] Heap Min Capacity: 100M\n" +
"[0.022s][info][gc,init] Heap Initial Capacity: 100M\n" +
"[0.022s][info][gc,init] Heap Max Capacity: 100M\n" +
"[0.022s][info][gc,init] Pre-touch: Disabled\n" +
"[0.022s][info][gc,init] Parallel Workers: 8\n" +
"[0.022s][info][gc,init] Concurrent Workers: 2\n" +
"[0.022s][info][gc,init] Concurrent Refinement Workers: 8\n" +
"[0.022s][info][gc,init] Periodic GC: Disabled\n" +
"[0.024s][info][gc,metaspace] CDS archive(s) mapped at: [0x0000000800000000-0x0000000800bd4000-0x0000000800bd4000), size 12402688, SharedBaseAddress: 0x0000000800000000, ArchiveRelocationMode: 0.\n" +
"[0.025s][info][gc,metaspace] Compressed class space mapped at: 0x0000000800c00000-0x0000000840c00000, reserved size: 1073741824\n" +
"[0.025s][info][gc,metaspace] Narrow klass base: 0x0000000800000000, Narrow klass shift: 0, Narrow klass range: 0x100000000\n" +
"[0.333s][info][gc,start ] GC(0) Pause Young (Normal) (G1 Evacuation Pause)\n" +
"[0.333s][info][gc,task ] GC(0) Using 2 workers of 8 for evacuation\n" +
"[0.354s][info][gc,phases ] GC(0) Pre Evacuate Collection Set: 0.0ms\n" +
"[0.354s][info][gc,phases ] GC(0) Merge Heap Roots: 0.1ms\n" +
"[0.354s][info][gc,phases ] GC(0) Evacuate Collection Set: 20.3ms\n" +
"[0.354s][info][gc,phases ] GC(0) Post Evacuate Collection Set: 0.2ms\n" +
"[0.354s][info][gc,phases ] GC(0) Other: 0.3ms\n" +
"[0.354s][info][gc,heap ] GC(0) Eden regions: 50->0(43)\n" +
"[0.354s][info][gc,heap ] GC(0) Survivor regions: 0->7(7)\n" +
"[0.354s][info][gc,heap ] GC(0) Old regions: 0->18\n" +
"[0.354s][info][gc,heap ] GC(0) Archive regions: 2->2\n" +
"[0.354s][info][gc,heap ] GC(0) Humongous regions: 1->1\n" +
"[0.354s][info][gc,metaspace] GC(0) Metaspace: 87K(320K)->87K(320K) NonClass: 84K(192K)->84K(192K) Class: 3K(128K)->3K(128K)\n" +
"[0.354s][info][gc ] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 51M->26M(100M) 20.955ms\n" +
"[0.354s][info][gc,cpu ] GC(0) User=0.03s Sys=0.01s Real=0.02s\n" +
"[1.097s][info][gc ] GC(1) Concurrent Mark Cycle\n" +
"[1.097s][info][gc,marking ] GC(1) Concurrent Clear Claimed Marks\n" +
"[1.097s][info][gc,marking ] GC(1) Concurrent Clear Claimed Marks 0.020ms\n" +
"[1.097s][info][gc,marking ] GC(1) Concurrent Scan Root Regions\n" +
"[1.099s][info][gc,marking ] GC(1) Concurrent Scan Root Regions 1.966ms\n" +
"[1.099s][info][gc,marking ] GC(1) Concurrent Mark\n" +
"[1.099s][info][gc,marking ] GC(1) Concurrent Mark From Roots\n" +
"[1.099s][info][gc,task ] GC(1) Using 2 workers of 2 for marking\n" +
"[1.113s][info][gc,marking ] GC(1) Concurrent Mark From Roots 14.489ms\n" +
"[1.113s][info][gc,marking ] GC(1) Concurrent Preclean\n" +
"[1.113s][info][gc,marking ] GC(1) Concurrent Preclean 0.061ms\n" +
"[1.114s][info][gc,start ] GC(1) Pause Remark\n" +
"[1.114s][info][gc ] GC(1) Pause Remark 82M->65M(100M) 0.341ms\n" +
"[1.114s][info][gc,cpu ] GC(1) User=0.00s Sys=0.00s Real=0.00s\n" +
"[1.115s][info][gc,marking ] GC(1) Concurrent Mark 15.656ms\n" +
"[1.115s][info][gc,marking ] GC(1) Concurrent Rebuild Remembered Sets\n" +
"[1.121s][info][gc,marking ] GC(1) Concurrent Rebuild Remembered Sets 6.891ms\n" +
"[1.122s][info][gc,start ] GC(1) Pause Cleanup\n" +
"[1.122s][info][gc ] GC(1) Pause Cleanup 65M->65M(100M) 0.056ms\n" +
"[1.122s][info][gc,cpu ] GC(1) User=0.00s Sys=0.00s Real=0.00s\n" +
"[1.122s][info][gc,marking ] GC(1) Concurrent Cleanup for Next Mark\n" +
"[1.122s][info][gc,marking ] GC(1) Concurrent Cleanup for Next Mark 0.417ms\n" +
"[1.122s][info][gc ] GC(1) Concurrent Mark Cycle 25.265ms\n" +
"[1.715s][info][gc,start ] GC(2) Pause Full (G1 Compaction Pause)\n" +
"[1.715s][info][gc,phases,start] GC(2) Phase 1: Mark live objects\n" +
"[1.729s][info][gc,phases ] GC(2) Phase 1: Mark live objects 14.039ms\n" +
"[1.729s][info][gc,phases,start] GC(2) Phase 2: Prepare for compaction\n" +
"[1.730s][info][gc,phases ] GC(2) Phase 2: Prepare for compaction 0.875ms\n" +
"[1.730s][info][gc,phases,start] GC(2) Phase 3: Adjust pointers\n" +
"[1.736s][info][gc,phases ] GC(2) Phase 3: Adjust pointers 6.156ms\n" +
"[1.736s][info][gc,phases,start] GC(2) Phase 4: Compact heap\n" +
"[1.738s][info][gc,phases ] GC(2) Phase 4: Compact heap 1.153ms\n" +
"[1.738s][info][gc,heap ] GC(2) Eden regions: 0->0(50)\n" +
"[1.738s][info][gc,heap ] GC(2) Survivor regions: 0->0(0)\n" +
"[1.738s][info][gc,heap ] GC(2) Old regions: 96->68\n" +
"[1.738s][info][gc,heap ] GC(2) Archive regions: 2->2\n" +
"[1.738s][info][gc,heap ] GC(2) Humongous regions: 2->1\n" +
"[1.738s][info][gc,metaspace ] GC(2) Metaspace: 87K(320K)->87K(320K) NonClass: 84K(192K)->84K(192K) Class: 3K(128K)->3K(128K)\n" +
"[1.738s][info][gc ] GC(2) Pause Full (G1 Compaction Pause) 98M->69M(100M) 22.935ms\n" +
"[1.738s][info][gc,cpu ] GC(2) User=0.04s Sys=0.00s Real=0.02s\n" +
"[2.145s][info][gc ] GC(3) Concurrent Undo Cycle\n" +
"[2.145s][info][gc,marking ] GC(3) Concurrent Cleanup for Next Mark\n" +
"[2.145s][info][gc,marking ] GC(3) Concurrent Cleanup for Next Mark 0.109ms\n" +
"[2.145s][info][gc ] GC(3) Concurrent Undo Cycle 0.125ms";
UnifiedG1GCLogParser parser = (UnifiedG1GCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
G1GCModel model = (G1GCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
// assert parsing success
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 4);
Assert.assertEquals(model.getHeapRegionSize(), 1L * 1024 * 1024);
GCEvent youngGC = model.getGcEvents().get(0);
Assert.assertEquals(youngGC.getGcid(), 0);
Assert.assertEquals(youngGC.getStartTime(), 333, DELTA);
Assert.assertEquals(youngGC.getDuration(), 20.955, DELTA);
Assert.assertEquals(youngGC.getEventType(), GCEventType.YOUNG_GC);
Assert.assertEquals(youngGC.getCause(), G1_EVACUATION_PAUSE);
Assert.assertEquals(youngGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 50 * 1024 * 1024, UNKNOWN_INT, 7 * 1024 * 1024, 50 * 1024 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(EDEN), new GCMemoryItem(EDEN, 50 * 1024 * 1024, UNKNOWN_INT, 0 * 1024 * 1024, 43 * 1024 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(SURVIVOR), new GCMemoryItem(SURVIVOR, 0 * 1024, UNKNOWN_INT, 7 * 1024 * 1024, 7 * 1024 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(OLD), new GCMemoryItem(OLD, 0, UNKNOWN_INT, 18 * 1024 * 1024, 50 * 1024 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(ARCHIVE), new GCMemoryItem(ARCHIVE, 2 * 1024 * 1024, UNKNOWN_INT, 2 * 1024 * 1024, UNKNOWN_INT));
Assert.assertEquals(youngGC.getMemoryItem(HUMONGOUS), new GCMemoryItem(HUMONGOUS, 1 * 1024 * 1024, UNKNOWN_INT, 1 * 1024 * 1024, UNKNOWN_INT));
Assert.assertEquals(youngGC.getMemoryItem(METASPACE), new GCMemoryItem(METASPACE, 87 * 1024, 320 * 1024, 87 * 1024, 320 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(NONCLASS), new GCMemoryItem(NONCLASS, 84 * 1024, 192 * 1024, 84 * 1024, 192 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(CLASS), new GCMemoryItem(CLASS, 3 * 1024, 128 * 1024, 3 * 1024, 128 * 1024));
Assert.assertEquals(youngGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 51 * 1024 * 1024, UNKNOWN_INT, 26 * 1024 * 1024, 100 * 1024 * 1024));
Assert.assertEquals(youngGC.getCpuTime().getReal(), 20, DELTA);
Assert.assertEquals(youngGC.getPhases().size(), 5);
Assert.assertEquals(youngGC.getPhases().get(1).getEventType(), GCEventType.G1_MERGE_HEAP_ROOTS);
Assert.assertEquals(youngGC.getPhases().get(1).getDuration(), 0.1, DELTA);
for (GCEvent phase : youngGC.getPhases()) {
Assert.assertTrue(phase.getStartTime() >= 0);
Assert.assertTrue(phase.getDuration() >= 0);
}
GCEvent concurrentCycle = model.getGcEvents().get(1);
Assert.assertEquals(concurrentCycle.getEventType(), GCEventType.G1_CONCURRENT_CYCLE);
Assert.assertEquals(concurrentCycle.getGcid(), 1);
Assert.assertEquals(concurrentCycle.getStartTime(), 1097, DELTA);
Assert.assertEquals(concurrentCycle.getDuration(), 25.265, DELTA);
Assert.assertEquals(concurrentCycle.getPhases().size(), 9);
for (GCEvent phase : concurrentCycle.getPhases()) {
Assert.assertTrue(phase.getStartTime() > 0);
Assert.assertTrue(phase.getDuration() > 0);
}
GCEvent fullGC = model.getGcEvents().get(2);
Assert.assertEquals(fullGC.getGcid(), 2);
Assert.assertEquals(fullGC.getStartTime(), 1715, DELTA);
Assert.assertEquals(fullGC.getDuration(), 22.935, DELTA);
Assert.assertEquals(fullGC.getEventType(), GCEventType.FULL_GC);
Assert.assertEquals(fullGC.getCause(), G1_COMPACTION);
Assert.assertEquals(fullGC.getMemoryItem(YOUNG), new GCMemoryItem(YOUNG, 0 * 1024 * 1024, UNKNOWN_INT, 0 * 1024 * 1024, 50 * 1024 * 1024));
Assert.assertEquals(fullGC.getMemoryItem(HEAP), new GCMemoryItem(HEAP, 98 * 1024 * 1024, UNKNOWN_INT, 69 * 1024 * 1024, 100 * 1024 * 1024));
Assert.assertEquals(fullGC.getCpuTime().getReal(), 20, DELTA);
Assert.assertEquals(fullGC.getPhases().size(), 4);
for (GCEvent phase : fullGC.getPhases()) {
Assert.assertTrue(phase.getStartTime() >= 0);
Assert.assertTrue(phase.getDuration() >= 0);
}
GCEvent concurrentUndo = model.getGcEvents().get(3);
Assert.assertEquals(concurrentUndo.getEventType(), GCEventType.G1_CONCURRENT_UNDO_CYCLE);
Assert.assertEquals(concurrentUndo.getGcid(), 3);
Assert.assertEquals(concurrentUndo.getStartTime(), 2145, DELTA);
Assert.assertEquals(concurrentUndo.getDuration(), 0.125, DELTA);
Assert.assertEquals(concurrentUndo.getPhases().size(), 1);
for (GCEvent phase : concurrentUndo.getPhases()) {
Assert.assertTrue(phase.getStartTime() > 0);
Assert.assertTrue(phase.getDuration() > 0);
}
GCLogMetadata metadata = model.getGcModelMetadata();
Assert.assertTrue(metadata.getImportantEventTypes().contains(GCEventType.G1_CONCURRENT_REBUILD_REMEMBERED_SETS.getName()));
Assert.assertTrue(metadata.getImportantEventTypes().contains(GCEventType.G1_CONCURRENT_UNDO_CYCLE.getName()));
}
@Test
public void testJDK17G1InferRegionSize() throws Exception {
String log =
"[1.715s][info][gc,start ] GC(2) Pause Full (G1 Compaction Pause)\n" +
"[1.715s][info][gc,phases,start] GC(2) Phase 1: Mark live objects\n" +
"[1.729s][info][gc,phases ] GC(2) Phase 1: Mark live objects 14.039ms\n" +
"[1.729s][info][gc,phases,start] GC(2) Phase 2: Prepare for compaction\n" +
"[1.730s][info][gc,phases ] GC(2) Phase 2: Prepare for compaction 0.875ms\n" +
"[1.730s][info][gc,phases,start] GC(2) Phase 3: Adjust pointers\n" +
"[1.736s][info][gc,phases ] GC(2) Phase 3: Adjust pointers 6.156ms\n" +
"[1.736s][info][gc,phases,start] GC(2) Phase 4: Compact heap\n" +
"[1.738s][info][gc,phases ] GC(2) Phase 4: Compact heap 1.153ms\n" +
"[1.738s][info][gc,heap ] GC(2) Eden regions: 0->0(50)\n" +
"[1.738s][info][gc,heap ] GC(2) Survivor regions: 0->0(0)\n" +
"[1.738s][info][gc,heap ] GC(2) Old regions: 96->68\n" +
"[1.738s][info][gc,heap ] GC(2) Archive regions: 2->2\n" +
"[1.738s][info][gc,heap ] GC(2) Humongous regions: 2->1\n" +
"[1.738s][info][gc,metaspace ] GC(2) Metaspace: 87K(320K)->87K(320K) NonClass: 84K(192K)->84K(192K) Class: 3K(128K)->3K(128K)\n" +
"[1.738s][info][gc ] GC(2) Pause Full (G1 Compaction Pause) 98M->69M(100M) 22.935ms\n" +
"[1.738s][info][gc,cpu ] GC(2) User=0.04s Sys=0.00s Real=0.02s";
UnifiedG1GCLogParser parser = (UnifiedG1GCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
G1GCModel model = (G1GCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
// assert parsing success
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().size(), 1);
Assert.assertEquals(model.getHeapRegionSize(), 1L * 1024 * 1024);
}
}
| 6,714 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa/gclog/TestGlobalDiagnoser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog;
import org.eclipse.jifa.common.listener.DefaultProgressListener;
import org.eclipse.jifa.gclog.diagnoser.AnalysisConfig;
import org.eclipse.jifa.gclog.diagnoser.GlobalDiagnoser;
import org.eclipse.jifa.gclog.diagnoser.GlobalDiagnoser.*;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.parser.GCLogParser;
import org.eclipse.jifa.gclog.parser.GCLogParserFactory;
import org.eclipse.jifa.gclog.util.I18nStringView;
import org.eclipse.jifa.gclog.vo.TimeRange;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import java.util.Map;
import java.util.stream.DoubleStream;
import static org.eclipse.jifa.gclog.TestUtil.*;
import static org.eclipse.jifa.gclog.diagnoser.AbnormalType.*;
import static org.eclipse.jifa.gclog.diagnoser.AnalysisConfig.defaultConfig;
public class TestGlobalDiagnoser {
public static final double DELTA = 1e-6;
@Before
public void setExtendTime() {
GlobalDiagnoser.setExtendTime(30000);
}
@Test
public void testDiagnoseBasic() throws Exception {
String log = "3.765: [Full GC (Metadata GC Threshold) 3.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]\n" +
"12.765: [Full GC (Last ditch collection) 12.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]\n" +
"80.765: [Full GC (System.gc()) 80.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]\n" +
"95.765: [Full GC (Allocation Failure) 95.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]\n" +
"103.765: [Full GC (Metadata GC Threshold) 103.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]\n" +
"120.765: [Full GC (Metadata GC Threshold) 120.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]\n" +
"155.765: [Full GC (Last ditch collection) 155.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
GCModel model = parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertEquals(model.getGcEvents().size(), 7);
GlobalAbnormalInfo diagnose = new GlobalDiagnoser(model, defaultConfig(model)).diagnose();
Map<String, List<Double>> seriousProblems = diagnose.getSeriousProblems();
Assert.assertEquals(seriousProblems.size(), 3);
Assert.assertArrayEquals(seriousProblems.get(METASPACE_FULL_GC.getName()).stream().mapToDouble(d -> d).toArray(),
new double[]{3765, 12765, 103765, 120765, 155765}, DELTA);
Assert.assertArrayEquals(seriousProblems.get(SYSTEM_GC.getName()).stream().mapToDouble(d -> d).toArray(),
new double[]{80765}, DELTA);
Assert.assertArrayEquals(seriousProblems.get(HEAP_MEMORY_FULL_GC.getName()).stream().mapToDouble(d -> d).toArray(),
new double[]{95765}, DELTA);
MostSeriousProblemSummary mostSeriousProblem = diagnose.getMostSeriousProblem();
Assert.assertEquals(mostSeriousProblem.getProblem(), new I18nStringView("jifa.gclog.diagnose.abnormal.metaspaceFullGC"));
Assert.assertTrue(mostSeriousProblem.getSuggestions().contains(new I18nStringView("jifa.gclog.diagnose.suggestion.checkMetaspace")));
Assert.assertTrue(mostSeriousProblem.getSuggestions().contains(new I18nStringView("jifa.gclog.diagnose.suggestion.enlargeMetaspace")));
Assert.assertFalse(mostSeriousProblem.getSuggestions().contains(new I18nStringView("jifa.gclog.diagnose.suggestion.upgradeTo11G1FullGC")));
List<TimeRange> sites = mostSeriousProblem.getSites();
Assert.assertEquals(sites.size(), 2);
double[] actual = sitesToArray(sites);
Assert.assertArrayEquals(actual, new double[]{0, 42765 + 115.0614, 73765, 155765 + 115.0614}, DELTA);
AnalysisConfig config = defaultConfig(model);
config.setTimeRange(new TimeRange(100000, 130000));
diagnose = new GlobalDiagnoser(model, config).diagnose();
seriousProblems = diagnose.getSeriousProblems();
Assert.assertEquals(seriousProblems.size(), 1);
Assert.assertEquals(seriousProblems.get(METASPACE_FULL_GC.getName()).size(), 2);
}
@Test
public void testNoProblem() throws Exception {
String log = "2020-12-27T00:29:54.757+0800: 1062298.547: [GC (Allocation Failure) 2020-12-27T00:29:54.757+0800: 1062298.547: [ParNew: 1826919K->78900K(1922432K), 0.0572643 secs] 3445819K->1697799K(4019584K), 0.0575802 secs] [Times: user=0.21 sys=0.00, real=0.05 secs]\n" +
"2020-12-27T01:03:34.874+0800: 1064318.664: [GC (Allocation Failure) 2020-12-27T01:03:34.874+0800: 1064318.665: [ParNew: 1826612K->80229K(1922432K), 0.0554822 secs] 3445511K->1699129K(4019584K), 0.0558081 secs] [Times: user=0.21 sys=0.00, real=0.06 secs]\n" +
"2020-12-27T01:47:52.957+0800: 1066976.747: [GC (Allocation Failure) 2020-12-27T01:47:52.957+0800: 1066976.747: [ParNew: 1827941K->134685K(1922432K), 0.0735485 secs] 3446841K->1753585K(4019584K), 0.0738704 secs] [Times: user=0.23 sys=0.00, real=0.07 secs]\n" +
"2020-12-27T02:39:47.913+0800: 1070091.703: [GC (Allocation Failure) 2020-12-27T02:39:47.913+0800: 1070091.703: [ParNew: 1882397K->80118K(1922432K), 0.0804496 secs] 3501297K->1740153K(4019584K), 0.0807793 secs] [Times: user=0.26 sys=0.01, real=0.08 secs]\n" +
"2020-12-27T03:31:13.977+0800: 1073177.767: [GC (Allocation Failure) 2020-12-27T03:31:13.977+0800: 1073177.767: [ParNew: 1827753K->74440K(1922432K), 0.0303335 secs] 3487788K->1734475K(4019584K), 0.0306656 secs] [Times: user=0.10 sys=0.00, real=0.03 secs]\n" +
"2020-12-27T04:21:42.951+0800: 1076206.741: [GC (Allocation Failure) 2020-12-27T04:21:42.951+0800: 1076206.741: [ParNew: 1822152K->76115K(1922432K), 0.0357291 secs] 3482187K->1736150K(4019584K), 0.0360764 secs] [Times: user=0.13 sys=0.00, real=0.04 secs]\n" +
"2020-12-27T05:13:19.851+0800: 1079303.642: [GC (Allocation Failure) 2020-12-27T05:13:19.851+0800: 1079303.642: [ParNew: 1823827K->68185K(1922432K), 0.0312874 secs] 3483862K->1728220K(4019584K), 0.0316223 secs] [Times: user=0.10 sys=0.01, real=0.03 secs]";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
GCModel model = parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
GlobalAbnormalInfo diagnose = new GlobalDiagnoser(model, defaultConfig(model)).diagnose();
Assert.assertEquals(diagnose.getSeriousProblems().size(), 0);
Assert.assertNull(diagnose.getMostSeriousProblem());
}
@Test
public void testOrderSites() throws Exception {
String log = "4.204: [GC (Allocation Failure) 4.204: [ParNew: 7575411K->562327K(7689600K), 0.4413861 secs] 8149808K->1188439K(20272512K), 0.4422627 secs] [Times: user=1.33 sys=0.07, real=0.44 secs]\n" +
"24.204: [GC (Allocation Failure) 14.204: [ParNew: 7575411K->562327K(7689600K), 0.4413861 secs] 8149808K->1188439K(20272512K), 0.4422627 secs] [Times: user=1.33 sys=0.07, real=0.44 secs]\n" +
"67.512: [GC (Allocation Failure) 67.512: [ParNew: 1879618K->93403K(1922432K), 0.1367250 secs] 1990018K->251801K(4019584K), 0.1369409 secs] [Times: user=0.40 sys=0.05, real=0.14 secs]\n" +
"104.204: [GC (Allocation Failure) 104.204: [ParNew: 7575411K->562327K(7689600K), 0.4413861 secs] 8149808K->1188439K(20272512K), 0.4422627 secs] [Times: user=1.33 sys=0.07, real=0.44 secs]\n" +
"114.204: [GC (Allocation Failure) 114.204: [ParNew: 7575411K->562327K(7689600K), 0.4413861 secs] 8149808K->1188439K(20272512K), 0.4422627 secs] [Times: user=1.33 sys=0.07, real=0.44 secs]\n" +
"204.204: [GC (Allocation Failure) 204.204: [ParNew: 7575411K->562327K(7689600K), 0.4413861 secs] 8149808K->1188439K(20272512K), 0.4422627 secs] [Times: user=1.33 sys=0.07, real=0.44 secs]\n" +
"214.512: [GC (Allocation Failure) 214.512: [ParNew: 1879618K->93403K(1922432K), 0.1367250 secs] 1990018K->251801K(4019584K), 0.1369409 secs] [Times: user=0.40 sys=0.05, real=0.14 secs]\n" +
"224.204: [GC (Allocation Failure) 224.204: [ParNew: 7575411K->562327K(7689600K), 0.4413861 secs] 8149808K->1188439K(20272512K), 0.4422627 secs] [Times: user=1.33 sys=0.07, real=0.44 secs]\n" +
"274.204: [GC (Allocation Failure) 274.204: [ParNew: 7575411K->562327K(7689600K), 0.4413861 secs] 8149808K->1188439K(20272512K), 0.4422627 secs] [Times: user=1.33 sys=0.07, real=0.44 secs]\n" +
"404.204: [GC (Allocation Failure) 304.204: [ParNew: 7575411K->562327K(7689600K), 0.4413861 secs] 8149808K->1188439K(20272512K), 0.4422627 secs] [Times: user=1.33 sys=0.07, real=0.44 secs]\n" +
"444.204: [GC (Allocation Failure) 344.204: [ParNew: 7575411K->562327K(7689600K), 0.4413861 secs] 8149808K->1188439K(20272512K), 0.4422627 secs] [Times: user=1.33 sys=0.07, real=0.44 secs]\n";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
GCModel model = parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
GlobalAbnormalInfo diagnose = new GlobalDiagnoser(model, defaultConfig(model)).diagnose();
MostSeriousProblemSummary mostSeriousProblem = diagnose.getMostSeriousProblem();
Assert.assertEquals(mostSeriousProblem.getProblem(), new I18nStringView("jifa.gclog.diagnose.abnormal.longYoungGCPause"));
Assert.assertTrue(mostSeriousProblem.getSuggestions().contains(new I18nStringView("jifa.gclog.diagnose.suggestion.shrinkYoungGen")));
List<TimeRange> sites = mostSeriousProblem.getSites();
Assert.assertEquals(sites.size(), 3);
double[] actual = sitesToArray(sites);
Assert.assertArrayEquals(actual, new double[]{0, 54204 + 442.2627, 174204, 304204 + 442.2627, 374204, 444204 + 442.2627}, DELTA);
}
@Test
public void testDiagnoseZGC() throws Exception {
String log = "[7.000s] GC(374) Garbage Collection (Proactive)\n" +
"[7.006s] GC(374) Pause Mark Start 4.459ms\n" +
"[7.312s] GC(374) Concurrent Mark 306.720ms\n" +
"[7.312s] GC(374) Pause Mark End 0.606ms\n" +
"[7.313s] GC(374) Concurrent Process Non-Strong References 1.290ms\n" +
"[7.314s] GC(374) Concurrent Reset Relocation Set 0.550ms\n" +
"[7.314s] GC(374) Concurrent Destroy Detached Pages 0.001ms\n" +
"[7.316s] GC(374) Concurrent Select Relocation Set 2.418ms\n" +
"[7.321s] GC(374) Concurrent Prepare Relocation Set 5.719ms\n" +
"[7.324s] GC(374) Pause Relocate Start 3.791ms\n" +
"[7.356s] GC(374) Concurrent Relocate 32.974ms\n" +
"[7.356s] GC(374) Load: 1.68/1.99/2.04\n" +
"[7.356s] GC(374) MMU: 2ms/0.0%, 5ms/0.0%, 10ms/0.0%, 20ms/0.0%, 50ms/0.0%, 100ms/0.0%\n" +
"[7.356s] GC(374) Mark: 8 stripe(s), 2 proactive flush(es), 1 terminate flush(es), 0 completion(s), 0 continuation(s)\n" +
"[7.356s] GC(374) Relocation: Successful, 359M relocated\n" +
"[7.356s] GC(374) NMethods: 21844 registered, 609 unregistered\n" +
"[7.356s] GC(374) Metaspace: 125M used, 127M capacity, 128M committed, 130M reserved\n" +
"[7.356s] GC(374) Soft: 18634 encountered, 0 discovered, 0 enqueued\n" +
"[7.356s] GC(374) Weak: 56186 encountered, 18454 discovered, 3112 enqueued\n" +
"[7.356s] GC(374) Final: 64 encountered, 16 discovered, 7 enqueued\n" +
"[7.356s] GC(374) Phantom: 1882 encountered, 1585 discovered, 183 enqueued\n" +
"[7.356s] GC(374) Mark Start Mark End Relocate Start Relocate End High Low\n" +
"[7.356s] GC(374) Capacity: 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%)\n" +
"[7.356s] GC(374) Reserve: 96M (0%) 96M (0%) 96M (0%) 96M (0%) 96M (0%) 96M (0%)\n" +
"[7.356s] GC(374) Free: 35250M (86%) 35210M (86%) 35964M (88%) 39410M (96%) 39410M (96%) 35210M (86%)\n" +
"[7.356s] GC(374) Used: 5614M (14%) 5654M (14%) 4900M (12%) 1454M (4%) 5654M (14%) 1454M (4%)\n" +
"[7.356s] GC(374) Live: - 1173M (3%) 1173M (3%) 1173M (3%) - -\n" +
"[7.356s] GC(374) Allocated: - 40M (0%) 40M (0%) 202M (0%) - -\n" +
"[7.356s] GC(374) Garbage: - 4440M (11%) 3686M (9%) 240M (1%) - -\n" +
"[7.356s] GC(374) Reclaimed: - - 754M (2%) 4200M (10%) - -\n" +
"[7.356s] GC(374) Garbage Collection (Proactive) 5614M(14%)->1454M(4%)\n" +
"[7.777s] Allocation Stall (ThreadPoolTaskScheduler-1) 0.204ms\n" +
"[7.888s] Allocation Stall (NioProcessor-2) 0.391ms\n" +
"[7.889s] Out Of Memory (thread 8)";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
GCModel model = parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
GlobalAbnormalInfo diagnose = new GlobalDiagnoser(model, defaultConfig(model)).diagnose();
Map<String, List<Double>> seriousProblems = diagnose.getSeriousProblems();
Assert.assertEquals(seriousProblems.size(), 2);
Assert.assertArrayEquals(seriousProblems.get(ALLOCATION_STALL.getName()).stream().mapToDouble(d -> d).toArray(),
new double[]{7777 - 0.204, 7888 - 0.391}, DELTA);
Assert.assertArrayEquals(seriousProblems.get(OUT_OF_MEMORY.getName()).stream().mapToDouble(d -> d).toArray(),
new double[]{7889}, DELTA);
MostSeriousProblemSummary mostSeriousProblem = diagnose.getMostSeriousProblem();
Assert.assertEquals(mostSeriousProblem.getProblem(), new I18nStringView("jifa.gclog.diagnose.abnormal.outOfMemory"));
Assert.assertTrue(mostSeriousProblem.getSuggestions().contains(new I18nStringView("jifa.gclog.diagnose.suggestion.checkMemoryLeak")));
Assert.assertTrue(mostSeriousProblem.getSuggestions().contains(new I18nStringView("jifa.gclog.diagnose.suggestion.enlargeHeap")));
List<TimeRange> sites = mostSeriousProblem.getSites();
Assert.assertEquals(sites.size(), 1);
double[] actual = sitesToArray(sites);
Assert.assertArrayEquals(actual, new double[]{0, 7889}, DELTA);
}
private double[] sitesToArray(List<TimeRange> sites) {
return sites.stream().flatMapToDouble(site -> DoubleStream.of(site.getStart(), site.getEnd())).toArray();
}
}
| 6,715 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa/gclog/TestEventDiagnoser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog;
import org.eclipse.jifa.common.listener.DefaultProgressListener;
import org.eclipse.jifa.gclog.diagnoser.*;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.parser.GCLogParser;
import org.eclipse.jifa.gclog.parser.GCLogParserFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import static org.eclipse.jifa.gclog.TestUtil.stringToBufferedReader;
import static org.eclipse.jifa.gclog.diagnoser.AbnormalType.*;
public class TestEventDiagnoser {
public static final double DELTA = 1e-6;
@Before
public void setExtendTime() {
GlobalDiagnoser.setExtendTime(30000);
}
@Test
public void testDiagnoseBasic() throws Exception {
String log = "2022-09-05T17:30:59.396+0800: 25730.571: [GC pause (G1 Humongous Allocation) (young) (to-space exhausted), 0.6835408 secs]\n" +
" [Parallel Time: 213.6 ms, GC Workers: 4]\n" +
" [GC Worker Start (ms): Min: 25730571.4, Avg: 25730571.6, Max: 25730572.1, Diff: 0.7]\n" +
" [Ext Root Scanning (ms): Min: 5.9, Avg: 7.4, Max: 9.1, Diff: 3.2, Sum: 29.7]\n" +
" [Update RS (ms): Min: 6.7, Avg: 7.8, Max: 8.2, Diff: 1.5, Sum: 31.0]\n" +
" [Processed Buffers: Min: 22, Avg: 27.8, Max: 31, Diff: 9, Sum: 111]\n" +
" [Scan RS (ms): Min: 25.9, Avg: 26.0, Max: 26.3, Diff: 0.4, Sum: 104.2]\n" +
" [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]\n" +
" [Object Copy (ms): Min: 171.8, Avg: 172.1, Max: 172.7, Diff: 0.9, Sum: 688.5]\n" +
" [Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]\n" +
" [Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 4]\n" +
" [GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]\n" +
" [GC Worker Total (ms): Min: 212.9, Avg: 213.4, Max: 213.6, Diff: 0.7, Sum: 853.6]\n" +
" [GC Worker End (ms): Min: 25730785.0, Avg: 25730785.0, Max: 25730785.0, Diff: 0.0]\n" +
" [Code Root Fixup: 0.1 ms]\n" +
" [Code Root Purge: 0.0 ms]\n" +
" [Clear CT: 0.6 ms]\n" +
" [Other: 469.2 ms]\n" +
" [Evacuation Failure: 466.7 ms]\n" +
" [Choose CSet: 0.0 ms]\n" +
" [Ref Proc: 0.8 ms]\n" +
" [Ref Enq: 0.0 ms]\n" +
" [Redirty Cards: 0.6 ms]\n" +
" [Humongous Register: 0.0 ms]\n" +
" [Humongous Reclaim: 0.4 ms]\n" +
" [Free CSet: 0.2 ms]\n" +
" [Eden: 1824.0M(2368.0M)->0.0B(480.0M) Survivors: 98304.0K->32768.0K Heap: 4576.2M(5120.0M)->3681.4M(5120.0M)]\n" +
" [Times: user=2.17 sys=0.08, real=0.69 secs] ";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
GCModel model = parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
GlobalDiagnoseInfo diagnose = model.getGlobalDiagnoseInfo(AnalysisConfig.defaultConfig(model));
EventDiagnoseInfo[] eventDiagnoseInfos = diagnose.getEventDiagnoseInfos();
Assert.assertEquals(eventDiagnoseInfos.length, model.getAllEvents().size());
long hit = 0;
for (GCEvent event : model.getAllEvents()) {
GCEventType type = event.getEventType();
EventAbnormalSet abs = diagnose.getEventDiagnoseInfo(event).getAbnormals();
if (type == GCEventType.YOUNG_GC) {
hit++;
absContainExactTypes(abs, List.of(TO_SPACE_EXHAUSTED, BAD_DURATION, BAD_PROMOTION));
} else if (type == GCEventType.G1_EVACUATION_FAILURE) {
hit++;
absContainExactTypes(abs, List.of(BAD_EVENT_TYPE, BAD_DURATION));
} else {
assert abs.isEmpty();
}
}
Assert.assertEquals(hit, 2);
}
private void absContainExactTypes(EventAbnormalSet abs, List<AbnormalType> types) {
Assert.assertEquals(abs.size(), types.size());
for (AbnormalType type : types) {
Assert.assertTrue(abs.contains(type));
}
}
}
| 6,716 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa/gclog/TestGCModel.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog;
import org.eclipse.jifa.common.listener.DefaultProgressListener;
import org.eclipse.jifa.gclog.event.*;
import org.eclipse.jifa.gclog.event.evnetInfo.GCCause;
import org.eclipse.jifa.gclog.event.evnetInfo.GCMemoryItem;
import org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType;
import org.eclipse.jifa.gclog.model.*;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.model.modeInfo.GCLogStyle;
import org.eclipse.jifa.gclog.model.modeInfo.VmOptions;
import org.eclipse.jifa.gclog.parser.GCLogParser;
import org.eclipse.jifa.gclog.parser.GCLogParserFactory;
import org.eclipse.jifa.gclog.parser.PreUnifiedG1GCLogParser;
import org.eclipse.jifa.gclog.util.Constant;
import org.eclipse.jifa.gclog.vo.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import java.util.Map;
import static org.eclipse.jifa.gclog.TestUtil.stringToBufferedReader;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
import static org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea.*;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
public class TestGCModel {
public static final double DELTA = 1e-6;
G1GCModel model;
@Before
public void mockModel() {
model = new G1GCModel();
model.setHeapRegionSize(1024 * 1024);
model.setCollectorType(GCCollectorType.G1);
model.setLogStyle(GCLogStyle.PRE_UNIFIED);
model.setHeapRegionSize(1024 * 1024);
model.setStartTime(1.0 * 1000);
model.setParallelThread(8);
model.setVmOptions(new VmOptions("-Xmx2g -Xms2g"));
model.setReferenceTimestamp(1000.0);
GCEvent[] events = new GCEvent[6];
for (int i = 0; i < 6; i++) {
events[i] = model.createAndGetEvent();
}
events[0].setEventType(GCEventType.YOUNG_GC);
events[0].setStartTime(1.0 * 1000);
events[0].setDuration(0.5 * 1000);
events[0].setCause("G1 Evacuation Pause");
events[0].setMemoryItem(new GCMemoryItem(EDEN, 20 * 1024 * 1024, 0, 100 * 1024 * 1024));
events[0].setMemoryItem(new GCMemoryItem(SURVIVOR, 0, 10 * 1024 * 1024, 100 * 1024 * 1024));
events[0].setMemoryItem(new GCMemoryItem(HUMONGOUS, 10 * 1024 * 1024, 10 * 1024 * 1024, Constant.UNKNOWN_INT));
events[0].setMemoryItem(new GCMemoryItem(METASPACE, 15 * 1024 * 1024, 15 * 1024 * 1024, 20 * 1024 * 1024));
events[0].setMemoryItem(new GCMemoryItem(OLD, 10 * 1024 * 1024, 12 * 1024 * 1024, 100 * 1024 * 1024));
events[0].setTrue(GCEventBooleanType.TO_SPACE_EXHAUSTED);
// expected result: collectionResult.addItem(new GCCollectionResultItem(TOTAL,40*1024,32*1024,300*1024));
events[1].setEventType(GCEventType.FULL_GC);
events[1].setStartTime(3.0 * 1000);
events[1].setDuration(0.4 * 1000);
events[1].setCause("G1 Evacuation Pause");
events[1].setMemoryItem(new GCMemoryItem(EDEN, 30 * 1024 * 1024, 0, 100 * 1024 * 1024));
events[1].setMemoryItem(new GCMemoryItem(SURVIVOR, 0, 0, 100 * 1024 * 1024));
events[1].setMemoryItem(new GCMemoryItem(HUMONGOUS, 10 * 1024 * 1024, 10 * 1024 * 1024, Constant.UNKNOWN_INT));
events[1].setMemoryItem(new GCMemoryItem(OLD, 10 * 1024 * 1024, 30 * 1024 * 1024, 100 * 1024 * 1024));
// expected result: events[1].setMemoryItem(new GCCollectionResultItem(HEAP,50,40,300));
events[2].setEventType(FULL_GC);
events[2].setStartTime(12.0 * 1000);
events[2].setDuration(1.0 * 1000);
events[2].setCause("Metadata GC Threshold");
events[2].setMemoryItem(new GCMemoryItem(EDEN, 24 * 1024 * 1024, 0, 100 * 1024 * 1024));
events[2].setMemoryItem(new GCMemoryItem(SURVIVOR, 8 * 1024 * 1024, 0, 100 * 1024 * 1024));
events[2].setMemoryItem(new GCMemoryItem(HUMONGOUS, 20 * 1024 * 1024, 20 * 1024 * 1024, Constant.UNKNOWN_INT));
events[2].setMemoryItem(new GCMemoryItem(OLD, 10 * 1024 * 1024, 10 * 1024 * 1024, 100 * 1024 * 1024));
events[2].setMemoryItem(new GCMemoryItem(HEAP, 62 * 1024 * 1024, 30 * 1024 * 1024, 300 * 1024 * 1024));
events[3].setEventType(G1_CONCURRENT_CYCLE);
events[3].setStartTime(16.0 * 1000);
events[3].setDuration(1.2 * 1000);
GCEventType[] concurrentCyclePhases = {G1_REMARK, G1_PAUSE_CLEANUP, G1_CONCURRENT_CLEAR_CLAIMED_MARKS};
double[] begins = {16.0, 16.2, 16.6};
for (int i = 0; i < concurrentCyclePhases.length; i++) {
GCEvent phase = new GCEvent();
phase.setGcid(4);
model.addPhase(events[3], phase);
phase.setEventType(concurrentCyclePhases[i]);
phase.setDuration(0.2 * (i + 1) * 1000);
phase.setStartTime(begins[i] * 1000);
}
events[3].getPhases().get(0).setMemoryItem(new GCMemoryItem(HEAP, 70 * 1024 * 1024, 70 * 1024 * 1024, 300 * 1024 * 1024));
events[3].getPhases().get(1).setMemoryItem(new GCMemoryItem(HEAP, 70 * 1024 * 1024, 70 * 1024 * 1024, 300 * 1024 * 1024));
events[4].setEventType(G1_CONCURRENT_CYCLE);
events[4].setStartTime(24 * 1000);
events[4].setDuration(0.6 * 1000);
concurrentCyclePhases = new GCEventType[]{G1_REMARK, G1_PAUSE_CLEANUP, G1_CONCURRENT_CLEAR_CLAIMED_MARKS};
begins = new double[]{24.0, 24.1, 24.3};
for (int i = 0; i < concurrentCyclePhases.length; i++) {
GCEvent phase = new GCEvent();
phase.setGcid(5);
model.addPhase(events[4], phase);
phase.setEventType(concurrentCyclePhases[i]);
phase.setDuration(0.1 * (i + 1) * 1000);
phase.setStartTime(begins[i] * 1000);
}
events[4].getPhases().get(0).setMemoryItem(new GCMemoryItem(HEAP, 70 * 1024 * 1024, 70 * 1024 * 1024, 300 * 1024 * 1024));
events[4].getPhases().get(1).setMemoryItem(new GCMemoryItem(HEAP, 70 * 1024 * 1024, 70 * 1024 * 1024, 300 * 1024 * 1024));
events[5].setEventType(YOUNG_GC);
events[5].setStartTime(32.0 * 1000);
events[5].setDuration(0.3 * 1000);
events[5].setCause("G1 Evacuation Pause");
events[5].setMemoryItem(new GCMemoryItem(EDEN, 16 * 1024 * 1024, 0, 100 * 1024 * 1024));
events[5].setMemoryItem(new GCMemoryItem(SURVIVOR, 0, 4 * 1024 * 1024, 100 * 1024 * 1024));
events[5].setMemoryItem(new GCMemoryItem(HUMONGOUS, 50 * 1024 * 1024, 50 * 1024 * 1024, Constant.UNKNOWN_INT));
events[5].setMemoryItem(new GCMemoryItem(METASPACE, 15 * 1024 * 1024, 15 * 1024 * 1024, 40 * 1024 * 1024));
// expected result: events[5].setMemoryItem(new GCCollectionResultItem(OLD,10,12,100));
events[5].setMemoryItem(new GCMemoryItem(HEAP, 76 * 1024 * 1024, 66 * 1024 * 1024, 300 * 1024 * 1024));
Safepoint safepoint = new Safepoint();
safepoint.setStartTime(31.9 * 1000);
safepoint.setTimeToEnter(0.6 * 1000);
safepoint.setDuration(0.3 * 1000);
model.addSafepoint(safepoint);
}
@Test
public void testModelMisc() {
model.calculateDerivedInfo(new DefaultProgressListener());
// derived model info
Assert.assertEquals(model.getEndTime(), 32.3 * 1000, DELTA);
Assert.assertEquals(model.getGcCollectionEvents().size(), 8);
// single event info
Assert.assertEquals(model.getGcEvents().get(0).getAllocation(), 40 * 1024 * 1024);
Assert.assertEquals(model.getGcEvents().get(0).getPromotion(), 2 * 1024 * 1024);
Assert.assertEquals(model.getGcEvents().get(0).getReclamation(), 8 * 1024 * 1024);
Assert.assertEquals(model.getGcEvents().get(3).getPause(), 0.6 * 1000, DELTA);
Assert.assertEquals(model.getGcEvents().get(4).getPause(), 0.3 * 1000, DELTA);
Assert.assertEquals(model.getGcEvents().get(0).getMemoryItem(HEAP),
new GCMemoryItem(HEAP, 40 * 1024 * 1024, 32 * 1024 * 1024, 300 * 1024 * 1024));
Assert.assertEquals(model.getGcEvents().get(5).getMemoryItem(OLD),
new GCMemoryItem(OLD, 10 * 1024 * 1024, 12 * 1024 * 1024, 100 * 1024 * 1024));
Assert.assertEquals(model.getGcEvents().get(4).getInterval(), 6.8 * 1000, DELTA);
// object statistics
ObjectStatistics objectStatistics = model.getObjectStatistics(new TimeRange(500, 33000));
Assert.assertEquals(objectStatistics.getObjectCreationSpeed(), (40 + 18 + 22 + 40 + 6) * 1024 * 1024 / 31800.0, DELTA);
Assert.assertEquals(objectStatistics.getObjectPromotionSpeed(), (2 + 2) * 1024 * 1024 / 31800.0, DELTA);
Assert.assertEquals(objectStatistics.getObjectPromotionAvg(), 2 * 1024 * 1024);
Assert.assertEquals(objectStatistics.getObjectPromotionMax(), 2 * 1024 * 1024);
// pause statistics
PauseStatistics pauseStatistics = model.getPauseStatistics(new TimeRange(10000, 30000));
Assert.assertEquals(pauseStatistics.getThroughput(), 1 - (1000 + 100 + 200 + 200 + 400) / 20000.0, DELTA);
Assert.assertEquals(pauseStatistics.getPauseAvg(), (1000 + 100 + 200 + 200 + 400) / 5.0, DELTA);
Assert.assertEquals(pauseStatistics.getPauseMedian(), 200, DELTA);
Assert.assertEquals(pauseStatistics.getPauseP99(), 0.96 * 1000 + 0.04 * 400, DELTA);
Assert.assertEquals(pauseStatistics.getPauseP999(), 0.996 * 1000 + 0.004 * 400, DELTA);
Assert.assertEquals(pauseStatistics.getPauseMax(), 1000.0, DELTA);
// pause Distribution
Map<String, int[]> pauseDistribution = model.getPauseDistribution(new TimeRange(10000, 30000), new int[]{0, 300});
Assert.assertArrayEquals(pauseDistribution.get(FULL_GC.getName()), new int[]{0, 1});
Assert.assertArrayEquals(pauseDistribution.get(G1_REMARK.getName()), new int[]{2, 0});
Assert.assertArrayEquals(pauseDistribution.get(G1_PAUSE_CLEANUP.getName()), new int[]{1, 1});
// phase statistics
List<PhaseStatistics.ParentStatisticsInfo> parents = model.getPhaseStatistics(new TimeRange(0, 999999999)).getParents();
Assert.assertEquals(parents.size(), 3);
Assert.assertEquals(parents.get(0).getCauses().size(), 1);
Assert.assertEquals(parents.get(2).getCauses().size(), 2);
Assert.assertEquals(parents.get(0).getCauses().get(0), new PhaseStatistics.PhaseStatisticItem(
"G1 Evacuation Pause", 2, 30500, 30500, 400, 500, 800));
Assert.assertEquals(parents.get(1).getSelf(), new PhaseStatistics.PhaseStatisticItem(
G1_CONCURRENT_CYCLE.getName(), 2, 6800, 6800, 900, 1200, 1800));
Assert.assertEquals(parents.get(1).getPhases().size(), 3);
Assert.assertEquals(parents.get(1).getPhases().get(1), new PhaseStatistics.PhaseStatisticItem(
G1_REMARK.getName(), 2, 7800, 7800, 150, 200, 300));
Map<String, List<Object[]>> graphData = model.getTimeGraphData(new String[]{"youngCapacity", "heapUsed", "reclamation", "promotion", G1_REMARK.getName()});
Assert.assertEquals(graphData.size(), 5);
List<Object[]> youngCapacity = graphData.get("youngCapacity");
Assert.assertEquals(youngCapacity.size(), 4);
Assert.assertArrayEquals(youngCapacity.get(3), new Object[]{32300L, 200L * 1024 * 1024,});
List<Object[]> heapUse = graphData.get("heapUsed");
Assert.assertEquals(heapUse.size(), 16);
Assert.assertArrayEquals(heapUse.get(14), new Object[]{32000L, 76L * 1024 * 1024,});
Assert.assertArrayEquals(heapUse.get(15), new Object[]{32300L, 66L * 1024 * 1024,});
List<Object[]> reclamation = graphData.get("reclamation");
Assert.assertEquals(reclamation.size(), 8);
Assert.assertArrayEquals(reclamation.get(7), new Object[]{32000L, 10L * 1024 * 1024,});
List<Object[]> promotion = graphData.get("promotion");
Assert.assertEquals(promotion.size(), 2);
Assert.assertArrayEquals(promotion.get(1), new Object[]{32000L, 2L * 1024 * 1024,});
List<Object[]> remark = graphData.get(G1_REMARK.getName());
Assert.assertEquals(remark.size(), 2);
Assert.assertArrayEquals(remark.get(1), new Object[]{24000L, 100.0,});
}
@Test
public void testUseCPUTimeAsPause() throws Exception {
String log = "2022-05-23T11:29:31.538+0800: 224076.254: [GC pause (G1 Evacuation Pause) (young), 0.6017393 secs]\n" +
" [Parallel Time: 21.6 ms, GC Workers: 13]\n" +
" [GC Worker Start (ms): Min: 224076603.9, Avg: 224076604.1, Max: 224076604.3, Diff: 0.4]\n" +
" [Ext Root Scanning (ms): Min: 1.7, Avg: 2.2, Max: 3.5, Diff: 1.8, Sum: 29.2]\n" +
" [Update RS (ms): Min: 2.6, Avg: 3.9, Max: 4.2, Diff: 1.6, Sum: 50.7]\n" +
" [Processed Buffers: Min: 21, Avg: 36.2, Max: 50, Diff: 29, Sum: 470]\n" +
" [Scan RS (ms): Min: 0.1, Avg: 0.3, Max: 0.3, Diff: 0.3, Sum: 3.3]\n" +
" [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]\n" +
" [Object Copy (ms): Min: 14.0, Avg: 14.3, Max: 14.4, Diff: 0.4, Sum: 186.2]\n" +
" [Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]\n" +
" [Termination Attempts: Min: 2, Avg: 5.5, Max: 11, Diff: 9, Sum: 72]\n" +
" [GC Worker Other (ms): Min: 0.1, Avg: 0.3, Max: 0.5, Diff: 0.4, Sum: 3.6]\n" +
" [GC Worker Total (ms): Min: 20.7, Avg: 21.0, Max: 21.3, Diff: 0.7, Sum: 273.2]\n" +
" [GC Worker End (ms): Min: 224076625.0, Avg: 224076625.2, Max: 224076625.4, Diff: 0.4]\n" +
" [Code Root Fixup: 0.1 ms]\n" +
" [Code Root Purge: 0.0 ms]\n" +
" [Clear CT: 1.1 ms]\n" +
" [Other: 578.9 ms]\n" +
" [Choose CSet: 0.0 ms]\n" +
" [Ref Proc: 2.6 ms]\n" +
" [Ref Enq: 0.0 ms]\n" +
" [Redirty Cards: 0.6 ms]\n" +
" [Humongous Register: 0.1 ms]\n" +
" [Humongous Reclaim: 0.1 ms]\n" +
" [Free CSet: 2.1 ms]\n" +
" [Eden: 2924.0M(2924.0M)->0.0B(2924.0M) Survivors: 148.0M->148.0M Heap: 3924.7M(5120.0M)->1006.9M(5120.0M)]\n" +
"Heap after GC invocations=1602 (full 0):\n" +
" garbage-first heap total 5242880K, used 1031020K [0x0000000680000000, 0x0000000680205000, 0x00000007c0000000)\n" +
" region size 2048K, 74 young (151552K), 74 survivors (151552K)\n" +
" Metaspace used 120752K, capacity 128436K, committed 129536K, reserved 1161216K\n" +
" class space used 14475K, capacity 16875K, committed 17152K, reserved 1048576K\n" +
"}\n" +
" [Times: user=0.29 sys=0.00, real=0.71 secs] ";
PreUnifiedG1GCLogParser parser = (PreUnifiedG1GCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
G1GCModel model = (G1GCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
Assert.assertEquals(model.getGcEvents().get(0).getPause(), 710, DELTA);
}
@Test
public void testCauseInterval() throws Exception {
String log = "0.003: [GC (Allocation Failure) 0.003: [ParNew: 1826919K->78900K(1922432K), 0.0572643 secs] 3445819K->1697799K(4019584K), 0.0575802 secs] [Times: user=0.21 sys=0.00, real=0.05 secs]\n" +
"12.765: [Full GC (Last ditch collection) 12.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]\n" +
"80.765: [Full GC (System.gc()) 80.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]\n" +
"95.765: [Full GC (Allocation Failure) 95.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]\n" +
"103.765: [Full GC (Metadata GC Threshold) 103.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]\n" +
"120.765: [Full GC (Allocation Failure) 120.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]\n" +
"155.765: [Full GC (Allocation Failure) 155.765: [CMS: 92159K->92159K(92160K), 0.1150376 secs] 99203K->99169K(101376K), [Metaspace: 3805K->3805K(1056768K)], 0.1150614 secs] [Times: user=0.11 sys=0.00, real=0.12 secs]";
GCLogParser parser = new GCLogParserFactory().getParser(stringToBufferedReader(log));
GCModel model = parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertEquals(model.getGcEvents().get(3).getCauseInterval(), UNKNOWN_DOUBLE, DELTA);
Assert.assertEquals(model.getGcEvents().get(5).getCauseInterval(), 24884.9386, DELTA);
Assert.assertEquals(model.getGcEvents().get(6).getCauseInterval(), 34884.9386, DELTA);
List<PhaseStatistics.ParentStatisticsInfo> parents = model.getPhaseStatistics(new TimeRange(0, 99999999)).getParents();
for (PhaseStatistics.ParentStatisticsInfo parent : parents) {
if (parent.getSelf().getName().equals(FULL_GC.getName())) {
for (PhaseStatistics.PhaseStatisticItem cause : parent.getCauses()) {
if (cause.getName().equals(GCCause.ALLOCATION_FAILURE.getName())) {
Assert.assertEquals(cause.getCount(), 3);
Assert.assertEquals(cause.getIntervalMin(), 24884.9386, DELTA);
Assert.assertEquals(cause.getIntervalAvg(), (24884.9386 + 34884.9386) / 2, DELTA);
return;
}
}
}
}
Assert.fail("should find full gc with Allocation Failure");
}
}
| 6,717 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa/gclog/TestObjectStatistics.java | package org.eclipse.jifa.gclog;
import org.eclipse.jifa.common.listener.DefaultProgressListener;
import org.eclipse.jifa.gclog.model.CMSGCModel;
import org.eclipse.jifa.gclog.model.G1GCModel;
import org.eclipse.jifa.gclog.parser.GCLogParserFactory;
import org.eclipse.jifa.gclog.parser.UnifiedG1GCLogParser;
import org.eclipse.jifa.gclog.parser.PreUnifiedGenerationalGCLogParser;
import org.eclipse.jifa.gclog.vo.MemoryStatistics;
import org.eclipse.jifa.gclog.vo.TimeRange;
import org.junit.Assert;
import org.junit.Test;
import static org.eclipse.jifa.gclog.TestUtil.stringToBufferedReader;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
public class TestObjectStatistics {
public static final double DELTA = 1e-6;
@Test
public void testJDk8CMS() throws Exception {
String log = "OpenJDK 64-Bit Server VM (25.152-b187) for linux-amd64 JRE (1.8.0_152-b187), built on Dec 23 2017 19:26:28 by \"admin\" with gcc 4.4.7\n" +
"Memory: 4k page, physical 8388608k(7983060k free), swap 0k(0k free)\n" +
"CommandLine flags: -XX:+CMSClassUnloadingEnabled -XX:CMSInitiatingOccupancyFraction=80 -XX:CMSMaxAbortablePrecleanTime=5000 -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/admin/logs/java.hprof -XX:InitialHeapSize=4294967296 -XX:MaxDirectMemorySize=1073741824 -XX:MaxHeapSize=4294967296 -XX:MaxMetaspaceSize=536870912 -XX:MaxNewSize=2147483648 -XX:MetaspaceSize=536870912 -XX:NewSize=2147483648 -XX:OldPLABSize=16 -XX:ParallelGCThreads=4 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:SurvivorRatio=10 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseParNewGC\n" +
"63218.274: [GC (Allocation Failure) 63218.274: [ParNew: 1886196K->174720K(1922432K), 0.2894588 secs] 3212959K->1553242K(4019584K), 0.2897776 secs] [Times: user=0.84 sys=0.03, real=0.29 secs]\n" +
"63471.854: [GC (CMS Initial Mark) [1 CMS-initial-mark: 1735874K(2097152K)] 1925568K(4019584K), 0.0760575 secs] [Times: user=0.17 sys=0.00, real=0.08 secs]\n" +
"63471.930: [CMS-concurrent-mark-start]\n" +
"63472.403: [CMS-concurrent-mark: 0.472/0.473 secs] [Times: user=0.68 sys=0.04, real=0.47 secs]\n" +
"63472.403: [CMS-concurrent-preclean-start]\n" +
"63472.413: [CMS-concurrent-preclean: 0.010/0.010 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]\n" +
"63472.413: [CMS-concurrent-abortable-preclean-start]\n" +
" CMS: abort preclean due to time 63478.523: [CMS-concurrent-abortable-preclean: 6.102/6.109 secs] [Times: user=6.13 sys=0.09, real=6.11 secs]\n" +
"63478.524: [GC (CMS Final Remark) [YG occupancy: 388009 K (1922432 K)]63478.524: [Rescan (parallel) , 0.1034279 secs]\n" +
"63478.627: [weak refs processing, 0.0063173 secs]\n" +
"63478.634: [class unloading, 0.1256964 secs]\n" +
"63478.760: [scrub symbol table, 0.0364073 secs]\n" +
"63478.796: [scrub string table, 0.0056749 secs][1 CMS-remark: 1735874K(2097152K)] 2123883K(4019584K), 0.3066740 secs] [Times: user=0.54 sys=0.00, real=0.31 secs]\n" +
"63478.833: [CMS-concurrent-sweep-start]\n" +
"63479.175: [GC (Allocation Failure) 63529.175: [ParNew: 1919804K->174720K(1922432K), 0.5404068 secs] 2298321K->734054K(4019584K), 0.5407823 secs] [Times: user=1.66 sys=0.00, real=0.54 secs]\n" +
"63479.993: [CMS-concurrent-sweep: 1.160/1.161 secs] [Times: user=1.23 sys=0.03, real=1.16 secs]\n" +
"63479.993: [CMS-concurrent-reset-start]\n" +
"63480.008: [CMS-concurrent-reset: 0.015/0.015 secs] [Times: user=0.00 sys=0.01, real=0.02 secs]\n" +
"63529.175: [GC (Allocation Failure) 63529.175: [ParNew: 1919804K->174720K(1922432K), 0.5404068 secs] 2298321K->734054K(4019584K), 0.5407823 secs] [Times: user=1.66 sys=0.00, real=0.54 secs]\n" +
"63533.175: [Full GC (GCLocker Initiated GC) 63533.775: [CMS: 1572864K->1048576K(2097152K), 15.0887099 secs] 2298321K->1048576K(4019584K), [Metaspace: 864432K->244432K(1869824K)], 15.0888402 secs] [Times: user=15.06 sys=0.05, real=15.08 secs]\n" +
"63581.039: [GC (Allocation Failure) 63581.040: [ParNew: 1922432K->174720K(1922432K), 0.4617450 secs] 2481766K->896372K(4019584K), 0.4620492 secs] [Times: user=1.49 sys=0.00, real=0.46 secs]\n" +
"63600.175: [Full GC (GCLocker Initiated GC) 63600.775: [CMS: 1572984K->1048592K(2097152K), 12.0887099 secs] 2988617K->1048592K(4019584K), [Metaspace: 878932K->27432K(1869824K)], 15.0888402 secs] [Times: user=15.06 sys=0.05, real=12.08 secs]\n" +
"63713.814: [GC (Allocation Failure) 63713.814: [ParNew: 1922432K->174720K(1922432K), 0.4928452 secs] 3167180K->1615581K(4019584K), 0.4931707 secs] [Times: user=1.67 sys=0.00, real=0.50 secs]\n" +
"63811.838: [GC (CMS Initial Mark) [1 CMS-initial-mark: 1729404K(2097152K)] 1914444K(4019584K), 0.0531800 secs] [Times: user=0.15 sys=0.00, real=0.05 secs]\n" +
"63811.891: [CMS-concurrent-mark-start]\n" +
"63812.437: [CMS-concurrent-mark: 0.546/0.546 secs] [Times: user=0.67 sys=0.00, real=0.55 secs]\n" +
"63812.437: [CMS-concurrent-preclean-start]\n" +
"63812.446: [CMS-concurrent-preclean: 0.008/0.009 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]\n" +
"63812.446: [CMS-concurrent-abortable-preclean-start]\n" +
" CMS: abort preclean due to time 63817.771: [CMS-concurrent-abortable-preclean: 5.320/5.325 secs] [Times: user=5.41 sys=0.07, real=5.33 secs]\n" +
"63817.772: [GC (CMS Final Remark) [YG occupancy: 268095 K (1922432 K)]63817.772: [Rescan (parallel) , 0.0782293 secs]63817.850: [weak refs processing, 0.0003177 secs]63817.850: [class unloading, 0.1284138 secs]63817.979: [scrub symbol table, 0.0407089 secs]63818.020: [scrub string table, 0.0038912 secs][1 CMS-remark: 1729404K(2097152K)] 1997499K(4019584K), 0.2742426 secs] [Times: user=0.49 sys=0.01, real=0.28 secs]\n" +
"63818.047: [CMS-concurrent-sweep-start]\n" +
"63819.309: [CMS-concurrent-sweep: 1.261/1.262 secs] [Times: user=1.34 sys=0.02, real=1.26 secs]\n" +
"63819.309: [CMS-concurrent-reset-start]\n" +
"63819.314: [CMS-concurrent-reset: 0.005/0.005 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]\n" +
"63966.141: [GC (Allocation Failure) 63966.141: [ParNew: 1920339K->174720K(1922492K), 0.2086826 secs] 2338509K->621384K(4019584K), 0.2089897 secs] [Times: user=0.72 sys=0.00, real=0.21 secs]";
PreUnifiedGenerationalGCLogParser parser = (PreUnifiedGenerationalGCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
CMSGCModel model = (CMSGCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
Assert.assertNotNull(model);
MemoryStatistics memStats = model.getMemoryStatistics(new TimeRange(0, 9999999999.0));
Assert.assertEquals(memStats.getYoung(), new MemoryStatistics.MemoryStatisticsItem(
(1922432 * 7 + 1922492) * 1024L / 8, 1922432 * 1024L, UNKNOWN_INT, UNKNOWN_INT));
Assert.assertEquals(memStats.getOld(), new MemoryStatistics.MemoryStatisticsItem(
(2097152 * 7 + 4019584 - 1922492) * 1024L / 8, 1572984 * 1024L, (1048576 + 1048592) * 1024L / 2, (2338509 - 1920339 + 2298321 - 1919804) * 1024L / 2));
Assert.assertEquals(memStats.getHumongous(), new MemoryStatistics.MemoryStatisticsItem(UNKNOWN_INT, UNKNOWN_INT, UNKNOWN_INT, UNKNOWN_INT));
Assert.assertEquals(memStats.getHeap(), new MemoryStatistics.MemoryStatisticsItem(
4019584 * 1024L, 3212959 * 1024L, (1048576 + 1048592) * 1024L / 2, UNKNOWN_INT));
Assert.assertEquals(memStats.getMetaspace(), new MemoryStatistics.MemoryStatisticsItem(
536870912, 878932L * 1024L, (244432 + 27432) * 1024L / 2, UNKNOWN_INT));
}
@Test
public void testJDK11G1() throws Exception {
String log = "[0.029s][info][gc,heap] Heap region size: 1M\n" +
"[0.033s][info][gc ] Using G1\n" +
"[0.033s][info][gc,heap,coops] Heap address: 0x0000000740000000, size: 3072 MB, Compressed Oops mode: Zero based, Oop shift amount: 3\n" +
"[28.224s][info][gc,start ] GC(0) Pause Young (Concurrent Start) (G1 Humongous Allocation)\n" +
"[28.224s][info][gc,task ] GC(0) Using 8 workers of 8 for evacuation\n" +
"[28.242s][info][gc,phases ] GC(0) Pre Evacuate Collection Set: 0.3ms\n" +
"[28.242s][info][gc,phases ] GC(0) Evacuate Collection Set: 15.9ms\n" +
"[28.242s][info][gc,phases ] GC(0) Post Evacuate Collection Set: 1.8ms\n" +
"[28.242s][info][gc,phases ] GC(0) Other: 0.3ms\n" +
"[28.242s][info][gc,heap ] GC(0) Eden regions: 148->0(172)\n" +
"[28.242s][info][gc,heap ] GC(0) Survivor regions: 20->10(23)\n" +
"[28.242s][info][gc,heap ] GC(0) Old regions: 214->220\n" +
"[28.242s][info][gc,heap ] GC(0) Humongous regions: 13->13\n" +
"[28.242s][info][gc,metaspace ] GC(0) Metaspace: 222590K->222590K(1251328K)\n" +
"[28.242s][info][gc ] GC(0) Pause Young (Concurrent Start) (G1 Humongous Allocation) 393M->242M(505M) 18.390ms\n" +
"[28.242s][info][gc,cpu ] GC(0) User=0.10s Sys=0.00s Real=0.02s\n" +
"[28.242s][info][gc ] GC(1) Concurrent Cycle\n" +
"[28.242s][info][gc,marking ] GC(1) Concurrent Clear Claimed Marks\n" +
"[28.242s][info][gc,marking ] GC(1) Concurrent Clear Claimed Marks 0.301ms\n" +
"[28.243s][info][gc,marking ] GC(1) Concurrent Scan Root Regions\n" +
"[28.250s][info][gc,marking ] GC(1) Concurrent Scan Root Regions 7.413ms\n" +
"[28.250s][info][gc,marking ] GC(1) Concurrent Mark (28.250s)\n" +
"[28.250s][info][gc,marking ] GC(1) Concurrent Mark From Roots\n" +
"[28.250s][info][gc,task ] GC(1) Using 2 workers of 2 for marking\n" +
"[28.794s][info][gc,marking ] GC(1) Concurrent Mark From Roots 544.204ms\n" +
"[28.794s][info][gc,marking ] GC(1) Concurrent Preclean\n" +
"[28.795s][info][gc,marking ] GC(1) Concurrent Preclean 0.996ms\n" +
"[28.795s][info][gc,marking ] GC(1) Concurrent Mark (28.250s, 28.795s) 545.303ms\n" +
"[28.795s][info][gc,start ] GC(1) Pause Remark\n" +
"[28.818s][info][gc,stringtable] GC(1) Cleaned string and symbol table, strings: 93320 processed, 4 removed, symbols: 553250 processed, 79 removed\n" +
"[28.818s][info][gc ] GC(1) Pause Remark 341M->334M(505M) 22.698ms\n" +
"[28.818s][info][gc,cpu ] GC(1) User=0.11s Sys=0.01s Real=0.03s\n" +
"[28.818s][info][gc,marking ] GC(1) Concurrent Rebuild Remembered Sets\n" +
"[29.125s][info][gc,marking ] GC(1) Concurrent Rebuild Remembered Sets 306.244ms\n" +
"[29.126s][info][gc,start ] GC(1) Pause Cleanup\n" +
"[29.126s][info][gc ] GC(1) Pause Cleanup 395M->395M(505M) 0.225ms\n" +
"[29.126s][info][gc,cpu ] GC(1) User=0.00s Sys=0.00s Real=0.00s\n" +
"[29.126s][info][gc,marking ] GC(1) Concurrent Cleanup for Next Mark\n" +
"[29.130s][info][gc,marking ] GC(1) Concurrent Cleanup for Next Mark 3.930ms\n" +
"[29.130s][info][gc ] GC(1) Concurrent Cycle 888.287ms\n" +
"[29.228s][info][gc,start ] GC(2) Pause Young (Prepare Mixed) (G1 Evacuation Pause)\n" +
"[29.228s][info][gc,task ] GC(2) Using 8 workers of 8 for evacuation\n" +
"[29.240s][info][gc,phases ] GC(2) Pre Evacuate Collection Set: 0.0ms\n" +
"[29.240s][info][gc,phases ] GC(2) Evacuate Collection Set: 10.4ms\n" +
"[29.240s][info][gc,phases ] GC(2) Post Evacuate Collection Set: 1.3ms\n" +
"[29.240s][info][gc,phases ] GC(2) Other: 0.2ms\n" +
"[29.240s][info][gc,heap ] GC(2) Eden regions: 172->0(9)\n" +
"[29.240s][info][gc,heap ] GC(2) Survivor regions: 10->16(23)\n" +
"[29.240s][info][gc,heap ] GC(2) Old regions: 217->217\n" +
"[29.240s][info][gc,heap ] GC(2) Humongous regions: 29->11\n" +
"[29.240s][info][gc,metaspace ] GC(2) Metaspace: 224850K->224850K(1253376K)\n" +
"[29.240s][info][gc ] GC(2) Pause Young (Prepare Mixed) (G1 Evacuation Pause) 427M->243M(505M) 12.048ms\n" +
"[29.240s][info][gc,cpu ] GC(2) User=0.08s Sys=0.00s Real=0.01s\n" +
"[29.268s][info][gc,start ] GC(3) Pause Young (Mixed) (G1 Evacuation Pause)\n" +
"[29.268s][info][gc,task ] GC(3) Using 8 workers of 8 for evacuation\n" +
"[29.280s][info][gc,phases ] GC(3) Pre Evacuate Collection Set: 0.0ms\n" +
"[29.280s][info][gc,phases ] GC(3) Evacuate Collection Set: 10.9ms\n" +
"[29.280s][info][gc,phases ] GC(3) Post Evacuate Collection Set: 0.4ms\n" +
"[29.280s][info][gc,phases ] GC(3) Other: 0.2ms\n" +
"[29.280s][info][gc,heap ] GC(3) Eden regions: 9->0(176)\n" +
"[29.280s][info][gc,heap ] GC(3) Survivor regions: 16->3(4)\n" +
"[29.280s][info][gc,heap ] GC(3) Old regions: 217->223\n" +
"[29.280s][info][gc,heap ] GC(3) Humongous regions: 11->11\n" +
"[29.280s][info][gc,metaspace ] GC(3) Metaspace: 224854K->224854K(1253376K)\n" +
"[29.280s][info][gc ] GC(3) Pause Young (Mixed) (G1 Evacuation Pause) 252M->236M(505M) 11.771ms\n" +
"[29.280s][info][gc,cpu ] GC(3) User=0.09s Sys=0.00s Real=0.01s\n" +
"[29.356s][info][gc,start ] GC(4) Pause Young (Concurrent Start) (G1 Humongous Allocation)\n" +
"[29.356s][info][gc,task ] GC(4) Using 8 workers of 8 for evacuation\n" +
"[29.365s][info][gc,phases ] GC(4) Pre Evacuate Collection Set: 0.3ms\n" +
"[29.365s][info][gc,phases ] GC(4) Evacuate Collection Set: 6.9ms\n" +
"[29.365s][info][gc,phases ] GC(4) Post Evacuate Collection Set: 1.2ms\n" +
"[29.365s][info][gc,phases ] GC(4) Other: 0.2ms\n" +
"[29.365s][info][gc,heap ] GC(4) Eden regions: 23->0(137)\n" +
"[29.365s][info][gc,heap ] GC(4) Survivor regions: 3->5(23)\n" +
"[29.365s][info][gc,heap ] GC(4) Old regions: 223->223\n" +
"[29.365s][info][gc,heap ] GC(4) Humongous regions: 11->11\n" +
"[29.365s][info][gc,metaspace ] GC(4) Metaspace: 225002K->225002K(1253376K)\n" +
"[29.365s][info][gc ] GC(4) Pause Young (Concurrent Start) (G1 Humongous Allocation) 258M->237M(505M) 8.709ms\n" +
"[29.365s][info][gc,cpu ] GC(4) User=0.05s Sys=0.00s Real=0.00s";
UnifiedG1GCLogParser parser = (UnifiedG1GCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
G1GCModel model = (G1GCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
MemoryStatistics memStats = model.getMemoryStatistics(new TimeRange(0, 9999999999.0));
Assert.assertEquals(memStats.getHumongous(), new MemoryStatistics.MemoryStatisticsItem(
UNKNOWN_INT, 29 * 1024 * 1024, UNKNOWN_INT, 29 * 1024 * 1024));
Assert.assertEquals(memStats.getOld(), new MemoryStatistics.MemoryStatisticsItem(
(505 * 4 - 195 - 32 - 180 - 160) * 1024 * 1024 / 4, 223 * 1024 * 1024, UNKNOWN_INT, 223 * 1024 * 1024));
Assert.assertEquals(memStats.getMetaspace(), new MemoryStatistics.MemoryStatisticsItem(
UNKNOWN_INT, 225002 * 1024, UNKNOWN_INT, 224850 * 1024));
}
@Test
public void testJDK11G1NoMixedGC() throws Exception {
String log = "[0.029s][info][gc,heap] Heap region size: 1M\n" +
"[0.033s][info][gc ] Using G1\n" +
"[0.033s][info][gc,heap,coops] Heap address: 0x0000000740000000, size: 3072 MB, Compressed Oops mode: Zero based, Oop shift amount: 3\n" +
"[28.224s][info][gc,start ] GC(0) Pause Young (Concurrent Start) (G1 Humongous Allocation)\n" +
"[28.224s][info][gc,task ] GC(0) Using 8 workers of 8 for evacuation\n" +
"[28.242s][info][gc,phases ] GC(0) Pre Evacuate Collection Set: 0.3ms\n" +
"[28.242s][info][gc,phases ] GC(0) Evacuate Collection Set: 15.9ms\n" +
"[28.242s][info][gc,phases ] GC(0) Post Evacuate Collection Set: 1.8ms\n" +
"[28.242s][info][gc,phases ] GC(0) Other: 0.3ms\n" +
"[28.242s][info][gc,heap ] GC(0) Eden regions: 148->0(172)\n" +
"[28.242s][info][gc,heap ] GC(0) Survivor regions: 20->10(23)\n" +
"[28.242s][info][gc,heap ] GC(0) Old regions: 214->220\n" +
"[28.242s][info][gc,heap ] GC(0) Humongous regions: 13->13\n" +
"[28.242s][info][gc,metaspace ] GC(0) Metaspace: 222590K->222590K(1251328K)\n" +
"[28.242s][info][gc ] GC(0) Pause Young (Concurrent Start) (G1 Humongous Allocation) 393M->242M(505M) 18.390ms\n" +
"[28.242s][info][gc,cpu ] GC(0) User=0.10s Sys=0.00s Real=0.02s\n" +
"[28.242s][info][gc ] GC(1) Concurrent Cycle\n" +
"[28.242s][info][gc,marking ] GC(1) Concurrent Clear Claimed Marks\n" +
"[28.242s][info][gc,marking ] GC(1) Concurrent Clear Claimed Marks 0.301ms\n" +
"[28.243s][info][gc,marking ] GC(1) Concurrent Scan Root Regions\n" +
"[28.250s][info][gc,marking ] GC(1) Concurrent Scan Root Regions 7.413ms\n" +
"[28.250s][info][gc,marking ] GC(1) Concurrent Mark (28.250s)\n" +
"[28.250s][info][gc,marking ] GC(1) Concurrent Mark From Roots\n" +
"[28.250s][info][gc,task ] GC(1) Using 2 workers of 2 for marking\n" +
"[28.794s][info][gc,marking ] GC(1) Concurrent Mark From Roots 544.204ms\n" +
"[28.794s][info][gc,marking ] GC(1) Concurrent Preclean\n" +
"[28.795s][info][gc,marking ] GC(1) Concurrent Preclean 0.996ms\n" +
"[28.795s][info][gc,marking ] GC(1) Concurrent Mark (28.250s, 28.795s) 545.303ms\n" +
"[28.795s][info][gc,start ] GC(1) Pause Remark\n" +
"[28.818s][info][gc,stringtable] GC(1) Cleaned string and symbol table, strings: 93320 processed, 4 removed, symbols: 553250 processed, 79 removed\n" +
"[28.818s][info][gc ] GC(1) Pause Remark 341M->334M(505M) 22.698ms\n" +
"[28.818s][info][gc,cpu ] GC(1) User=0.11s Sys=0.01s Real=0.03s\n" +
"[28.818s][info][gc,marking ] GC(1) Concurrent Rebuild Remembered Sets\n" +
"[29.125s][info][gc,marking ] GC(1) Concurrent Rebuild Remembered Sets 306.244ms\n" +
"[29.126s][info][gc,start ] GC(1) Pause Cleanup\n" +
"[29.126s][info][gc ] GC(1) Pause Cleanup 395M->395M(505M) 0.225ms\n" +
"[29.126s][info][gc,cpu ] GC(1) User=0.00s Sys=0.00s Real=0.00s\n" +
"[29.126s][info][gc,marking ] GC(1) Concurrent Cleanup for Next Mark\n" +
"[29.130s][info][gc,marking ] GC(1) Concurrent Cleanup for Next Mark 3.930ms\n" +
"[29.130s][info][gc ] GC(1) Concurrent Cycle 888.287ms\n" +
"[29.228s][info][gc,start ] GC(2) Pause Young (Prepare Mixed) (G1 Evacuation Pause)\n" +
"[29.228s][info][gc,task ] GC(2) Using 8 workers of 8 for evacuation\n" +
"[29.240s][info][gc,phases ] GC(2) Pre Evacuate Collection Set: 0.0ms\n" +
"[29.240s][info][gc,phases ] GC(2) Evacuate Collection Set: 10.4ms\n" +
"[29.240s][info][gc,phases ] GC(2) Post Evacuate Collection Set: 1.3ms\n" +
"[29.240s][info][gc,phases ] GC(2) Other: 0.2ms\n" +
"[29.240s][info][gc,heap ] GC(2) Eden regions: 172->0(9)\n" +
"[29.240s][info][gc,heap ] GC(2) Survivor regions: 10->16(23)\n" +
"[29.240s][info][gc,heap ] GC(2) Old regions: 218->217\n" +
"[29.240s][info][gc,heap ] GC(2) Humongous regions: 29->11\n" +
"[29.240s][info][gc,metaspace ] GC(2) Metaspace: 224850K->224850K(1253376K)\n" +
"[29.240s][info][gc ] GC(2) Pause Young (Prepare Mixed) (G1 Evacuation Pause) 427M->243M(505M) 12.048ms\n" +
"[29.240s][info][gc,cpu ] GC(2) User=0.08s Sys=0.00s Real=0.01s\n" +
"[29.268s][info][gc,start ] GC(3) Pause Young (Normal) (G1 Evacuation Pause)\n" +
"[29.268s][info][gc,task ] GC(3) Using 8 workers of 8 for evacuation\n" +
"[29.280s][info][gc,phases ] GC(3) Pre Evacuate Collection Set: 0.0ms\n" +
"[29.280s][info][gc,phases ] GC(3) Evacuate Collection Set: 10.9ms\n" +
"[29.280s][info][gc,phases ] GC(3) Post Evacuate Collection Set: 0.4ms\n" +
"[29.280s][info][gc,phases ] GC(3) Other: 0.2ms\n" +
"[29.280s][info][gc,heap ] GC(3) Eden regions: 9->0(176)\n" +
"[29.280s][info][gc,heap ] GC(3) Survivor regions: 16->3(4)\n" +
"[29.280s][info][gc,heap ] GC(3) Old regions: 217->222\n" +
"[29.280s][info][gc,heap ] GC(3) Humongous regions: 12->11\n" +
"[29.280s][info][gc,metaspace ] GC(3) Metaspace: 224854K->224855K(1253376K)\n" +
"[29.280s][info][gc ] GC(3) Pause Young (Normal) (G1 Evacuation Pause) 252M->236M(505M) 11.771ms\n" +
"[29.280s][info][gc,cpu ] GC(3) User=0.09s Sys=0.00s Real=0.01s\n" +
"[29.356s][info][gc,start ] GC(4) Pause Young (Concurrent Start) (G1 Humongous Allocation)\n" +
"[29.356s][info][gc,task ] GC(4) Using 8 workers of 8 for evacuation\n" +
"[29.365s][info][gc,phases ] GC(4) Pre Evacuate Collection Set: 0.3ms\n" +
"[29.365s][info][gc,phases ] GC(4) Evacuate Collection Set: 6.9ms\n" +
"[29.365s][info][gc,phases ] GC(4) Post Evacuate Collection Set: 1.2ms\n" +
"[29.365s][info][gc,phases ] GC(4) Other: 0.2ms\n" +
"[29.365s][info][gc,heap ] GC(4) Eden regions: 23->0(137)\n" +
"[29.365s][info][gc,heap ] GC(4) Survivor regions: 3->5(23)\n" +
"[29.365s][info][gc,heap ] GC(4) Old regions: 223->223\n" +
"[29.365s][info][gc,heap ] GC(4) Humongous regions: 11->11\n" +
"[29.365s][info][gc,metaspace ] GC(4) Metaspace: 225002K->225002K(1253376K)\n" +
"[29.365s][info][gc ] GC(4) Pause Young (Concurrent Start) (G1 Humongous Allocation) 258M->237M(505M) 8.709ms\n" +
"[29.365s][info][gc,cpu ] GC(4) User=0.05s Sys=0.00s Real=0.00s";
UnifiedG1GCLogParser parser = (UnifiedG1GCLogParser)
(new GCLogParserFactory().getParser(stringToBufferedReader(log)));
G1GCModel model = (G1GCModel) parser.parse(stringToBufferedReader(log));
model.calculateDerivedInfo(new DefaultProgressListener());
MemoryStatistics memStats = model.getMemoryStatistics(new TimeRange(0, 9999999999.0));
Assert.assertEquals(memStats.getHumongous(), new MemoryStatistics.MemoryStatisticsItem(
UNKNOWN_INT, 29 * 1024 * 1024, UNKNOWN_INT, 29 * 1024 * 1024));
Assert.assertEquals(memStats.getOld(), new MemoryStatistics.MemoryStatisticsItem(
(505 * 4 - 195 - 32 - 180 - 160) * 1024 * 1024 / 4, 223 * 1024 * 1024, UNKNOWN_INT, 217 * 1024 * 1024));
Assert.assertEquals(memStats.getMetaspace(), new MemoryStatistics.MemoryStatisticsItem(
UNKNOWN_INT, 225002 * 1024, UNKNOWN_INT, 224850 * 1024));
}
}
| 6,718 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa/gclog/TestVmOptions.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog;
import org.eclipse.jifa.gclog.model.modeInfo.VmOptions;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
public class TestVmOptions {
@Test
public void testVmOptions() {
String optionString =
"-server " +
"-XX:+UseG1GC " +
"-XX:-DisableExplicitGC " +
"-verbose:gc " +
"-Xloggc:gc.log " +
"-XX:+PrintGCDetails " +
"-XX:+PrintGCDateStamps " +
"-XX:+HeapDumpOnOutOfMemoryError " +
"-XX:HeapDumpPath=/home/admin/logs " +
"-XX:ErrorFile=/home/admin/logs/hs_err_pid%p.log " +
"-Xms4200m " +
"-Xmx4200m " +
"-XX:ParallelGCThreads=8 " +
"-XX:MaxNewSize=1500m " +
"-XX:InitiatingHeapOccupancyPercent=50 " +
"-XX:G1HeapRegionSize=8m " +
"-Xss512k " +
"-XX:MetaspaceSize=10240 " +
"-XX:MaxMetaspaceSize=512m\n";
VmOptions options = new VmOptions(optionString);
Assert.assertEquals(options.getOriginalOptionString(), optionString);
Assert.assertNull(options.getOptionValue("Xmn"));
Assert.assertEquals(4200L * 1024 * 1024 * 1024, (long) options.getOptionValue("Xmx"));
Assert.assertTrue(options.getOptionValue("server"));
Assert.assertFalse(options.getOptionValue("DisableExplicitGC"));
Assert.assertEquals(50L, (long) options.getOptionValue("InitiatingHeapOccupancyPercent"));
Assert.assertEquals(10240L, (long) options.getOptionValue("MetaspaceSize"));
Assert.assertEquals("/home/admin/logs/hs_err_pid%p.log", options.getOptionValue("ErrorFile"));
Assert.assertEquals("gc", options.getOptionValue("verbose"));
Assert.assertEquals("gc.log", options.getOptionValue("Xloggc"));
VmOptions.VmOptionResult result = options.getVmOptionResult();
Assert.assertTrue(result.getOther().contains(new VmOptions.VmOptionVo("-XX:ErrorFile=/home/admin/logs/hs_err_pid%p.log")));
Map<String, Integer> optionIndex = new HashMap<>();
for (int i = 0; i < result.getGcRelated().size(); i++) {
optionIndex.put(result.getGcRelated().get(i).getText(), i);
}
Assert.assertTrue(optionIndex.get("-XX:+UseG1GC") < optionIndex.get("-Xms4200m"));
Assert.assertTrue(optionIndex.get("-Xms4200m") < optionIndex.get("-XX:ParallelGCThreads=8"));
Assert.assertTrue(optionIndex.get("-XX:ParallelGCThreads=8") < optionIndex.get("-XX:InitiatingHeapOccupancyPercent=50"));
Assert.assertTrue(optionIndex.get("-XX:InitiatingHeapOccupancyPercent=50") < optionIndex.get("-XX:-DisableExplicitGC"));
Assert.assertTrue(optionIndex.get("-XX:-DisableExplicitGC") < optionIndex.get("-XX:+PrintGCDetails"));
}
}
| 6,719 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa/gclog/TestGCLogUtil.java | package org.eclipse.jifa.gclog;
import org.eclipse.jifa.gclog.util.DoubleData;
import org.junit.Assert;
import org.junit.Test;
import static org.eclipse.jifa.gclog.util.Constant.EPS;
public class TestGCLogUtil {
@Test
public void testDoubleData() {
DoubleData doubleData = new DoubleData(true);
doubleData.add(1);
doubleData.add(2);
doubleData.add(3);
doubleData.add(4);
Assert.assertEquals(doubleData.getPercentile(0.99), 0.03 * 3 + 0.97 * 4, EPS);
Assert.assertEquals(doubleData.getPercentile(0.75), 0.75 * 3 + 0.25 * 4, EPS);
doubleData.add(0);
Assert.assertEquals(doubleData.getMedian(), 2, EPS);
Assert.assertEquals(doubleData.average(), 2, EPS);
Assert.assertEquals(doubleData.getMax(), 4, EPS);
Assert.assertEquals(doubleData.getMin(), 0, EPS);
Assert.assertEquals(doubleData.getN(), 5, EPS);
}
}
| 6,720 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/test/java/org/eclipse/jifa/gclog/TestUtil.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog;
import org.eclipse.jifa.gclog.diagnoser.AnalysisConfig;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.vo.TimeRange;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
public class TestUtil {
public static BufferedReader stringToBufferedReader(String source) {
InputStream inputStream = new ByteArrayInputStream(source.getBytes());
return new BufferedReader(new InputStreamReader(inputStream));
}
}
| 6,721 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/vo/PhaseStatistics.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PhaseStatistics {
private List<ParentStatisticsInfo> parents;
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class ParentStatisticsInfo {
private PhaseStatisticItem self;
private List<PhaseStatisticItem> phases;
private List<PhaseStatisticItem> causes;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class PhaseStatisticItem{
private String name;
private int count;
private double intervalAvg;
private double intervalMin;
private double durationAvg;
private double durationMax;
private double durationTotal;
}
}
| 6,722 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/vo/TimeRange.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class TimeRange {
//unit is ms
private double start = UNKNOWN_DOUBLE;
private double end = UNKNOWN_DOUBLE;
public boolean isValid() {
return start >= 0 && end >= 0 && start < end;
}
public double length() {
if (isValid()) {
return end - start;
} else {
return UNKNOWN_DOUBLE;
}
}
@Override
public String toString() {
return start + " ~ " + end;
}
}
| 6,723 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/vo/MemoryStatistics.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MemoryStatistics {
private MemoryStatisticsItem young;
private MemoryStatisticsItem old;
private MemoryStatisticsItem humongous;
private MemoryStatisticsItem heap;
private MemoryStatisticsItem metaspace;
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class MemoryStatisticsItem {
private long capacityAvg;
private long usedMax;
private long usedAvgAfterFullGC;
private long usedAvgAfterOldGC;
}
}
| 6,724 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/vo/PauseStatistics.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PauseStatistics {
double throughput;
double pauseAvg;
double pauseMedian;
double pauseP99;
double pauseP999;
double pauseMax;
}
| 6,725 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/vo/ObjectStatistics.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ObjectStatistics {
private double objectCreationSpeed = UNKNOWN_DOUBLE; // B/ms
private double objectPromotionSpeed = UNKNOWN_DOUBLE; // B/ms
private long objectPromotionAvg = UNKNOWN_INT; // B
private long objectPromotionMax = UNKNOWN_INT; // B
}
| 6,726 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/vo/GCEventVO.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.vo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
* This class is used for interaction with front end.
*/
public class GCEventVO {
private Map<String, Object> info = new HashMap<>();
private List<GCEventVO> phases = new ArrayList<>();
// todo: add diagnostic info
public void saveInfo(String type, Object value) {
info.put(type, value);
}
public void addPhase(GCEventVO phase) {
phases.add(phase);
}
private String infoToString() {
return info.toString();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(infoToString());
if (phases != null) {
for (GCEventVO phase : phases) {
sb.append("\n ").append(phase.infoToString());
}
}
return sb.toString();
}
}
| 6,727 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/util/CountingMap.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.util;
import java.util.HashMap;
import java.util.Map;
public class CountingMap<T> {
private Map<T, Integer> map = new HashMap<>();
public void put(T key) {
put(key, 1);
}
public void put(T key, int n) {
map.put(key, map.getOrDefault(key, 0) + n);
}
public boolean containKey(T key) {
return map.containsKey(key);
}
public int get(T key) {
return map.getOrDefault(key, 0);
}
}
| 6,728 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/util/DoubleData.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
public class DoubleData {
private int n = 0;
private double sum = 0;
private double min = Double.MAX_VALUE;
// min value of double is not Double.MIN_VALUE
private double max = -Double.MAX_VALUE;
private List<Double> originalData;
private boolean dataSorted;
public DoubleData(boolean recordOriginalData) {
// recording all data is expensive, only do it if necessary
if (recordOriginalData) {
originalData = new ArrayList<>();
}
}
public DoubleData() {
this(false);
}
public double getMedian() {
return getPercentile(0.5);
}
public double getPercentile(double percentile) {
// should not call this method if originalData is null
if (originalData.size() == 0) {
return UNKNOWN_DOUBLE;
}
if (!dataSorted) {
Collections.sort(originalData);
dataSorted = true;
}
double p = (n - 1) * percentile;
int i = (int) Math.floor(p);
double weight = p - i;
if (weight == 0) {
return originalData.get(i);
} else {
return weight * originalData.get(i + 1) + (1 - weight) * originalData.get(i);
}
}
public void add(double x) {
if (x == UNKNOWN_DOUBLE) {
return;
}
if (originalData != null) {
originalData.add(x);
dataSorted = false;
}
sum += x;
n++;
min = Math.min(min, x);
max = Math.max(max, x);
}
public int getN() {
return n;
}
public double getSum() {
if (n == 0) {
return UNKNOWN_DOUBLE;
}
return sum;
}
public double getMin() {
if (n == 0) {
return UNKNOWN_DOUBLE;
}
return min;
}
public double getMax() {
if (n == 0) {
return UNKNOWN_DOUBLE;
}
return max;
}
public double average() {
if (n == 0) {
return UNKNOWN_DOUBLE;
}
return sum / n;
}
}
| 6,729 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/util/I18nStringView.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.util;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class I18nStringView {
private String name;// should be i18n name in frontend
private Map<String, Object> params;
public I18nStringView(String name) {
this.name = name;
}
public I18nStringView(String name, Object... params) {
this.name = name;
if (params.length % 2 != 0) {
throw new RuntimeException("params number should be multiple of 2");
}
if (params.length == 0) {
return;
}
this.params = new HashMap<>();
for (int i = 0; i < params.length; i += 2) {
this.params.put(params[i].toString(), params[i + 1]);
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
I18nStringView that = (I18nStringView) o;
return Objects.equals(name, that.name) && Objects.equals(params, that.params);
}
@Override
public int hashCode() {
return Objects.hash(name, params);
}
}
| 6,730 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/util/Constant.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.util;
public interface Constant {
double UNKNOWN_DOUBLE = -1d;
int UNKNOWN_INT = -1;
long UNKNOWN_LONG = -1L;
String NA = "N/A";
double MS2S = 1e3;
double KB2MB = 1 << 10;
double EPS = 1e-6;
}
| 6,731 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/util/Key2ValueListMap.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Key2ValueListMap<K, V> {
private Map<K, List<V>> map;
public Key2ValueListMap(Map<K, List<V>> map) {
this.map = map;
}
public Key2ValueListMap() {
map = new HashMap<>();
}
public void put(K key, V value) {
List<V> list = map.getOrDefault(key, null);
if (list == null) {
list = new ArrayList<>();
map.put(key, list);
}
list.add(value);
}
public List<V> get(K key) {
return map.getOrDefault(key, null);
}
public Map<K, List<V>> getInnerMap() {
return map;
}
}
| 6,732 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/util/LongData.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.util;
import java.math.BigInteger;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
public class LongData {
private int n;
private BigInteger sum = BigInteger.ZERO;
private long min = Integer.MAX_VALUE;
private long max = Integer.MIN_VALUE;
public void add(long x) {
if (x == UNKNOWN_INT) {
return;
}
sum = sum.add(BigInteger.valueOf(x));
n++;
min = Math.min(min, x);
max = Math.max(max, x);
}
public int getN() {
return n;
}
public long getSum() {
if (n == 0) {
return UNKNOWN_INT;
}
return sum.longValue();
}
public long getMin() {
if (n == 0) {
return UNKNOWN_INT;
}
return min;
}
public long getMax() {
if (n == 0) {
return UNKNOWN_INT;
}
return max;
}
public double average() {
if (n == 0) {
return UNKNOWN_DOUBLE;
}
return sum.divide(BigInteger.valueOf(n)).doubleValue();
}
}
| 6,733 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/util/GCLogUtil.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.util;
import org.eclipse.jifa.gclog.event.evnetInfo.CpuTime;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
import static org.eclipse.jifa.gclog.util.Constant.MS2S;
public class GCLogUtil {
private GCLogUtil() {
}
private static final long BYTE_UNIT_GAP = 1024;
/**
* parse a string that represents a memory size and convert into size in B
* e.g. "10m" -> 10485760, "111 KB" -> 113664
* do not check format, do not consider b(bit)
*/
public static long toByte(String sizeString, long divideIfNoUnit) {
sizeString = sizeString.toLowerCase();
int mid;
for (mid = 0; mid < sizeString.length(); mid++) {
char c = sizeString.charAt(mid);
if (!Character.isDigit(c) && c != '.') {
break;
}
}
double size = Double.parseDouble(sizeString.substring(0, mid));
String unit = sizeString.substring(mid).trim();
switch (unit) {
case "b":
return (long) size;
case "k":
case "kb":
return (long) (size * BYTE_UNIT_GAP);
case "m":
case "mb":
return (long) (size * BYTE_UNIT_GAP * BYTE_UNIT_GAP);
case "g":
case "gb":
return (long) (size * BYTE_UNIT_GAP * BYTE_UNIT_GAP * BYTE_UNIT_GAP);
case "t":
case "tb":
return (long) (size * (BYTE_UNIT_GAP * BYTE_UNIT_GAP * BYTE_UNIT_GAP * BYTE_UNIT_GAP));
default:
return (long) (size / divideIfNoUnit);
}
}
public static long toByte(String sizeString) {
return toByte(sizeString, BYTE_UNIT_GAP);
}
/**
* find the last time and parse it into time in ms
* e.g. "123ms" -> 123, "12s" -> 12000
* do not check format
*/
public static double toMillisecond(String timeString) {
int mid;
for (mid = 0; mid < timeString.length(); mid++) {
char c = timeString.charAt(mid);
if (!Character.isDigit(c) && c != '.') {
break;
}
}
double number = Double.parseDouble(timeString.substring(0, mid));
double unit;
switch (timeString.substring(mid)) {
case "ns":
unit = 1 / MS2S / MS2S;
break;
case "ms":
unit = 1;
break;
default: // default unit is s
unit = MS2S;
}
return number * unit;
}
/**
* e.g. "user=0.15s sys=0.01s real=0.02s","user=0.04 sys=0.00, real=0.01 secs"
*/
public static CpuTime parseCPUTime(String s) {
CpuTime cpuTime = null;
int start = 0;
for (int i = 0; /* we will return */ ; i++) {
start = s.indexOf("=", start);
if (start < 0) {
return null;
}
start++;
int end = start;
while (end < s.length()) {
char c = s.charAt(end);
if (c == ' ' || c == 's' || c == ',') {
break;
}
end++;
}
double time = Double.parseDouble(s.substring(start, end)) * MS2S;
if (i == 0) {
cpuTime = new CpuTime();
cpuTime.setUser(time);
} else if (i == 1) {
cpuTime.setSys(time);
} else if (i == 2) {
cpuTime.setReal(time);
return cpuTime;
}
start = end;
}
}
/**
* e.g. "Concurrent Clear Claimed Marks 0.009ms", "Concurrent Clear Claimed Marks" -> "0.009ms"
* "Pre Evacuate Collection Set: 0.0ms" , "Pre Evacuate Collection Set" -> "0.0ms"
* do not check format
*/
public static String parseValueOfPrefix(String s, String prefix) {
int index = prefix.length();
// filter some signs
int begin;
for (begin = index; begin < s.length(); begin++) {
char c = s.charAt(begin);
if (c != ' ' && c != ':') {
break;
}
}
return s.substring(begin);
}
/**
* e.g. "3604K->3608K(262144K)" -> [null, "3604K", "3608K", "262144K"]
* "3604K->3608K" -> ["3604K", null, "3608K", null]
* "3604K(262144K)->3608K(262144K)" -> ["3604K", "262144K", "3608K", "262144K"]
* "608K(262144K)" -> [null, null, "3608", "262144"]
* do not check format
*/
public static String[] parseFromToString(String s) {
String[] result = new String[4];
int arrow = s.indexOf("->");
String[] parts;
if (arrow >= 0) {
parts = new String[]{s.substring(0, arrow), s.substring(arrow + 2)};
} else {
parts = new String[]{s};
}
int base = parts.length == 1 ? 2 : 0;
for (String part : parts) {
int indexLeftBracket = part.indexOf('(');
if (indexLeftBracket >= 0) {
result[base] = part.substring(0, indexLeftBracket);
result[base + 1] = part.substring(indexLeftBracket + 1, part.length() - 1);
} else {
result[base] = part;
}
base += 2;
}
return result;
}
/**
* e.g. "3604K->3608K(262144K)" -> [3604, -1, 3608, 262144]
* "3604K->3608K" -> [3604, -1, 3608, -1]
* "3604K(262144K)->3608K(262144K)" -> [3604, -1, 3608, 262144]
* "608K(262144K)" -> [-1, -1, 3608, 262144]
* do not check format
*/
public static long[] parseMemorySizeFromTo(String s, long divideIfNoUnit) {
long[] result = new long[4];
String[] parts = parseFromToString(s);
for (int i = 0; i < 4; i++) {
result[i] = parts[i] == null ? UNKNOWN_INT : toByte(parts[i], divideIfNoUnit);
}
return result;
}
public static long[] parseMemorySizeFromTo(String s) {
return parseMemorySizeFromTo(s, BYTE_UNIT_GAP);
}
// e.g " Pause Young (Normal) (G1 Evacuation Pause) " -> ["Pause", "Young", "Normal", "(G1", "Evacuation", "Pause)"]
public static String[] splitBySpace(String s) {
List<String> list = new ArrayList<>();
int index = 0;
while (index < s.length()) {
int left = index;
while (left < s.length() && s.charAt(left) == ' ') {
left++;
}
if (left >= s.length()) {
break;
}
int right = left + 1;
while (right < s.length() && s.charAt(right) != ' ') {
right++;
}
list.add(s.substring(left, right));
index = right;
}
return list.toArray(new String[0]);
}
// e.g " Pause Young (Normal) (G1 Evacuation Pause) " -> ["Pause Young", "Normal", "G1 Evacuation Pause"]
public static String[] splitByBracket(String s) {
List<String> list = new ArrayList<>();
int index = 0;
while (index < s.length()) {
int indexLeftBracket = s.indexOf('(', index);
int indexRightBracket = s.indexOf(')', index);
int nextIndex;
if (indexLeftBracket < 0) {
nextIndex = indexRightBracket;
} else if (indexRightBracket < 0) {
nextIndex = indexLeftBracket;
} else {
nextIndex = Math.min(indexLeftBracket, indexRightBracket);
}
if (nextIndex < 0) {
nextIndex = s.length();
}
String word = s.substring(index, nextIndex).trim();
if (word.length() > 0) {
list.add(word);
}
index = nextIndex + 1;
}
return list.toArray(new String[0]);
}
// e.g. Pause Young (Normal) (System.gc())
// input->| |<-output
public static int nextBalancedRightBracket(String text, int leftBracketIndex) {
int balance = 1;
for (int i = leftBracketIndex + 1; i < text.length(); i++) {
char c = text.charAt(i);
if (c == '(') {
balance++;
} else if (c == ')') {
balance--;
}
if (balance == 0) {
return i;
}
}
return -1;
}
// return true if text starting from index is equal to pattern
public static boolean stringSubEquals(String text, int index, String pattern) {
if (text.length() < pattern.length() + index) {
return false;
}
for (int i = 0; i < pattern.length(); i++) {
if (text.charAt(i + index) != pattern.charAt(i)) {
return false;
}
}
return true;
}
public static String stringSubEqualsAny(String text, int index, String[] searchStrings) {
for (String searchString : searchStrings) {
if (stringSubEquals(text, index, searchString)) {
return searchString;
}
}
return null;
}
public static boolean isDatestamp(String text) {
return isDatestamp(text, 0);
}
public static final int DATESTAMP_LENGTH = "2021-11-24T23:23:44.225-0800".length();
// we don't check strictly for efficiency
public static boolean isDatestamp(String text, int index) {
return text.length() - index >= DATESTAMP_LENGTH &&// check range
text.charAt(index + 4) == '-' &&
text.charAt(index + 7) == '-' &&
text.charAt(index + 10) == 'T' &&
text.charAt(index + 13) == ':' &&
text.charAt(index + 19) == '.';
}
public static long parseDateStamp(String text) {
// need an additional ':' so that datetime can be correctly parsed
text = text.substring(0, text.length() - 2) + ":" + text.substring(text.length() - 2);
OffsetDateTime odt = OffsetDateTime.parse(text);
return odt.toInstant().toEpochMilli();
}
// check text is a decimal from index and there are digitNumberAfterDot after dot
// return end index if matching, else -1
public static int isDecimal(String text, int index, int digitNumberAfterDot) {
for (int i = index; i < text.length(); i++) {
char c = text.charAt(i);
if (Character.isDigit(c)) {
continue;
}
if (c != '.') {
return -1;
}
for (int j = 1; j <= digitNumberAfterDot; j++) {
if (!Character.isDigit(text.charAt(i + j))) {
return -1;
}
}
return i + digitNumberAfterDot + 1;
}
return -1;
}
}
| 6,734 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/util/FourConsumer.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.util;
public interface FourConsumer<T1, T2, T3, T4> {
void accept(T1 t1, T2 t2, T3 t3, T4 t4);
}
| 6,735 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/util/TriConsumer.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.util;
public interface TriConsumer<T1, T2, T3> {
void accept(T1 t1, T2 t2, T3 t3);
}
| 6,736 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/util/IntData.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.util;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
public class IntData {
private int n;
private long sum;
private int min = Integer.MAX_VALUE;
private int max = Integer.MIN_VALUE;
public void add(int x) {
if (x == UNKNOWN_INT) {
return;
}
sum += x;
n++;
min = Math.min(min, x);
max = Math.max(max, x);
}
public int getN() {
return n;
}
public long getSum() {
if (n == 0) {
return UNKNOWN_INT;
}
return sum;
}
public int getMin() {
if (n == 0) {
return UNKNOWN_INT;
}
return min;
}
public int getMax() {
if (n == 0) {
return UNKNOWN_INT;
}
return max;
}
public double average() {
if (n == 0) {
return UNKNOWN_DOUBLE;
}
return ((double) sum) / ((double) n);
}
}
| 6,737 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/diagnoser/AbnormalType.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.diagnoser;
import org.eclipse.jifa.gclog.util.I18nStringView;
import java.util.HashMap;
import java.util.Map;
public class AbnormalType {
public static String I18N_PREFIX = "jifa.gclog.diagnose.abnormal.";
private static Map<String, AbnormalType> name2Type = new HashMap<>();
// Types below can be used in either gc detail diagnose and global diagnose.
// Order these members by their general importance
public static AbnormalType OUT_OF_MEMORY = new AbnormalType("outOfMemory");
public static AbnormalType ALLOCATION_STALL = new AbnormalType("allocationStall");
public static AbnormalType METASPACE_FULL_GC = new AbnormalType("metaspaceFullGC");
public static AbnormalType HEAP_MEMORY_FULL_GC = new AbnormalType("heapMemoryFullGC");
public static AbnormalType FREQUENT_YOUNG_GC = new AbnormalType("frequentYoungGC");
public static AbnormalType LONG_YOUNG_GC_PAUSE = new AbnormalType("longYoungGCPause");
public static AbnormalType SYSTEM_GC = new AbnormalType("systemGC");
public static AbnormalType LONG_G1_REMARK = new AbnormalType("longG1Remark");
public static AbnormalType LONG_CMS_REMARK = new AbnormalType("longCMSRemark");
// Types below are used in gc details and simply denote which part of
// info is not normal and the problem description text. They can be declared in any order.
public static AbnormalType BAD_DURATION = new AbnormalType("badDuration");
public static AbnormalType BAD_EVENT_TYPE = new AbnormalType("badEventType");
public static AbnormalType BAD_CAUSE_FULL_GC = new AbnormalType("badCauseFullGC");
public static AbnormalType BAD_INTERVAL = new AbnormalType("badInterval");
public static AbnormalType BAD_PROMOTION = new AbnormalType("badPromotion");
public static AbnormalType BAD_YOUNG_GEN_CAPACITY = new AbnormalType("smallYoungGen");
public static AbnormalType BAD_OLD_GEN_CAPACITY = new AbnormalType("smallOldGen");
public static AbnormalType BAD_HUMONGOUS_USED = new AbnormalType("highHumongousUsed");
public static AbnormalType BAD_HEAP_USED = new AbnormalType("highHeapUsed");
public static AbnormalType BAD_OLD_USED = new AbnormalType("highOldUsed");
public static AbnormalType BAD_METASPACE_USED = new AbnormalType("highMetaspaceUsed");
public static AbnormalType BAD_SYS = new AbnormalType("badSys");
public static AbnormalType BAD_USR = new AbnormalType("badUsr");
public static AbnormalType TO_SPACE_EXHAUSTED = new AbnormalType("toSpaceExhausted");
public static AbnormalType LAST_TYPE = new AbnormalType("lastType");
private String name;
private int ordinal;
private AbnormalType(String name) {
this.name = name;
ordinal = name2Type.size();
name2Type.put(name, this);
}
public static AbnormalType getType(String name) {
return name2Type.getOrDefault(name, null);
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
public I18nStringView toI18nStringView() {
return new I18nStringView(I18N_PREFIX + name);
}
public int getOrdinal() {
return ordinal;
}
}
| 6,738 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/diagnoser/DefaultSuggestionGenerator.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.diagnoser;
import org.eclipse.jifa.common.JifaException;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.util.I18nStringView;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.eclipse.jifa.gclog.diagnoser.SuggestionType.*;
// This class generates common suggestions when we can not find the exact cause of problem.
public class DefaultSuggestionGenerator extends SuggestionGenerator {
private AbnormalPoint ab;
public DefaultSuggestionGenerator(GCModel model, AbnormalPoint ab) {
super(model);
this.ab = ab;
}
private static Map<AbnormalType, Method> rules = new HashMap<>();
static {
initializeRules();
}
private static void initializeRules() {
Method[] methods = DefaultSuggestionGenerator.class.getDeclaredMethods();
for (Method method : methods) {
GeneratorRule annotation = method.getAnnotation(GeneratorRule.class);
if (annotation != null) {
method.setAccessible(true);
int mod = method.getModifiers();
if (Modifier.isAbstract(mod) || Modifier.isFinal(mod)) {
throw new JifaException("Illegal method modifier: " + method);
}
rules.put(AbnormalType.getType(annotation.value()), method);
}
}
}
@GeneratorRule("metaspaceFullGC")
private void metaspaceFullGC() {
addSuggestion(CHECK_METASPACE);
addSuggestion(ENLARGE_METASPACE);
fullGCSuggestionCommon();
}
@GeneratorRule("systemGC")
private void systemGC() {
addSuggestion(CHECK_SYSTEM_GC);
addSuggestion(DISABLE_SYSTEM_GC);
suggestOldSystemGC();
fullGCSuggestionCommon();
}
@GeneratorRule("outOfMemory")
private void outOfMemory() {
addSuggestion(CHECK_MEMORY_LEAK);
suggestEnlargeHeap(false);
}
@GeneratorRule("allocationStall")
private void allocationStall() {
addSuggestion(CHECK_MEMORY_LEAK);
suggestEnlargeHeap(true);
addSuggestion(INCREASE_CONC_GC_THREADS);
addSuggestion(INCREASE_Z_ALLOCATION_SPIKE_TOLERANCE);
}
@GeneratorRule("heapMemoryFullGC")
private void heapMemoryFullGC() {
addSuggestion(CHECK_MEMORY_LEAK);
addSuggestion(CHECK_FAST_PROMOTION);
suggestStartOldGCEarly();
fullGCSuggestionCommon();
}
@GeneratorRule("longYoungGCPause")
private void longYoungGCPause() {
addSuggestion(CHECK_LIVE_OBJECTS);
addSuggestion(CHECK_CPU_TIME);
addSuggestion(CHECK_REFERENCE_GC);
suggestCheckEvacuationFailure();
suggestShrinkYoungGen();
suggestUseMoreDetailedLogging();
}
@GeneratorRule("frequentYoungGC")
private void frequentYoungGC() {
suggestExpandYoungGen();
addSuggestion(CHECK_FAST_OBJECT_ALLOCATION);
}
@GeneratorRule("longG1Remark")
private void longG1Remark() {
addSuggestion(CHECK_REFERENCE_GC);
addSuggestion(CHECK_CLASS_UNLOADING);
suggestUseMoreDetailedLogging();
}
@GeneratorRule("longCMSRemark")
private void longCMSRemark() {
addSuggestion(CHECK_RESCAN);
addSuggestion(CHECK_REFERENCE_GC);
addSuggestion(CHECK_CLASS_UNLOADING);
suggestUseMoreDetailedLogging();
}
public List<I18nStringView> generate() {
if (ab.getType() == null) {
return result;
}
Method rule = rules.getOrDefault(ab.getType(), null);
if (rule != null) {
try {
rule.invoke(this);
} catch (Exception e) {
ErrorUtil.shouldNotReachHere();
}
}
return result;
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
private @interface GeneratorRule {
String value();
}
}
| 6,739 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/diagnoser/GlobalDiagnoseInfo.java | package org.eclipse.jifa.gclog.diagnoser;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.model.GCModel;
import java.util.ArrayList;
import java.util.List;
import static org.eclipse.jifa.gclog.util.Constant.*;
public class GlobalDiagnoseInfo {
private GCModel model;
private AnalysisConfig config; // time range in this config is ignored
private EventDiagnoseInfo[] eventDiagnoseInfos;
public GlobalDiagnoseInfo(GCModel model, AnalysisConfig config) {
this.model = model;
this.config = config;
int length = model.getAllEvents().size();
this.eventDiagnoseInfos = new EventDiagnoseInfo[length];
for (int i = 0; i < length; i++) {
eventDiagnoseInfos[i] = new EventDiagnoseInfo();
}
}
public GCModel getModel() {
return model;
}
public AnalysisConfig getConfig() {
return config;
}
public EventDiagnoseInfo[] getEventDiagnoseInfos() {
return eventDiagnoseInfos;
}
public EventDiagnoseInfo getEventDiagnoseInfo(GCEvent event) {
int id = event.getId();
if (id == UNKNOWN_INT) {
ErrorUtil.shouldNotReachHere();
}
return eventDiagnoseInfos[id];
}
public List<AbnormalPoint.AbnormalPointVO> getEventDiagnoseVO(GCEvent event) {
List<AbnormalPoint.AbnormalPointVO> result = new ArrayList<>();
EventDiagnoseInfo eventDiagnose = getEventDiagnoseInfo(event);
if (eventDiagnose == null) {
return result;
}
eventDiagnose.getAbnormals().iterate(ab -> result.add(ab.toVO()));
return result;
}
public String toDebugString() {
StringBuilder sb = new StringBuilder();
for (GCEvent event : model.getGcEvents()) {
eventToDebugString(event, sb);
event.phasesDoDFS(phase -> {
sb.append(" ");
eventToDebugString(phase, sb);
});
}
return sb.toString();
}
private void eventToDebugString(GCEvent event, StringBuilder sb) {
sb.append(event.toDebugString(model)).append(" [");
getEventDiagnoseInfo(event).getAbnormals().iterate(ab ->sb.append(ab).append(", "));
sb.append("]\n");
}
}
| 6,740 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/diagnoser/EventAbnormalDetector.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.diagnoser;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.*;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import static org.eclipse.jifa.gclog.diagnoser.AbnormalType.*;
import static org.eclipse.jifa.gclog.diagnoser.AbnormalType.TO_SPACE_EXHAUSTED;
import static org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType.*;
import static org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea.*;
import static org.eclipse.jifa.gclog.util.Constant.*;
// This class detects abnormals that will be displayed in gc detail in frontend. Their cause and suggestion will
// be found in the next step in EventSuggestionGenerator.
public class EventAbnormalDetector {
private static List<Method> eventDiagnoseRules = new ArrayList<>();
private GCModel model;
private AnalysisConfig config;
private GlobalDiagnoseInfo globalDiagnoseInfo;
public EventAbnormalDetector(GCModel model, AnalysisConfig config, GlobalDiagnoseInfo globalDiagnoseInfo) {
this.model = model;
this.config = config;
this.globalDiagnoseInfo = globalDiagnoseInfo;
}
public void diagnose() {
callDiagnoseRules();
}
private void callDiagnoseRules() {
// The order matters.
duration();
eventType();
gcCause();
specialSituation();
memory();
cputime();
promotion();
interval();
}
private void addAbnormal(GCEvent event, AbnormalType type) {
EventAbnormalSet set = globalDiagnoseInfo.getEventDiagnoseInfo(event).getAbnormals();
set.add(new AbnormalPoint(type, event));
}
private void duration() {
for (GCEvent event : model.getAllEvents()) {
boolean pause = event.isPause();
double threshold = pause ? config.getLongPauseThreshold() : config.getLongConcurrentThreshold();
double actual = pause ? event.getPause() : event.getDuration();
if (actual == UNKNOWN_DOUBLE) {
return;
}
if (actual >= threshold) {
addAbnormal(event, BAD_DURATION);
}
}
}
protected void eventType() {
for (GCEvent event : model.getAllEvents()) {
if (event.getEventType().isBad()) {
addAbnormal(event, BAD_EVENT_TYPE);
}
}
}
protected void gcCause() {
for (GCEvent event : model.getGcEvents()) {
if (event.getCause() != null && event.isBadFullGC()) {
addAbnormal(event, BAD_CAUSE_FULL_GC);
}
}
// todo: we should warn user if humongous or gclocker gc is frequent
}
protected void specialSituation() {
for (GCEvent event : model.getGcEvents()) {
if (event.isTrue(GCEventBooleanType.TO_SPACE_EXHAUSTED)) {
addAbnormal(event, TO_SPACE_EXHAUSTED);
}
}
}
protected void memory() {
List<MemoryArea> areasToCheck = new ArrayList<>(5);
if (model.isGenerational()) {
areasToCheck.add(YOUNG);
areasToCheck.add(OLD);
}
if (model.hasHumongousArea()) {
areasToCheck.add(HUMONGOUS);
}
areasToCheck.add(HEAP);
areasToCheck.add(METASPACE);
for (GCEvent event : model.getGcCollectionEvents()) {
GCMemoryItem heap = event.getMemoryItem(HEAP);
long heapCapacity = heap != null ? heap.getPostCapacity() : UNKNOWN_INT;
for (MemoryArea area : areasToCheck) {
GCMemoryItem memory = event.getMemoryItem(area);
if (memory == null) {
continue;
}
// post capacity
long capacity = memory.getPostCapacity();
if (capacity != UNKNOWN_INT && heapCapacity != UNKNOWN_INT && (area == YOUNG || area == OLD)) {
// only check one case: generation capacity is too small
long threshold = (long) (config.getSmallGenerationThreshold() * heapCapacity / 100);
if (capacity <= threshold) {
addAbnormal(event, area == YOUNG ? BAD_YOUNG_GEN_CAPACITY : BAD_OLD_GEN_CAPACITY);
}
}
// post used
long postUsed = memory.getPostUsed();
if (area == YOUNG || postUsed == UNKNOWN_INT) {
continue;
}
// check one case: used is too high after gc
if (area == OLD) {
// FIXME: in JDK8, printed g1 post capacity may be much smaller than eden preused of the next
// young gc. Maybe we need to improve this check
if (capacity != UNKNOWN_INT && (event.isFullGC() || event.isTrue(GC_AT_END_OF_OLD_CYCLE))) {
long threshold = (long) (capacity * config.getHighOldUsageThreshold() / 100);
if (postUsed > threshold) {
addAbnormal(event, BAD_OLD_USED);
}
}
} else if (area == HUMONGOUS) {
if (heapCapacity != UNKNOWN_INT) {
long threshold = (long) (heapCapacity * config.getHighHumongousUsageThreshold() / 100);
if (postUsed >= threshold) {
addAbnormal(event, BAD_HUMONGOUS_USED);
}
}
} else if (area == HEAP) {
if (capacity != UNKNOWN_INT && (event.isFullGC() || event.isTrue(GC_AT_END_OF_OLD_CYCLE))) {
long threshold = (long) (capacity * config.getHighOldUsageThreshold() / 100);
if (postUsed > threshold) {
addAbnormal(event, BAD_HEAP_USED);
}
}
} else if (area == METASPACE) {
if (capacity != UNKNOWN_INT && (event.isFullGC() || event.isTrue(GC_AFTER_REMARK))) {
long threshold = (long) (capacity * config.getHighMetaspaceUsageThreshold() / 100);
if (postUsed > threshold) {
addAbnormal(event, BAD_METASPACE_USED);
}
}
}
}
}
}
protected void cputime() {
for (GCEvent event : model.getAllEvents()) {
CpuTime cpuTime = event.getCpuTime();
// we rarely care about cpu time of concurrent phase
if (cpuTime == null || event.isPause()) {
continue;
}
if (!globalDiagnoseInfo.getEventDiagnoseInfo(event)
.getAbnormals().contains(BAD_DURATION)) {
continue;
}
double real = cpuTime.getReal();
double sys = cpuTime.getSys();
double usr = cpuTime.getUser();
if (sys / real >= config.getHighSysThreshold() / 100) {
addAbnormal(event, BAD_SYS);
}
if (usr / real <= config.getLowUsrThreshold() / 100) {
addAbnormal(event, BAD_USR);
}
}
}
protected void promotion() {
if (!model.isGenerational()) {
return;
}
for (GCEvent event : model.getGcCollectionEvents()) {
long promotion = event.getPromotion();
if (promotion == UNKNOWN_INT) {
continue;
}
GCMemoryItem old = event.getMemoryItem(OLD);
if (old.getPostCapacity() == UNKNOWN_INT) {
continue;
}
long threshold = (long) (old.getPostCapacity() * config.getHighPromotionThreshold() / 100);
if (promotion >= threshold) {
addAbnormal(event, BAD_PROMOTION);
}
}
}
protected void interval() {
for (GCEvent event : model.getAllEvents()) {
double actual = event.getInterval();
if (actual == UNKNOWN_DOUBLE) {
continue;
}
GCEventType eventType = event.getEventType();
double threshold;
if (eventType.isYoungGC()) {
threshold = config.getYoungGCFrequentIntervalThreshold();
} else if (eventType.isOldGC()) {
threshold = config.getOldGCFrequentIntervalThreshold();
} else if (event.isFullGC()) {
threshold = config.getFullGCFrequentIntervalThreshold();
} else {
continue;
}
if (actual <= threshold) {
addAbnormal(event, BAD_INTERVAL);
}
}
}
}
| 6,741 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/diagnoser/AnalysisConfig.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.diagnoser;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.vo.TimeRange;
import java.util.Objects;
@Data
@NoArgsConstructor
@ToString
public class AnalysisConfig {
private TimeRange timeRange;
private double longPauseThreshold;
private double longConcurrentThreshold;
private double youngGCFrequentIntervalThreshold;
private double oldGCFrequentIntervalThreshold;
private double fullGCFrequentIntervalThreshold;
private double highOldUsageThreshold;
private double highHumongousUsageThreshold;
private double highHeapUsageThreshold;
private double highMetaspaceUsageThreshold;
private double smallGenerationThreshold;
private double highPromotionThreshold;
private double badThroughputThreshold;
private double tooManyOldGCThreshold;
private double highSysThreshold;
private double lowUsrThreshold;
public static AnalysisConfig defaultConfig(GCModel model) {
AnalysisConfig config = new AnalysisConfig();
config.setTimeRange(new TimeRange(model.getStartTime(), model.getEndTime()));
config.setLongPauseThreshold(model.isPauseless() ? 30 : 400);
config.setLongConcurrentThreshold(30000);
config.setYoungGCFrequentIntervalThreshold(1000);
config.setOldGCFrequentIntervalThreshold(15000);
config.setFullGCFrequentIntervalThreshold(model.isGenerational() ? 60000 : 2000);
config.setHighOldUsageThreshold(80);
config.setHighHumongousUsageThreshold(50);
config.setHighHeapUsageThreshold(60);
config.setHighMetaspaceUsageThreshold(80);
config.setSmallGenerationThreshold(10);
config.setHighPromotionThreshold(3);
config.setBadThroughputThreshold(90);
config.setTooManyOldGCThreshold(20);
config.setHighSysThreshold(50);
config.setLowUsrThreshold(100);
return config;
}
// time range is ignored here
@Override
public boolean equals(Object o) {
if (this == o) return true;
AnalysisConfig config = (AnalysisConfig) o;
return Double.compare(config.longPauseThreshold, longPauseThreshold) == 0 && Double.compare(config.longConcurrentThreshold, longConcurrentThreshold) == 0 && Double.compare(config.youngGCFrequentIntervalThreshold, youngGCFrequentIntervalThreshold) == 0 && Double.compare(config.oldGCFrequentIntervalThreshold, oldGCFrequentIntervalThreshold) == 0 && Double.compare(config.fullGCFrequentIntervalThreshold, fullGCFrequentIntervalThreshold) == 0 && Double.compare(config.highOldUsageThreshold, highOldUsageThreshold) == 0 && Double.compare(config.highHumongousUsageThreshold, highHumongousUsageThreshold) == 0 && Double.compare(config.highHeapUsageThreshold, highHeapUsageThreshold) == 0 && Double.compare(config.highMetaspaceUsageThreshold, highMetaspaceUsageThreshold) == 0 && Double.compare(config.smallGenerationThreshold, smallGenerationThreshold) == 0 && Double.compare(config.highPromotionThreshold, highPromotionThreshold) == 0 && Double.compare(config.badThroughputThreshold, badThroughputThreshold) == 0 && Double.compare(config.tooManyOldGCThreshold, tooManyOldGCThreshold) == 0 && Double.compare(config.highSysThreshold, highSysThreshold) == 0 && Double.compare(config.lowUsrThreshold, lowUsrThreshold) == 0;
}
@Override
public int hashCode() {
return Objects.hash(longPauseThreshold, longConcurrentThreshold, youngGCFrequentIntervalThreshold, oldGCFrequentIntervalThreshold, fullGCFrequentIntervalThreshold, highOldUsageThreshold, highHumongousUsageThreshold, highHeapUsageThreshold, highMetaspaceUsageThreshold, smallGenerationThreshold, highPromotionThreshold, badThroughputThreshold, tooManyOldGCThreshold, highSysThreshold, lowUsrThreshold);
}
}
| 6,742 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/diagnoser/SuggestionType.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.diagnoser;
public enum SuggestionType {
// The order of enums doesn't matter
// Whenever a new suggestion is added here, add its text to the frontend
UPGRADE_TO_11_G1_FULL_GC("upgradeTo11G1FullGC"),
CHECK_SYSTEM_GC("checkSystemGC"),
DISABLE_SYSTEM_GC("disableSystemGC"),
OLD_SYSTEM_GC("oldSystemGC"),
CHECK_METASPACE("checkMetaspace"),
ENLARGE_METASPACE("enlargeMetaspace"),
ENLARGE_HEAP("enlargeHeap"),
INCREASE_CONC_GC_THREADS("increaseConcGCThreads"),
INCREASE_Z_ALLOCATION_SPIKE_TOLERANCE("increaseZAllocationSpikeTolerance"),
DECREASE_IHOP("decreaseIHOP"),
DECREASE_CMSIOF("decreaseCMSIOF"),
CHECK_LIVE_OBJECTS("checkLiveObjects"),
CHECK_REFERENCE_GC("checkReferenceGC"),
CHECK_CPU_TIME("checkCPUTime"),
SHRINK_YOUNG_GEN("shrinkYoungGen"),
SHRINK_YOUNG_GEN_G1("shrinkYoungGenG1"),
CHECK_EVACUATION_FAILURE("checkEvacuationFailure"),
CHECK_FAST_PROMOTION("checkFastPromotion"),
CHECK_RESCAN("checkRescan"),
CHECK_CLASS_UNLOADING("checkClassUnloading"),
EXPAND_YOUNG_GEN("expandYoungGen"),
EXPAND_YOUNG_GEN_G1("expandYoungGenG1"),
CHECK_FAST_OBJECT_ALLOCATION("checkFastObjectAllocation"),
USE_MORE_DETAILED_LOGGING_PREUNIFIED("useMoreDetailedLoggingPreunified"),
USE_MORE_DETAILED_LOGGING_UNIFIED("useMoreDetailedLoggingUnified"),
CHECK_MEMORY_LEAK("checkMemoryLeak");
public static final String I18N_PREFIX = "jifa.gclog.diagnose.suggestion.";
private String name;
SuggestionType(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}
| 6,743 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/diagnoser/AbnormalPoint.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.diagnoser;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.jifa.gclog.event.TimedEvent;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.util.I18nStringView;
import java.util.Comparator;
import java.util.List;
import static org.eclipse.jifa.gclog.diagnoser.AbnormalType.LAST_TYPE;
@Data
public class AbnormalPoint {
private AbnormalType type;
private TimedEvent site;
private List<I18nStringView> defaultSuggestions;
public static final AbnormalPoint LEAST_SERIOUS = new AbnormalPoint(LAST_TYPE, null);
public AbnormalPoint(AbnormalType type, TimedEvent site) {
this.type = type;
this.site = site;
}
public static final Comparator<AbnormalPoint> compareByImportance = (ab1, ab2) -> {
if (ab1.type != ab2.type) {
return ab1.type.getOrdinal() - ab2.type.getOrdinal();
}
return 0;
};
public void generateDefaultSuggestions(GCModel model) {
this.defaultSuggestions = new DefaultSuggestionGenerator(model, this).generate();
}
public AbnormalPointVO toVO() {
AbnormalPointVO vo = new AbnormalPointVO();
vo.setType(type.getName());
vo.setDefaultSuggestions(defaultSuggestions);
return vo;
}
@Override
public String toString() {
return "AbnormalPoint{" +
"type=" + type +
", defaultSuggestions=" + defaultSuggestions +
'}';
}
@Data
@NoArgsConstructor
public static class AbnormalPointVO {
// don't use I18nStringView because frontend need to check this field
private String type;
private List<I18nStringView> defaultSuggestions;
}
}
| 6,744 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/diagnoser/SuggestionGenerator.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.diagnoser;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.model.modeInfo.GCLogStyle;
import org.eclipse.jifa.gclog.util.I18nStringView;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import static org.eclipse.jifa.gclog.diagnoser.SuggestionType.*;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
public abstract class SuggestionGenerator {
protected GCModel model;
protected BitSet givenCause = new BitSet();
protected List<I18nStringView> result = new ArrayList<>();
public SuggestionGenerator(GCModel model) {
this.model = model;
}
protected void addSuggestion(SuggestionType type, Object... params) {
// don't add duplicate suggestions
if (givenCause.get(type.ordinal())) {
return;
}
givenCause.set(type.ordinal());
result.add(new I18nStringView(SuggestionType.I18N_PREFIX + type.toString(), params));
}
protected void suggestExpandYoungGen() {
if (model.getCollectorType() == GCCollectorType.G1) {
addSuggestion(EXPAND_YOUNG_GEN_G1);
} else {
addSuggestion(EXPAND_YOUNG_GEN);
}
}
protected void suggestShrinkYoungGen() {
if (model.getCollectorType() == GCCollectorType.G1) {
addSuggestion(SHRINK_YOUNG_GEN_G1);
} else {
addSuggestion(SHRINK_YOUNG_GEN);
}
}
protected void suggestUseMoreDetailedLogging() {
if (model.getLogStyle() == GCLogStyle.UNIFIED) {
addSuggestion(USE_MORE_DETAILED_LOGGING_UNIFIED);
}
}
protected void suggestOldSystemGC() {
if (model.hasOldGC()) {
addSuggestion(OLD_SYSTEM_GC);
}
}
protected void suggestEnlargeHeap(boolean suggestHeapSize) {
if (suggestHeapSize) {
long size = model.getRecommendMaxHeapSize();
if (size != UNKNOWN_INT) {
addSuggestion(ENLARGE_HEAP, "recommendSize", size);
} else {
addSuggestion(ENLARGE_HEAP);
}
} else {
addSuggestion(ENLARGE_HEAP);
}
}
protected void fullGCSuggestionCommon() {
if (model.getCollectorType() == GCCollectorType.G1 && model.getLogStyle() == GCLogStyle.PRE_UNIFIED) {
addSuggestion(UPGRADE_TO_11_G1_FULL_GC);
}
}
protected void suggestStartOldGCEarly() {
switch (model.getCollectorType()) {
case CMS:
addSuggestion(DECREASE_CMSIOF);
break;
case G1:
addSuggestion(DECREASE_IHOP);
break;
}
}
protected void suggestCheckEvacuationFailure() {
if (model.getCollectorType() == GCCollectorType.G1) {
addSuggestion(CHECK_EVACUATION_FAILURE);
}
}
}
| 6,745 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/diagnoser/EventAbnormalSet.java | package org.eclipse.jifa.gclog.diagnoser;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
public class EventAbnormalSet {
private List<AbnormalPoint> abnormals = null;
public void add(AbnormalPoint ab) {
if (abnormals == null) {
abnormals = new ArrayList<>();
}
abnormals.add(ab);
}
public AbnormalPoint get(AbnormalType type) {
if (abnormals != null) {
for (AbnormalPoint abnormal : abnormals) {
if (abnormal.getType() == type) {
return abnormal;
}
}
}
return null;
}
public int size() {
if (abnormals == null) {
return 0;
}
return abnormals.size();
}
public boolean contains(AbnormalType type) {
return get(type) != null;
}
public void iterate(Consumer<AbnormalPoint> consumer) {
if (abnormals == null) {
return;
}
for (AbnormalPoint abnormal : abnormals) {
consumer.accept(abnormal);
}
}
public boolean isEmpty() {
if (abnormals == null) {
return true;
}
return abnormals.isEmpty();
}
public List<AbnormalPoint.AbnormalPointVO> toVO() {
List<AbnormalPoint.AbnormalPointVO> result = new ArrayList<>();
this.iterate(ab -> {
result.add(ab.toVO());
});
return result;
}
@Override
public String toString() {
return "EventAbnormalSet{" +
"abnormals=" + abnormals +
'}';
}
}
| 6,746 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/diagnoser/GlobalDiagnoser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.diagnoser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.eclipse.jifa.common.JifaException;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.event.TimedEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.GCCause;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.model.ZGCModel;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.util.DoubleData;
import org.eclipse.jifa.gclog.util.I18nStringView;
import org.eclipse.jifa.gclog.util.Key2ValueListMap;
import org.eclipse.jifa.gclog.vo.TimeRange;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static org.eclipse.jifa.gclog.diagnoser.AbnormalType.*;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
import static org.eclipse.jifa.gclog.event.TimedEvent.newByStartEnd;
/**
* To diagnose abnormal in gclog, we mainly try to analyze 3 things:
* 1. what's going wrong
* 2. why it is going wrong
* 3. how to deal with it
* Currently, we have just implemented finding global serious and definite problem
* and give general suggestions based on phenomenon without analyzing cause specific cause.
* In the future, we will
* 1. do local diagnose on each event, find abnormal of event info, explain its cause
* and give appropriate suggestion if necessary.
* 2. Try to find accurate cause and give "the best" suggestion for those serious based on local diagnose.
*/
public class GlobalDiagnoser {
private GCModel model;
private AnalysisConfig config;
private Key2ValueListMap<String, Double> allProblems = new Key2ValueListMap<>();
private List<AbnormalPoint> mostSeriousProblemList = new ArrayList<>();
private List<AbnormalPoint> mergedMostSeriousProblemList = new ArrayList<>();
private AbnormalPoint mostSerious = AbnormalPoint.LEAST_SERIOUS;
public GlobalDiagnoser(GCModel model, AnalysisConfig config) {
this.model = model;
this.config = config;
}
public GlobalAbnormalInfo diagnose() {
findAllAbnormalPoints();
mergeTimeRanges();
return generateVo();
}
private void findAllAbnormalPoints() {
for (Method rule : globalDiagnoseRules) {
try {
rule.invoke(this);
} catch (Exception e) {
ErrorUtil.shouldNotReachHere();
}
}
}
// Extend the start time forward by 2.5 min so that user can see what happened before the problem.
// Extend the end time backward by 2.5 min so adjacent events can be merged.
private static long EXTEND_TIME = 150 * 1000;
// allow changing this value for testing
public static void setExtendTime(long extendTime) {
EXTEND_TIME = extendTime;
}
private void mergeTimeRanges() {
if (mostSerious == AbnormalPoint.LEAST_SERIOUS) {
return;
}
AbnormalPoint first = mostSeriousProblemList.get(0);
mostSeriousProblemList.sort(Comparator.comparingDouble(ab -> ab.getSite().getStartTime()));
double start = UNKNOWN_DOUBLE;
double end = UNKNOWN_DOUBLE;
for (AbnormalPoint ab : mostSeriousProblemList) {
if (start == UNKNOWN_DOUBLE) {
start = ab.getSite().getStartTime();
end = Math.max(ab.getSite().getStartTime(), ab.getSite().getEndTime());
} else if (ab.getSite().getStartTime() - end <= 2 * EXTEND_TIME) {
end = Math.max(Math.max(ab.getSite().getStartTime(), ab.getSite().getEndTime()), end);
} else {
AbnormalPoint merged = new AbnormalPoint(first.getType(), newByStartEnd(start, end));
mergedMostSeriousProblemList.add(merged);
start = ab.getSite().getStartTime();
end = Math.max(ab.getSite().getStartTime(), ab.getSite().getEndTime());
}
}
if (start != UNKNOWN_DOUBLE) {
AbnormalPoint merged = new AbnormalPoint(first.getType(), newByStartEnd(start, end));
mergedMostSeriousProblemList.add(merged);
}
}
private GlobalAbnormalInfo generateVo() {
MostSeriousProblemSummary summary = null;
if (mostSerious != AbnormalPoint.LEAST_SERIOUS) {
AbnormalPoint first = mergedMostSeriousProblemList.get(0);
first.generateDefaultSuggestions(model);
summary = new MostSeriousProblemSummary(
mergedMostSeriousProblemList.stream()
.sorted((ab1, ab2) -> Double.compare(ab2.getSite().getDuration(), ab1.getSite().getDuration()))
.limit(3)
.sorted(Comparator.comparingDouble(ab -> ab.getSite().getStartTime()))
.map(ab -> new TimeRange(
Math.max(ab.getSite().getStartTime() - EXTEND_TIME, config.getTimeRange().getStart()),
Math.min(ab.getSite().getEndTime() + EXTEND_TIME, config.getTimeRange().getEnd())
))
.collect(Collectors.toList()),
first.getType().toI18nStringView(),
first.getDefaultSuggestions()
);
}
return new GlobalAbnormalInfo(summary, allProblems.getInnerMap());
}
private static List<Method> globalDiagnoseRules = new ArrayList<>();
static {
initializeRules();
}
private static void initializeRules() {
Method[] methods = GlobalDiagnoser.class.getDeclaredMethods();
for (Method method : methods) {
if (method.getAnnotation(GlobalDiagnoseRule.class) != null) {
method.setAccessible(true);
int mod = method.getModifiers();
if (Modifier.isAbstract(mod) || Modifier.isFinal(mod) ||
!(Modifier.isPublic(mod) || Modifier.isProtected(mod))) {
throw new JifaException("Illegal method modifier: " + method);
}
globalDiagnoseRules.add(method);
}
}
}
@GlobalDiagnoseRule
protected void longGCPause() {
model.iterateEventsWithinTimeRange(model.getAllEvents(), config.getTimeRange(), event -> {
event.pauseEventOrPhasesDo(pauseEvent -> {
if (pauseEvent.getPause() <= config.getLongPauseThreshold()) {
return;
}
if (pauseEvent.isYoungGC()) {
addAbnormalPoint(new AbnormalPoint(LONG_YOUNG_GC_PAUSE, pauseEvent));
}
});
});
}
@GlobalDiagnoseRule
protected void allocationStall() {
if (model.getCollectorType() != GCCollectorType.ZGC) {
return;
}
ZGCModel zModel = (ZGCModel) model;
model.iterateEventsWithinTimeRange(zModel.getAllocationStalls(), config.getTimeRange(), stall -> {
addAbnormalPoint(new AbnormalPoint(ALLOCATION_STALL, stall));
});
}
@GlobalDiagnoseRule
protected void outOfMemory() {
model.iterateEventsWithinTimeRange(model.getOoms(), config.getTimeRange(), oom -> {
addAbnormalPoint(new AbnormalPoint(AbnormalType.OUT_OF_MEMORY, oom));
});
}
@GlobalDiagnoseRule
protected void longRemark() {
model.iterateEventsWithinTimeRange(model.getAllEvents(), config.getTimeRange(), remark -> {
GCEventType type = remark.getEventType();
if (remark.getPause() < config.getLongPauseThreshold()) {
return;
}
if (type == CMS_FINAL_REMARK) {
addAbnormalPoint(new AbnormalPoint(LONG_CMS_REMARK, remark));
} else if (type == G1_REMARK) {
addAbnormalPoint(new AbnormalPoint(LONG_G1_REMARK, remark));
}
});
}
@GlobalDiagnoseRule
protected void frequentYoungGC() {
DoubleData interval = new DoubleData();
model.iterateEventsWithinTimeRange(model.getGcEvents(), config.getTimeRange(), event -> {
if (event.isYoungGC() && event.getInterval() != UNKNOWN_DOUBLE) {
interval.add(event.getInterval());
}
});
if (interval.getN() > 0 && interval.average() < config.getYoungGCFrequentIntervalThreshold()) {
addAbnormalPoint(new AbnormalPoint(FREQUENT_YOUNG_GC, TimedEvent.fromTimeRange(config.getTimeRange())));
}
}
@GlobalDiagnoseRule
protected void fullGC() {
boolean shouldAvoidFullGC = model.shouldAvoidFullGC();
model.iterateEventsWithinTimeRange(model.getGcEvents(), config.getTimeRange(), event -> {
if (event.getEventType() != FULL_GC) {
return;
}
GCCause cause = event.getCause();
if (cause.isMetaspaceFullGCCause()) {
addAbnormalPoint(new AbnormalPoint(METASPACE_FULL_GC, event));
} else if (shouldAvoidFullGC && cause.isHeapMemoryTriggeredFullGCCause()) {
addAbnormalPoint(new AbnormalPoint(HEAP_MEMORY_FULL_GC, event));
} else if (cause == GCCause.SYSTEM_GC) {
addAbnormalPoint(new AbnormalPoint(AbnormalType.SYSTEM_GC, event));
}
});
}
private void addAbnormalPoint(AbnormalPoint point) {
allProblems.put(point.getType().getName(), point.getSite().getStartTime());
int compare = AbnormalPoint.compareByImportance.compare(point, mostSerious);
if (compare < 0) {
mostSeriousProblemList.clear();
mostSerious = point;
}
if (compare <= 0) {
mostSeriousProblemList.add(point);
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
private @interface GlobalDiagnoseRule {
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class GlobalAbnormalInfo {
private MostSeriousProblemSummary mostSeriousProblem;
private Map<String, List<Double>> seriousProblems;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public static class MostSeriousProblemSummary {
private List<TimeRange> sites;
private I18nStringView problem;
private List<I18nStringView> suggestions;
}
}
| 6,747 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/diagnoser/EventDiagnoseInfo.java | package org.eclipse.jifa.gclog.diagnoser;
import lombok.Data;
@Data
public class EventDiagnoseInfo {
private EventAbnormalSet abnormals = new EventAbnormalSet();
public EventDiagnoseInfo() {
}
}
| 6,748 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/GCLogAnalyzer.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import org.eclipse.jifa.common.JifaException;
import org.eclipse.jifa.common.listener.DefaultProgressListener;
import org.eclipse.jifa.common.listener.ProgressListener;
import org.eclipse.jifa.gclog.model.GCModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class GCLogAnalyzer {
private static final Logger LOGGER = LoggerFactory.getLogger(GCLogAnalyzer.class);
private File file;
private ProgressListener listener;
private final int MAX_SINGLE_LINE_LENGTH = 2048; // max length in hotspot
public GCLogAnalyzer(File file, ProgressListener listener) {
this.file = file;
this.listener = listener;
}
public GCLogAnalyzer(File file) {
this(file, new DefaultProgressListener());
}
public GCModel parse() throws Exception {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(file));
listener.beginTask("Paring " + file.getName(), 1000);
listener.sendUserMessage(ProgressListener.Level.INFO, "Deciding gc log format.", null);
// decide log format
GCLogParserFactory logParserFactory = new GCLogParserFactory();
br.mark(GCLogParserFactory.MAX_ATTEMPT_LINE * MAX_SINGLE_LINE_LENGTH);
GCLogParser parser = logParserFactory.getParser(br);
listener.worked(100);
try {
br.reset();
} catch (IOException e) {
// Recreate stream in case mark invalid. This is unlikely but possible when the log
// contains undesired characters
br.close();
br = new BufferedReader(new FileReader(file));
}
// read original info from log file
listener.sendUserMessage(ProgressListener.Level.INFO, "Parsing gc log file.", null);
GCModel model = parser.parse(br);
if (model.isEmpty()) {
throw new JifaException("Fail to parse gc log. Is this really a gc log?");
}
listener.worked(500);
// calculate derived info for query from original info
listener.sendUserMessage(ProgressListener.Level.INFO, "Calculating information from original data.", null);
model.calculateDerivedInfo(listener);
return model;
} catch (Exception e) {
LOGGER.info("fail to parse gclog {}: {}", file.getName(), e.getMessage());
throw e;
} finally {
if (br != null) {
br.close();
}
}
}
}
| 6,749 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/UnifiedG1GCLogParser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType;
import org.eclipse.jifa.gclog.model.G1GCModel;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.util.Constant;
import org.eclipse.jifa.gclog.util.GCLogUtil;
import java.util.ArrayList;
import java.util.List;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
import static org.eclipse.jifa.gclog.parser.ParseRule.*;
import static org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext.GCID;
import static org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext.UPTIME;
public class UnifiedG1GCLogParser extends UnifiedG1OrGenerationalGCLogParser {
private final static GCEventType[] YOUNG_MIXED = {YOUNG_GC, G1_MIXED_GC};
private final static GCEventType[] CONCURRENT_CYCLE_CPU_TIME_EVENTS = {
YOUNG_GC, G1_MIXED_GC, FULL_GC, G1_PAUSE_CLEANUP, G1_REMARK};
/*
* [0.001s][warning][gc] -XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead.
* [0.004s][info ][gc,heap] Heap region size: 1M
* [0.019s][info ][gc ] Using G1
* [0.019s][info ][gc,heap,coops] Heap address: 0x0000000095c00000, size: 1700 MB, Compressed Oops mode: 32-bit
* [0.050s][info ][gc ] Periodic GC disabled
*
* [0.751s][info][gc,start ] GC(0) Pause Young (Normal) (G1 Evacuation Pause)
* [0.752s][info][gc,task ] GC(0) Using 2 workers of 2 for evacuation
* [0.760s][info][gc,phases ] GC(0) Pre Evacuate Collection Set: 0.0ms
* [0.354s][info][gc,phases ] GC(0) Merge Heap Roots: 0.1ms
* [0.760s][info][gc,phases ] GC(0) Evacuate Collection Set: 5.9ms
* [0.760s][info][gc,phases ] GC(0) Post Evacuate Collection Set: 2.3ms
* [0.760s][info][gc,phases ] GC(0) Other: 0.3ms
* [0.760s][info][gc,heap ] GC(0) Eden regions: 6->0(5)
* [0.760s][info][gc,heap ] GC(0) Survivor regions: 0->1(1)
* [0.760s][info][gc,heap ] GC(0) Old regions: 0->0
* [0.760s][info][gc,heap ] GC(0) Humongous regions: 0->0
* [0.760s][info][gc,metaspace ] GC(0) Metaspace: 10707K->10707K(1058816K)
* [0.760s][info][gc ] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 96M->3M(2048M) 8.547ms
* [0.760s][info][gc,cpu ] GC(0) User=0.01s Sys=0.01s Real=0.01s
*
* [2.186s][info][gc ] GC(5) Concurrent Cycle
* [2.186s][info][gc ] GC(5) Concurrent Mark Cycle
* [2.186s][info][gc,marking ] GC(5) Concurrent Clear Claimed Marks
* [2.186s][info][gc,marking ] GC(5) Concurrent Clear Claimed Marks 0.016ms
* [2.186s][info][gc,marking ] GC(5) Concurrent Scan Root Regions
* [2.189s][info][gc,marking ] GC(5) Concurrent Scan Root Regions 3.214ms
* [2.189s][info][gc,marking ] GC(5) Concurrent Mark (2.189s)
* [2.189s][info][gc,marking ] GC(5) Concurrent Mark Reset For Overflow
* [2.189s][info][gc,marking ] GC(5) Concurrent Mark From Roots
* [2.190s][info][gc,task ] GC(5) Using 2 workers of 2 for marking
* [2.190s][info][gc,marking ] GC(5) Concurrent Mark From Roots 0.226ms
* [2.190s][info][gc,marking ] GC(5) Concurrent Preclean
* [2.190s][info][gc,marking ] GC(5) Concurrent Preclean 0.030ms
* [2.190s][info][gc,marking ] GC(5) Concurrent Mark (2.189s, 2.190s) 0.272ms
* [2.190s][info][gc,start ] GC(5) Pause Remark
* [2.193s][info][gc,stringtable] GC(5) Cleaned string and symbol table, strings: 10318 processed, 0 removed, symbols: 69242 processed, 330 removed
* [2.193s][info][gc ] GC(5) Pause Remark 14M->14M(2048M) 3.435ms
* [2.193s][info][gc,cpu ] GC(5) User=0.01s Sys=0.00s Real=0.00s
* [2.193s][info][gc,marking ] GC(5) Concurrent Rebuild Remembered Sets
* [2.193s][info][gc,marking ] GC(5) Concurrent Rebuild Remembered Sets 0.067ms
* [2.194s][info][gc,start ] GC(5) Pause Cleanup
* [2.194s][info][gc ] GC(5) Pause Cleanup 14M->14M(2048M) 0.067ms
* [2.194s][info][gc,cpu ] GC(5) User=0.00s Sys=0.00s Real=0.00s
* [2.194s][info][gc,marking ] GC(5) Concurrent Cleanup for Next Mark
* [2.217s][info][gc,marking ] GC(5) Concurrent Cleanup for Next Mark 23.105ms
* [2.217s][info][gc ] GC(5) Concurrent Cycle 30.799ms
*
* [6.845s][info][gc,task ] GC(26) Using 2 workers of 2 for full compaction
* [6.845s][info][gc,start ] GC(26) Pause Full (System.gc())
* [6.857s][info][gc,phases,start] GC(26) Phase 1: Mark live objects
* [6.907s][info][gc,stringtable ] GC(26) Cleaned string and symbol table, strings: 11395 processed, 5 removed, symbols: 69956 processed, 0 removed
* [6.907s][info][gc,phases ] GC(26) Phase 1: Mark live objects 49.532ms
* [6.907s][info][gc,phases,start] GC(26) Phase 2: Prepare for compaction
* [6.922s][info][gc,phases ] GC(26) Phase 2: Prepare for compaction 15.369ms
* [6.922s][info][gc,phases,start] GC(26) Phase 3: Adjust pointers
* [6.947s][info][gc,phases ] GC(26) Phase 3: Adjust pointers 25.161ms
* [6.947s][info][gc,phases,start] GC(26) Phase 4: Compact heap
* [6.963s][info][gc,phases ] GC(26) Phase 4: Compact heap 16.169ms
* [6.966s][info][gc,heap ] GC(26) Eden regions: 4->0(6)
* [6.966s][info][gc,heap ] GC(26) Survivor regions: 1->0(1)
* [6.966s][info][gc,heap ] GC(26) Old regions: 80->6
* [6.966s][info][gc,heap ] GC(26) Humongous regions: 2->2
* [6.966s][info][gc,metaspace ] GC(26) Metaspace: 22048K->22048K(1069056K)
* [6.966s][info][gc ] GC(26) Pause Full (System.gc()) 1368M->111M(2048M) 120.634ms
* [6.966s][info][gc,cpu ] GC(26) User=0.22s Sys=0.01s Real=0.12s
*
* [2.145s][info][gc ] GC(3) Concurrent Undo Cycle
* [2.145s][info][gc,marking ] GC(3) Concurrent Cleanup for Next Mark
* [2.145s][info][gc,marking ] GC(3) Concurrent Cleanup for Next Mark 0.109ms
* [2.145s][info][gc ] GC(3) Concurrent Undo Cycle 0.125ms
*/
private static List<ParseRule> withoutGCIDRules;
private static List<ParseRule> withGCIDRules;
static {
initializeParseRules();
}
private static void initializeParseRules() {
withoutGCIDRules = new ArrayList<>(getSharedWithoutGCIDRules());
withoutGCIDRules.add(new PrefixAndValueParseRule("Heap region size", UnifiedG1GCLogParser::parseHeapRegionSize));
withoutGCIDRules.add(new PrefixAndValueParseRule("Heap Region Size:", UnifiedG1GCLogParser::parseHeapRegionSize));
withGCIDRules = new ArrayList<>(getSharedWithGCIDRules());
withGCIDRules.add(new PrefixAndValueParseRule(" Pre Evacuate Collection Set", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule(" Merge Heap Roots", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule(" Evacuate Collection Set", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule(" Post Evacuate Collection Set", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule(" Other", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Cycle", UnifiedG1GCLogParser::parseConcurrentCycle));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Mark Cycle", UnifiedG1GCLogParser::parseConcurrentCycle));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Undo Cycle", UnifiedG1GCLogParser::parseConcurrentCycle));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Clear Claimed Marks", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Scan Root Regions", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Mark From Roots", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Mark", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Mark Reset For Overflow", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Preclean", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Pause Remark", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Rebuild Remembered Sets", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Pause Cleanup", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Cleanup for Next Mark", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Phase 1: Mark live objects", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Phase 2: Prepare for compaction", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Phase 3: Adjust pointers", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Phase 4: Compact heap", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new PrefixAndValueParseRule("Concurrent Mark Abort", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new FixedContentParseRule("To-space exhausted", UnifiedG1GCLogParser::parseToSpaceExhausted));
}
@Override
protected List<ParseRule> getWithoutGCIDRules() {
return withoutGCIDRules;
}
@Override
protected List<ParseRule> getWithGCIDRules() {
return withGCIDRules;
}
/*
* [2.145s][info][gc ] GC(3) Concurrent Undo Cycle
* [2.186s][info][gc ] GC(5) Concurrent Cycle
* [2.186s][info][gc ] GC(5) Concurrent Mark Cycle
*/
private static void parseConcurrentCycle(AbstractGCLogParser parser, ParseRuleContext context, String prefix, String value) {
GCModel model = parser.getModel();
GCEventType eventType = "Concurrent Undo Cycle".equals(prefix) ? G1_CONCURRENT_UNDO_CYCLE : G1_CONCURRENT_CYCLE;
boolean end = value.endsWith("ms");
GCEvent event;
if (!end || (event = model.getLastEventOfType(eventType)).getDuration() != Constant.UNKNOWN_DOUBLE) {
event = new GCEvent();
event.setStartTime(context.get(UPTIME));
event.setEventType(eventType);
event.setGcid(context.get(GCID));
model.putEvent(event);
}
parseCollectionAndDuration(event, context, value);
}
private static void parseHeapRegionSize(AbstractGCLogParser parser, ParseRuleContext context, String prefix, String value) {
G1GCModel model = (G1GCModel) parser.getModel();
model.setHeapRegionSize(GCLogUtil.toByte(value));
model.setRegionSizeExact(true);
}
private static void parseToSpaceExhausted(AbstractGCLogParser parser, ParseRuleContext context) {
GCModel model = parser.getModel();
GCEvent event = model.getLastEventOfType(YOUNG_MIXED);
if (event == null) {
// log may be incomplete
return;
}
event.setTrue(GCEventBooleanType.TO_SPACE_EXHAUSTED);
}
@Override
protected GCEvent getCPUTimeEventOrPhase(GCEvent event) {
if (event.getEventType() == YOUNG_GC || event.getEventType() == FULL_GC || event.getEventType() == G1_MIXED_GC) {
return event;
} else if (event.getEventType() == G1_CONCURRENT_CYCLE) {
return getModel().getLastEventOfType(CONCURRENT_CYCLE_CPU_TIME_EVENTS);
} else {
return null;
}
}
@Override
protected GCEventType getGCEventType(String eventString) {
switch (eventString) {
case "Pre Evacuate Collection Set":
return G1_COLLECT_PRE_EVACUATION;
case "Merge Heap Roots":
return G1_MERGE_HEAP_ROOTS;
case "Evacuate Collection Set":
return G1_COLLECT_EVACUATION;
case "Post Evacuate Collection Set":
return G1_COLLECT_POST_EVACUATION;
case "Other":
return G1_COLLECT_OTHER;
case "Concurrent Clear Claimed Marks":
return G1_CONCURRENT_CLEAR_CLAIMED_MARKS;
case "Concurrent Scan Root Regions":
return G1_CONCURRENT_SCAN_ROOT_REGIONS;
case "Concurrent Mark From Roots":
return G1_CONCURRENT_MARK_FROM_ROOTS;
case "Concurrent Mark":
return G1_CONCURRENT_MARK;
case "Concurrent Preclean":
return G1_CONCURRENT_PRECLEAN;
case "Pause Remark":
return G1_REMARK;
case "Concurrent Rebuild Remembered Sets":
return G1_CONCURRENT_REBUILD_REMEMBERED_SETS;
case "Pause Cleanup":
return G1_PAUSE_CLEANUP;
case "Concurrent Cleanup for Next Mark":
return G1_CONCURRENT_CLEANUP_FOR_NEXT_MARK;
case "Phase 1: Mark live objects":
return G1_MARK_LIVE_OBJECTS;
case "Phase 2: Prepare for compaction":
return G1_PREPARE_FOR_COMPACTION;
case "Phase 3: Adjust pointers":
return G1_ADJUST_POINTERS;
case "Phase 4: Compact heap":
return G1_COMPACT_HEAP;
case "Concurrent Mark Abort":
return G1_CONCURRENT_MARK_ABORT;
case "Concurrent Mark Reset For Overflow":
return G1_CONCURRENT_MARK_RESET_FOR_OVERFLOW;
default:
ErrorUtil.shouldNotReachHere();
}
return null;
}
}
| 6,750 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/UnifiedGenerationalGCLogParser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import java.util.ArrayList;
import java.util.List;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
public class UnifiedGenerationalGCLogParser extends UnifiedG1OrGenerationalGCLogParser {
private final static GCEventType[] CMS_CPU_TIME_EVENTS = {CMS_INITIAL_MARK, CMS_CONCURRENT_MARK,
CMS_CONCURRENT_PRECLEAN, CMS_FINAL_REMARK, CMS_CONCURRENT_SWEEP, CMS_CONCURRENT_RESET};
/*
* cms
* [0.276s][info ][gc,start ] GC(0) Pause Young (Allocation Failure)
* [0.276s][info ][gc,task ] GC(0) Using 8 workers of 8 for evacuation
* [0.278s][debug][gc,age ] GC(0) Desired survivor size 1114112 bytes, new threshold 1 (max threshold 6)
* [0.278s][info ][gc,heap ] GC(0) ParNew: 19277K->1969K(19648K)
* [0.278s][info ][gc,heap ] GC(0) CMS: 21564K->23127K(43712K)
* [0.278s][info ][gc,metaspace ] GC(0) Metaspace: 5319K->5319K(1056768K)
* [0.278s][info ][gc ] GC(0) Pause Young (Allocation Failure) 39M->24M(61M) 2.065ms
* [0.278s][info ][gc,cpu ] GC(0) User=0.00s Sys=0.00s Real=0.00s
* [1.017s][info ][gc,promotion ] Promotion failed
*
* [1.017s][info ][gc,start ] GC(1) Pause Full (Allocation Failure)
* [1.017s][info ][gc,phases,start] GC(1) Phase 1: Mark live objects
* [1.019s][info ][gc,phases ] GC(1) Phase 1: Mark live objects 1.788ms
* [1.019s][info ][gc,phases,start] GC(1) Phase 2: Compute new object addresses
* [1.020s][info ][gc,phases ] GC(1) Phase 2: Compute new object addresses 0.485ms
* [1.020s][info ][gc,phases,start] GC(1) Phase 3: Adjust pointers
* [1.021s][info ][gc,phases ] GC(1) Phase 3: Adjust pointers 1.138ms
* [1.021s][info ][gc,phases,start] GC(1) Phase 4: Move objects
* [1.022s][info ][gc,phases ] GC(1) Phase 4: Move objects 0.903ms
* [1.022s][info ][gc ] GC(1) Pause Full (Allocation Failure) 60M->3M(61M) 4.853ms
*
* [2.278s][info ][gc,start ] GC(2) Pause Initial Mark
* [2.279s][info ][gc ] GC(2) Pause Initial Mark 29M->29M(61M) 0.184ms
* [2.279s][info ][gc,cpu ] GC(2) User=0.00s Sys=0.00s Real=0.00s
* [2.279s][info ][gc ] GC(2) Concurrent Mark
* [2.279s][info ][gc,task ] GC(2) Using 2 workers of 2 for marking
* [2.280s][info ][gc ] GC(2) Concurrent Mark 1.553ms
* [2.280s][info ][gc,cpu ] GC(2) User=0.00s Sys=0.00s Real=0.00s
* [2.282s][info ][gc ] GC(2) Concurrent Preclean
* [2.282s][info ][gc ] GC(2) Concurrent Preclean 0.172ms
* [2.282s][info ][gc,cpu ] GC(2) User=0.00s Sys=0.00s Real=0.00s
* [2.283s][info ][gc,start ] GC(2) Pause Remark
* [2.284s][info ][gc ] GC(2) Pause Remark 26M->26M(61M) 1.736ms
* [2.284s][info ][gc,cpu ] GC(2) User=0.00s Sys=0.00s Real=0.01s
* [2.284s][info ][gc ] GC(2) Concurrent Sweep
* [2.285s][info ][gc ] GC(2) Concurrent Sweep 0.543ms
* [2.285s][info ][gc,cpu ] GC(2) User=0.00s Sys=0.00s Real=0.00s
* [2.285s][info ][gc ] GC(2) Concurrent Reset
* [2.285s][info ][gc ] GC(2) Concurrent Reset 0.323ms
* [2.285s][info ][gc,cpu ] GC(2) User=0.01s Sys=0.00s Real=0.00s
* [2.285s][info ][gc,heap ] GC(2) Old: 23127K->2019K(43712K)
* ----------------------------------------------------------------------
* parallel
* [0.020s][info][gc,start ] GC(0) Pause Young (Allocation Failure)
* [0.026s][info ][gc,heap ] GC(0) PSYoungGen: 16384K->2559K(18944K)
* [0.026s][info ][gc,heap ] GC(0) ParOldGen: 0K->2121K(44032K)
* [0.026s][info ][gc,metaspace ] GC(0) Metaspace: 15746K->15746K(1062912K)
* [0.026s][info ][gc ] GC(0) Pause Young (Allocation Failure) 16M->4M(61M) 5.423ms
* [0.026s][info ][gc,cpu ] GC(0) User=0.02s Sys=0.01s Real=0.00s
*
* [1.115s][info ][gc,start ] GC(1) Pause Full (Ergonomics)
* [1.116s][info ][gc,phases,start] GC(1) Marking Phase
* [1.120s][info ][gc,phases ] GC(1) Marking Phase 4.518ms
* [1.120s][info ][gc,phases,start] GC(1) Summary Phase
* [1.120s][info ][gc,phases ] GC(1) Summary Phase 0.013ms
* [1.120s][info ][gc,phases,start] GC(1) Adjust Roots
* [1.122s][info ][gc,phases ] GC(1) Adjust Roots 2.423ms
* [1.122s][info ][gc,phases,start] GC(1) Compaction Phase
* [1.128s][info ][gc,phases ] GC(1) Compaction Phase 5.461ms
* [1.128s][info ][gc,phases,start] GC(1) Post Compact
* [1.129s][info ][gc,phases ] GC(1) Post Compact 0.974ms
* [1.130s][info ][gc,heap ] GC(1) PSYoungGen: 13467K->0K(16896K)
* [1.130s][info ][gc,heap ] GC(1) ParOldGen: 42920K->7823K(26624K)
* [1.130s][info ][gc,metaspace ] GC(1) Metaspace: 15855K->15855K(1064960K)
* [1.130s][info ][gc ] GC(1) Pause Full (Ergonomics) 55M->7M(42M) 14.092ms
* [1.130s][info ][gc,cpu ] GC(1) User=0.04s Sys=0.00s Real=0.02s
* ----------------------------------------------------------------------
* serial
* [1.206s][info ][gc,start ] GC(0) Pause Young (Allocation Failure)
* [1.207s][info ][gc,heap ] GC(0) DefNew: 17950K->1955K(19648K)
* [1.207s][info ][gc,heap ] GC(0) Tenured: 6759K->6759K(43712K)
* [1.207s][info ][gc,metaspace ] GC(0) Metaspace: 16398K->16398K(1064960K)
* [1.207s][info ][gc ] GC(0) Pause Young (Allocation Failure) 24M->8M(61M) 0.508ms
* [1.207s][info ][gc,cpu ] GC(0) User=0.00s Sys=0.00s Real=0.00s
*
* [2.401s][info ][gc,start ] GC(1) Pause Full (Allocation Failure)
* [2.401s][info ][gc,phases,start] GC(1) Phase 1: Mark live objects
* [2.406s][info ][gc,phases ] GC(1) Phase 1: Mark live objects 5.032ms
* [2.406s][info ][gc,phases,start] GC(1) Phase 2: Compute new object addresses
* [2.407s][info ][gc,phases ] GC(1) Phase 2: Compute new object addresses 0.965ms
* [2.407s][info ][gc,phases,start] GC(1) Phase 3: Adjust pointers
* [2.412s][info ][gc,phases ] GC(1) Phase 3: Adjust pointers 4.156ms
* [2.412s][info ][gc,phases,start] GC(1) Phase 4: Move objects
* [2.412s][info ][gc,phases ] GC(1) Phase 4: Move objects 0.280ms
* [2.412s][info ][gc ] GC(1) Pause Full (Allocation Failure) 60M->6M(61M) 11.072ms
*/
private static List<ParseRule> withoutGCIDRules;
private static List<ParseRule> withGCIDRules;
static {
initializeParseRules();
}
private static void initializeParseRules() {
withoutGCIDRules = new ArrayList<>(getSharedWithoutGCIDRules());
withGCIDRules = new ArrayList<>(getSharedWithGCIDRules());
withGCIDRules.add(new ParseRule.FixedContentParseRule("Promotion failed", UnifiedGenerationalGCLogParser::parsePromotionFailed));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Phase 1: Mark live objects", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Phase 2: Compute new object addresses", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Phase 3: Adjust pointers", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Phase 4: Move objects", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Pause Initial Mark", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Concurrent Mark", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Concurrent Preclean", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Pause Remark", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Concurrent Sweep", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Concurrent Reset", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Marking Phase", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Summary Phase", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Adjust Roots", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Compaction Phase", UnifiedG1OrGenerationalGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Post Compact", UnifiedG1OrGenerationalGCLogParser::parsePhase));
}
@Override
protected List<ParseRule> getWithoutGCIDRules() {
return withoutGCIDRules;
}
@Override
protected List<ParseRule> getWithGCIDRules() {
return withGCIDRules;
}
private static void parsePromotionFailed(AbstractGCLogParser parser, ParseRule.ParseRuleContext context) {
GCModel model = parser.getModel();
GCEvent event = model.getLastEventOfType(YOUNG_GC);
if (event == null) {
return;
}
event.setTrue(GCEventBooleanType.PROMOTION_FAILED);
}
@Override
protected GCEvent getCPUTimeEventOrPhase(GCEvent event) {
if (event.getEventType() == YOUNG_GC || event.getEventType() == FULL_GC) {
return event;
} else if (event.getEventType() == CMS_CONCURRENT_MARK_SWEPT) {
return getModel().getLastEventOfType(CMS_CPU_TIME_EVENTS);
} else {
return null;
}
}
@Override
protected GCEventType getGCEventType(String eventString) {
switch (eventString) {
case "Phase 1: Mark live objects":
return SERIAL_MARK_LIFE_OBJECTS;
case "Phase 2: Compute new object addresses":
return SERIAL_COMPUTE_NEW_OBJECT_ADDRESSES;
case "Phase 3: Adjust pointers":
return SERIAL_ADJUST_POINTERS;
case "Phase 4: Move objects":
return SERIAL_MOVE_OBJECTS;
case "Pause Initial Mark":
return CMS_INITIAL_MARK;
case "Concurrent Mark":
return CMS_CONCURRENT_MARK;
case "Concurrent Preclean":
return CMS_CONCURRENT_PRECLEAN;
case "Pause Remark":
return CMS_FINAL_REMARK;
case "Concurrent Sweep":
return CMS_CONCURRENT_SWEEP;
case "Concurrent Reset":
return CMS_CONCURRENT_RESET;
case "Marking Phase":
return PARALLEL_PHASE_MARKING;
case "Summary Phase":
return PARALLEL_PHASE_SUMMARY;
case "Adjust Roots":
return PARALLEL_PHASE_ADJUST_ROOTS;
case "Compaction Phase":
return PARALLEL_PHASE_COMPACTION;
case "Post Compact":
return PARALLEL_PHASE_POST_COMPACT;
default:
ErrorUtil.shouldNotReachHere();
}
return null;
}
}
| 6,751 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/UnifiedG1OrGenerationalGCLogParser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.*;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext;
import org.eclipse.jifa.gclog.parser.ParseRule.PrefixAndValueParseRule;
import org.eclipse.jifa.gclog.util.Constant;
import org.eclipse.jifa.gclog.util.GCLogUtil;
import java.util.ArrayList;
import java.util.List;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
import static org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext.GCID;
import static org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext.UPTIME;
public abstract class UnifiedG1OrGenerationalGCLogParser extends AbstractUnifiedGCLogParser {
private static List<ParseRule> withoutGCIDRules;
private static List<ParseRule> withGCIDRules;
public static List<ParseRule> getSharedWithoutGCIDRules() {
return withoutGCIDRules;
}
public static List<ParseRule> getSharedWithGCIDRules() {
return withGCIDRules;
}
static {
initializeParseRules();
}
private static void initializeParseRules() {
withoutGCIDRules = new ArrayList<>(AbstractUnifiedGCLogParser.getSharedWithoutGCIDRules());
withGCIDRules = new ArrayList<>(AbstractUnifiedGCLogParser.getSharedWithGCIDRules());
withGCIDRules.add(new PrefixAndValueParseRule("Metaspace:", UnifiedG1OrGenerationalGCLogParser::parseMetaspace));
withGCIDRules.add(UnifiedG1OrGenerationalGCLogParser::parseHeap);
withGCIDRules.add(new PrefixAndValueParseRule("Pause Young", UnifiedG1OrGenerationalGCLogParser::parseYoungFullGC));
withGCIDRules.add(new PrefixAndValueParseRule("Pause Full", UnifiedG1OrGenerationalGCLogParser::parseYoungFullGC));
withGCIDRules.add(UnifiedG1OrGenerationalGCLogParser::parseWorker);
withGCIDRules.add(UnifiedG1OrGenerationalGCLogParser::parseCpuTime);
// subclass will add more rules
}
protected abstract List<ParseRule> getWithoutGCIDRules();
protected abstract List<ParseRule> getWithGCIDRules();
private static boolean parseCpuTime(AbstractGCLogParser parser, ParseRuleContext context, String text) {
GCModel model = parser.getModel();
//[0.524s][info ][gc,cpu ] GC(0) User=22.22s Sys=23.23s Real=24.24s
if (!text.startsWith("User=") || !text.endsWith("s")) {
return false;
}
CpuTime cpuTime = GCLogUtil.parseCPUTime(text);
GCEvent event = model.getLastEventOfGCID(context.get(GCID));
if (event != null) {
event = ((UnifiedG1OrGenerationalGCLogParser) parser).getCPUTimeEventOrPhase(event);
if (event != null) {
event.setCpuTime(cpuTime);
}
}
return true;
}
protected abstract GCEvent getCPUTimeEventOrPhase(GCEvent event);
@Override
protected final void doParseLineWithoutGCID(String detail, double uptime) {
ParseRuleContext context = new ParseRuleContext();
context.put(UPTIME, uptime);
doParseUsingRules(this, context, detail, getWithoutGCIDRules());
}
@Override
protected final void doParseLineWithGCID(String detail, int gcid, double uptime) {
ParseRuleContext context = new ParseRuleContext();
context.put(UPTIME, uptime);
context.put(GCID, gcid);
doParseUsingRules(this, context, detail, getWithGCIDRules());
}
/**
* for reference
* [0.501s][info ][gc,start ] GC(0) Pause Young (Normal) (G1 Evacuation Pause)
* [0.524s][info ][gc ] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 18M->19M(20M) 21.21ms
* [6.845s][info][gc,start ] GC(26) Pause Full (System.gc())
* [0.276s][info ][gc,start ] GC(34) Pause Young (Allocation Failure)
* [10.115s][info ][gc,start ] GC(25) Pause Full (Ergonomics)
* [15.732s][info][gc,start ] GC(42) Pause Young (Mixed) (G1 Evacuation Pause)
* [56.810s][info][gc,start ] GC(33) Pause Young (Concurrent Start) (GCLocker Initiated GC)
*/
private static void parseYoungFullGC(AbstractGCLogParser parser, ParseRuleContext context, String title, String text) {
GCModel model = parser.getModel();
String[] parts = GCLogUtil.splitByBracket(text);
int causeIndex = 0;
GCEventType eventType = title.endsWith("Young") ? YOUNG_GC : FULL_GC;
GCEventBooleanType specialSituation = null;
if (parser.getMetadata().getCollector() == GCCollectorType.G1 && eventType == YOUNG_GC) {
switch (parts[0]) {
case "Concurrent Start":
specialSituation = GCEventBooleanType.INITIAL_MARK;
break;
case "Prepare Mixed":
specialSituation = GCEventBooleanType.PREPARE_MIXED;
break;
case "Mixed":
eventType = G1_MIXED_GC;
break;
}
causeIndex++;
}
GCCause cause = GCCause.getCause(parts[causeIndex]);
boolean end = text.endsWith("ms");
GCEvent event;
if (!end || (event = model.getLastEventOfGCID(context.get(GCID))) == null) {
event = new GCEvent();
event.setStartTime(context.get(UPTIME));
event.setEventType(eventType);
event.setCause(cause);
if (cause == GCCause.CMS_FINAL_REMARK) {
event.setTrue(GCEventBooleanType.IGNORE_PAUSE);
}
if (specialSituation != null) {
event.setTrue(specialSituation);
}
event.setGcid(context.get(GCID));
model.putEvent(event);
}
if (end) {
int tailBegin = text.lastIndexOf(' ');
tailBegin = text.lastIndexOf(' ', tailBegin - 1);
if (tailBegin > 0) {
parseCollectionAndDuration(event, context, text.substring(tailBegin + 1));
}
}
}
// 18M->19M(20M) 21.21ms
protected static void parseCollectionAndDuration(GCEvent event, ParseRuleContext context, String s) {
if (StringUtils.isBlank(s)) {
return;
}
for (String part : s.split(" ")) {
if (part.contains("->") && part.endsWith(")") && !part.startsWith("(")) {
long[] memories = GCLogUtil.parseMemorySizeFromTo(part);
GCMemoryItem item = new GCMemoryItem(MemoryArea.HEAP, memories);
event.setMemoryItem(item);
} else if (part.endsWith("ms")) {
double duration = GCLogUtil.toMillisecond(part);
event.setDuration(duration);
if (event.getStartTime() == Constant.UNKNOWN_DOUBLE) {
event.setStartTime((double) context.get(UPTIME) - duration);
}
}
}
}
/**
* [0.524s][info ][gc,heap ] GC(0) Eden regions: 5->6(7)
* [0.524s][info ][gc,heap ] GC(0) Survivor regions: 8->9(10)
* [0.524s][info ][gc,heap ] GC(0) Old regions: 11->12
* [0.524s][info ][gc,heap ] GC(0) Humongous regions: 13->14
* [1.738s][info][gc,heap ] GC(2) Archive regions: 2->2
* [0.524s][info ][gc,metaspace ] GC(0) Metaspace: 15K->16K(17K)
* [2.285s][info ][gc,heap ] GC(2) Old: 23127K->2019K(43712K)
* [0.160s][info ][gc,heap ] GC(0) ParNew: 17393K->2175K(19648K)
* [0.160s][info ][gc,heap ] GC(0) CMS: 0K->130K(43712K)
* [0.194s][info][gc,heap ] GC(0) DefNew: 40960K(46080K)->5120K(46080K) Eden: 40960K(40960K)->0K(40960K) From: 0K(5120K)->5120K(5120K)
* [0.569s][info][gc,heap ] GC(1) PSYoungGen: 6128K(45056K)->0K(45056K) Eden: 0K(38912K)->0K(38912K) From: 6128K(6144K)->0K(6144K)
*/
private static boolean parseHeap(AbstractGCLogParser parser, ParseRuleContext context, String s) {
GCModel model = parser.getModel();
String[] parts = GCLogUtil.splitBySpace(s);
if (parts.length != 2 && parts.length != 3 && parts.length != 6) {
return false;
}
String generationName = parts[0];
if (generationName.endsWith(":")) {
generationName = generationName.substring(0, generationName.length() - 1);
}
MemoryArea generation = MemoryArea.getMemoryArea(generationName);
if (generation == null) {
return false;
}
// format check done
GCEvent event = model.getLastEventOfGCID(context.get(GCID));
if (event == null) {
// log may be incomplete
return true;
}
if (event.getEventType() == CMS_CONCURRENT_MARK_SWEPT) {
event = event.getLastPhaseOfType(CMS_CONCURRENT_SWEEP);
if (event == null) {
return true;
}
}
long[] memories = GCLogUtil.parseMemorySizeFromTo(parts.length == 3 ? parts[2] :parts[1], 1);
// will multiply region size before calculating derived info for g1
GCMemoryItem item = new GCMemoryItem(generation, memories);
event.setMemoryItem(item);
if (parts.length == 6) {
event.setMemoryItem(new GCMemoryItem(MemoryArea.EDEN, GCLogUtil.parseMemorySizeFromTo(parts[3])));
event.setMemoryItem(new GCMemoryItem(MemoryArea.SURVIVOR, GCLogUtil.parseMemorySizeFromTo(parts[5])));
}
return true;
}
/*
* [0.160s][info ][gc,metaspace ] GC(0) Metaspace: 5147K->5147K(1056768K)
* [0.194s][info][gc,metaspace] GC(0) Metaspace: 137K(384K)->138K(384K) NonClass: 133K(256K)->133K(256K) Class: 4K(128K)->4K(128K)
*/
private static void parseMetaspace(AbstractGCLogParser parser, ParseRuleContext context, String title, String text) {
GCModel model = parser.getModel();
GCEvent event = model.getLastEventOfGCID(context.get(GCID));
if (event == null) {
// log may be incomplete
return;
}
String[] parts = GCLogUtil.splitBySpace(text);
event.setMemoryItem(new GCMemoryItem(MemoryArea.METASPACE, GCLogUtil.parseMemorySizeFromTo(parts[0])));
if (parts.length == 5) {
model.setMetaspaceCapacityReliable(true);
event.setMemoryItem(new GCMemoryItem(MemoryArea.NONCLASS, GCLogUtil.parseMemorySizeFromTo(parts[2])));
event.setMemoryItem(new GCMemoryItem(MemoryArea.CLASS, GCLogUtil.parseMemorySizeFromTo(parts[4])));
}
}
/**
* e.g.
* [2.983s][info ][gc,marking ] GC(1) Concurrent Clear Claimed Marks
* [2.983s][info ][gc,marking ] GC(1) Concurrent Clear Claimed Marks 25.25ms
* [3.266s][info ][gc,phases ] GC(2) Phase 1: Mark live objects 50.50ms
* [3.002s][info ][gc ] GC(1) Pause Cleanup 1480M->1480M(1700M) 41.41ms
* <p>
* two cases of phases in gclog: one line summary , two lines of begin and end
*/
protected static void parsePhase(AbstractGCLogParser parser, ParseRuleContext context, String phaseName, String value) {
GCModel model = parser.getModel();
phaseName = phaseName.trim();
GCEventType phaseType = ((UnifiedG1OrGenerationalGCLogParser) parser).getGCEventType(phaseName);
boolean end = value.endsWith("ms");
GCEvent event;
// cms does not have a line to indicate its beginning, hard code here
if (parser.getMetadata().getCollector() == GCCollectorType.CMS &&
phaseType == CMS_INITIAL_MARK && !end) {
event = new GCEvent();
event.setEventType(CMS_CONCURRENT_MARK_SWEPT);
event.setStartTime(context.get(UPTIME));
event.setGcid(context.get(GCID));
model.putEvent(event);
} else {
event = model.getLastEventOfGCID(context.get(GCID));
}
if (event == null) {
// log may be incomplete
return;
}
GCEvent phase = event.getLastPhaseOfType(phaseType);
if (phase == null) {
phase = new GCEvent();
phase.setEventType(phaseType);
phase.setGcid(context.get(GCID));
phase.setStartTime(context.get(UPTIME));
if (phaseType == G1_CONCURRENT_MARK_ABORT || phaseType == G1_CONCURRENT_MARK_RESET_FOR_OVERFLOW ||
phaseType == CMS_CONCURRENT_INTERRUPTED || phaseType == CMS_CONCURRENT_FAILURE) {
phase.setDuration(0);
}
model.addPhase(event, phase);
}
parseCollectionAndDuration(phase, context, value);
}
//[0.502s][info ][gc,task ] GC(0) Using 8 workers of 8 for evacuation
//[2.984s][info ][gc,task ] GC(1) Using 2 workers of 2 for marking
private static boolean parseWorker(AbstractGCLogParser parser, ParseRuleContext context, String text) {
GCModel model = parser.getModel();
String[] parts = GCLogUtil.splitBySpace(text);
if (parts.length >= 7 && "Using".equals(parts[0]) && "workers".equals(parts[2])) {
if ("evacuation".equals(parts[6])) {
model.setParallelThread(Integer.parseInt(parts[4]));
} else if ("marking".equals(parts[6])) {
model.setConcurrentThread(Integer.parseInt(parts[4]));
}
return true;
}
return false;
}
protected abstract GCEventType getGCEventType(String eventString);
}
| 6,752 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/AbstractPreUnifiedGCLogParser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import lombok.Data;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea;
import org.eclipse.jifa.gclog.event.evnetInfo.CpuTime;
import org.eclipse.jifa.gclog.event.evnetInfo.GCMemoryItem;
import org.eclipse.jifa.gclog.event.evnetInfo.ReferenceGC;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.model.modeInfo.VmOptions;
import org.eclipse.jifa.gclog.parser.ParseRule.PrefixAndValueParseRule;
import org.eclipse.jifa.gclog.util.Constant;
import org.eclipse.jifa.gclog.util.GCLogUtil;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static org.eclipse.jifa.gclog.util.Constant.*;
/*
* We mainly consider -XX:+PrintGCDetails. -XX:+PrintReferenceGC and -XX:+PrintApplicationStopTime are also considered
* because they are commonly used, and they will greatly affect parsing. We will continue support for cases in the future.
*/
public abstract class AbstractPreUnifiedGCLogParser extends AbstractGCLogParser {
private LinkedList<List<GCLogToken>> sentenceToParseQueue = new LinkedList<>();
private LinkedList<List<GCLogToken>> sentenceToAssembleStack = new LinkedList<>();
private final static String[] FULL_LINE_PREFIXES = Arrays.stream(new String[]{
"CommandLine flags: ",
"OpenJDK",
"Memory:",
" [Parallel Time",
" [GC Worker Start (ms)",
" [Ext Root Scanning (ms)",
" [Update RS (ms)",
" [Processed Buffers",
" [Scan RS (ms)",
" [Code Root Scanning (ms)",
" [Object Copy (ms)",
" [Termination (ms)",
" [Termination Attempts",
" [GC Worker Other (ms)",
" [GC Worker Total (ms)",
" [GC Worker End (ms)",
" [Code Root Fixup",
" [Code Root Purge",
" [Clear CT",
" [Other",
" [Evacuation Failure",
" [Choose CSet",
" [Ref Proc",
" [Ref Enq",
" [Redirty Cards",
" [Humongous Register",
" [Humongous Reclaim",
" [Free CSet",
" [Eden",
}).sorted(Comparator.reverseOrder()).toArray(String[]::new);
private static final String[] TRACETIME_GC_START_TITLES = Arrays.stream(new String[]{
"GC pause",
"GC",
"Full GC",
}).sorted(Comparator.reverseOrder()).toArray(String[]::new);
private static final String[] TRACETIME_GENERATION_TITLES = Arrays.stream(new String[]{
"ParNew",
"ASParNew",
"DefNew",
"PSYoungGen",
"PSOldGen",
"ParOldGen",
"Tenured",
"CMS",
"ASCMS",
}).sorted(Comparator.reverseOrder()).toArray(String[]::new);
private static final String[] TRACETIME_OTHER_TITLES = Arrays.stream(new String[]{
"CMS-concurrent-mark-start",
"CMS-concurrent-mark",
"CMS-concurrent-preclean-start",
"CMS-concurrent-preclean",
"CMS-concurrent-abortable-preclean-start",
"CMS-concurrent-abortable-preclean",
"CMS-concurrent-sweep-start",
"CMS-concurrent-sweep",
"CMS-concurrent-reset-start",
"CMS-concurrent-reset",
"Rescan (parallel) ",
"Rescan (non-parallel) ",
"CMS:MSC ",
"grey object rescan",
"root rescan",
"visit unhandled CLDs",
"dirty klass scan",
"weak refs processing",
"class unloading",
"scrub symbol table",
"scrub string table",
"Verify After",
"Verify Before",
"GC ref-proc",
"phase 1",
"phase 2",
"phase 3",
"phase 4",
"adjust roots",
"compaction phase",
"par compact",
"deferred updates",
"dense prefix task setup",
"drain task setup",
"steal task setup",
"marking phase",
"par mark",
"reference processing",
"post compact",
"pre compact",
"summary phase",
"Scavenge",
"References",
"StringTable",
"Heap Dump (after full gc): ",
"Class Histogram (after full gc): ",
"Heap Dump (before full gc): ",
"Class Histogram (before full gc): ",
"per-gen-adjust",
"marking",
"ref processing",
"adjust-strong-roots",
"adjust-weak-roots",
"adjust-preserved-marks",
"adjust-heap",
"Preclean SoftReferences",
"Preclean WeakReferences",
"Preclean FinalReferences",
"Preclean PhantomReferences",
"SoftReference",
"WeakReference",
"FinalReference",
"PhantomReference",
"JNI Weak Reference",
"par-adjust-pointers",
"GC concurrent-root-region-scan-start",
"GC concurrent-root-region-scan-end",
"GC concurrent-mark-start",
"GC concurrent-mark-end",
"GC concurrent-mark-reset-for-overflow",
"GC concurrent-mark-abort",
"GC remark ",
"Finalize Marking",
"GC ref-proc",
"Unloading",
"GC cleanup",
"GC concurrent-cleanup-start",
"GC concurrent-cleanup-end"
}).sorted(Comparator.reverseOrder()).toArray(String[]::new);
private static final String[][] EMBEDDED_SENTENCE_BEGIN_END = {
{"[1 CMS-", ")]"},
{"[YG occupancy: ", "]"},
{" CMS: abort preclean due to time ", null},
{" CMS: abort preclean due to loop ", null},
{" (promotion failed) ", null},
{" (promotion failed)", null},
{" (concurrent mode failure)", null},
{" (to-space exhausted)", null},
{" [Times", "]"}
};
private static final String[] EMBEDDED_SENTENCE_WITH_BRACKET = Arrays.stream(EMBEDDED_SENTENCE_BEGIN_END)
.filter(beginEnd -> {
if (beginEnd[1] == null) {
return beginEnd[0].startsWith(" (") && beginEnd[0].endsWith(")");
} else {
return beginEnd[0].startsWith(" (") && beginEnd[1].endsWith(")");
}
})
.map(begin_end -> begin_end[0])
.toArray(String[]::new);
/*
* In preunified gclogs a sentence may insert into another sentence and this makes parsing difficult. Overall,
* there are two types of sentences:
* (1) Each sentence is consist of two parts like: "datestamp/timestamp: [action" + "heap change, duration]"
* (2) The sentence is printed simultaneously, and there is no common datestamp or timestamp
* We will first reassemble original gclog text into lines like this, and then do actual parsing work.
* for example
* 2021-11-24T23:23:44.225-0800: 796.991: [GC (Allocation Failure) 2021-11-24T23:23:44.225-0800: 796.992: [ParNew: 1922432K->1922432K(1922432K), 0.0000267 secs]2021-11-24T23:23:44.226-0800: 796.992: [CMS2021-11-24T23:23:45.066-0800: 797.832: [CMS-concurrent-sweep: 1.180/1.376 secs] [Times: user=3.42 sys=0.14, real=1.38 secs]
* (concurrent mode failure): 2034154K->1051300K(2097152K), 4.6146919 secs] 3956586K->1051300K(4019584K), [Metaspace: 296232K->296083K(1325056K)], 4.6165192 secs] [Times: user=4.60 sys=0.05, real=4.62 secs]
* will be transformed into
* 2021-11-24T23:23:44.225-0800: 796.991: [GC (Allocation Failure) 3956586K->1051300K(4019584K), [Metaspace: 296232K->296083K(1325056K)], 4.6165192 secs] [Times: user=4.60 sys=0.05, real=4.62 secs]
* 2021-11-24T23:23:44.225-0800: 796.992: [ParNew: 1922432K->1922432K(1922432K), 0.0000267 secs]
* 2021-11-24T23:23:44.226-0800: 796.992: [CMS: 2034154K->1051300K(2097152K), 4.6146919 secs]
* 2021-11-24T23:23:45.066-0800: 797.832: [CMS-concurrent-sweep: 1.180/1.376 secs] [Times: user=3.42 sys=0.14, real=1.38 secs]
* (concurrent mode failure)
*
*/
@Override
protected final void doParseLine(String line) {
new LineAssembler(this, line).doAssemble();
if (sentenceToAssembleStack.isEmpty()) {
while (!sentenceToParseQueue.isEmpty()) {
doParseSentence(pollSentenceToParse());
}
}
}
private void doParseSentence(List<GCLogToken> line) {
try {
GCEvent event = new GCEvent();
String title = null;
String referenceGC = null;
String datestamp = null;
for (GCLogToken token : line) {
if (token.getType() == TOKEN_LINE_FULL_SENTENCE || token.getType() == TOKEN_EMBEDDED_SENTENCE) {
doParseFullSentence(token.getValue());
return;
} else if (token.getType() == TOKEN_DATESTAMP) {
datestamp = token.getValue();
} else if (token.getType() == TOKEN_UPTIME) {
event.setStartTime(MS2S * Double.parseDouble(token.getValue()));
} else if (token.getType() == TOKEN_GCID) {
event.setGcid(Integer.parseInt(token.getValue()));
} else if (token.getType() == TOKEN_GC_TRACETIME_TITLE) {
// title is complex, it may include event name, gc cause, generation or something else.
// let subclass parse it
title = token.getValue();
} else if (token.getType() == TOKEN_SAFEPOINT) {
if (doBeforeParsingGCTraceTime(event, datestamp)) {
doParseSafePoint(event, token.getValue());
}
return;
} else if (token.getType() == TOKEN_MEMORY_CHANGE) {
long[] memories = GCLogUtil.parseMemorySizeFromTo(token.getValue(), (int) KB2MB);
GCMemoryItem item = new GCMemoryItem(MemoryArea.HEAP, memories);
event.setMemoryItem(item);
} else if (token.getType() == TOKEN_REFERENCE_GC) {
referenceGC = token.getValue();
} else if (token.getType() == TOKEN_DURATION) {
event.setDuration(MS2S * Double.parseDouble(token.getValue()));
} else if (token.getType() == TOKEN_METASPACE) {
long[] memories = GCLogUtil.parseMemorySizeFromTo(token.getValue(), (int) KB2MB);
GCMemoryItem item = new GCMemoryItem(MemoryArea.METASPACE, memories);
event.setMemoryItem(item);
} else if (token.getType() == TOKEN_RIGHT_BRACKET) {
// do nothing
} else {
ErrorUtil.shouldNotReachHere();
}
}
// jni weak does not print reference count
if (referenceGC != null || "JNI Weak Reference".equals(title)) {
if (doBeforeParsingGCTraceTime(event, datestamp)) {
doParseReferenceGC(event, title, referenceGC);
}
} else if (title != null) {
if (doBeforeParsingGCTraceTime(event, datestamp)) {
doParseGCTraceTime(event, title);
}
}
} catch (Exception e) {
LOGGER.debug(e.getMessage());
}
}
protected abstract void doParseFullSentence(String sentence);
protected abstract void doParseGCTraceTime(GCEvent event, String title);
// subclass should tell which event this reference gc belongs to
protected abstract GCEvent getReferenceGCEvent();
// subclass should tell which event this cputime belongs to
protected abstract List<GCEventType> getCPUTimeGCEvent();
// 0.231: Total time for which application threads were stopped: 0.0001215 seconds, Stopping threads took: 0.0000271 seconds
private void doParseSafePoint(GCEvent event, String s) {
if (!s.startsWith("Total time for which application")) {
return;
}
parseSafepointStop(event.getStartTime(), s);
}
// "123 refs"
// "123 refs, 234 refs"
private void doParseReferenceGC(GCEvent event, String title, String referenceGCString) {
GCEvent referenceGCEvent = getReferenceGCEvent();
if (referenceGCEvent == null) {
return;
}
ReferenceGC referenceGC = referenceGCEvent.getReferenceGC();
if (referenceGC == null) {
referenceGC = new ReferenceGC();
referenceGCEvent.setReferenceGC(referenceGC);
}
List<Integer> counts = null;
if (referenceGCString != null) {
counts = Arrays.stream(referenceGCString.split(", "))
.map(s -> Integer.parseInt(s.substring(0, s.length() - " refs".length())))
.collect(Collectors.toList());
}
switch (title) {
case "SoftReference":
referenceGC.setSoftReferencePauseTime(event.getDuration());
referenceGC.setSoftReferenceStartTime(event.getStartTime());
referenceGC.setSoftReferenceCount(counts.get(0));
break;
case "WeakReference":
referenceGC.setWeakReferencePauseTime(event.getDuration());
referenceGC.setWeakReferenceStartTime(event.getStartTime());
referenceGC.setWeakReferenceCount(counts.get(0));
break;
case "FinalReference":
referenceGC.setFinalReferencePauseTime(event.getDuration());
referenceGC.setFinalReferenceStartTime(event.getStartTime());
referenceGC.setFinalReferenceCount(counts.get(0));
break;
case "PhantomReference":
referenceGC.setPhantomReferencePauseTime(event.getDuration());
referenceGC.setPhantomReferenceStartTime(event.getStartTime());
referenceGC.setPhantomReferenceCount(counts.get(0));
if (counts.size() > 1) {
referenceGC.setPhantomReferenceFreedCount(counts.get(1));
}
break;
case "JNI Weak Reference":
referenceGC.setJniWeakReferencePauseTime(event.getDuration());
referenceGC.setJniWeakReferenceStartTime(event.getStartTime());
break;
default:
ErrorUtil.shouldNotReachHere();
}
}
private double lastUptime = UNKNOWN_DOUBLE;
private boolean doBeforeParsingGCTraceTime(GCEvent event, String datestampString) {
double timestamp = UNKNOWN_DOUBLE;
double uptime = event.getStartTime();
GCModel model = getModel();
// set model reference timestamp
if (model.getReferenceTimestamp() == UNKNOWN_DOUBLE && datestampString != null) {
// parsing timestamp is expensive, do it lazily
timestamp = GCLogUtil.parseDateStamp(datestampString);
double startTimestamp = uptime == UNKNOWN_DOUBLE ? timestamp : timestamp - uptime;
model.setReferenceTimestamp(startTimestamp);
}
// set event start time
if (event.getStartTime() == UNKNOWN_DOUBLE) {
if (datestampString != null && model.getReferenceTimestamp() != UNKNOWN_DOUBLE) {
if (timestamp == UNKNOWN_DOUBLE) {
timestamp = GCLogUtil.parseDateStamp(datestampString);
}
uptime = timestamp - model.getReferenceTimestamp();
} else {
// HACK: There may be rare concurrency issue in printing uptime and datestamp when two threads
// are printing simultaneously and this may lead to problem in parsing. Copy the uptime from
// the last known uptime.
uptime = lastUptime;
}
event.setStartTime(uptime);
}
if (event.getStartTime() == UNKNOWN_DOUBLE) {
// we have no way to know uptime
return false;
} else {
lastUptime = event.getStartTime();
}
// set model start and end time
if (model.getStartTime() == UNKNOWN_DOUBLE) {
model.setStartTime(uptime);
}
model.setEndTime(Math.max(uptime, model.getEndTime()));
return true;
}
private void pushSentenceToAssemble(List<GCLogToken> sentence) {
sentenceToAssembleStack.offerLast(sentence);
}
private List<GCLogToken> pollSentenceToAssemble() {
return sentenceToAssembleStack.pollLast();
}
private void pushSentenceToParse(List<GCLogToken> sentence) {
sentenceToParseQueue.offerLast(sentence);
}
private List<GCLogToken> pollSentenceToParse() {
return sentenceToParseQueue.pollFirst();
}
private interface GCLogTokenType {
// for efficiency, sometimes we do not check strictly
GCLogToken parseNextToken(String line, int index, AbstractPreUnifiedGCLogParser parser);
}
@Override
protected void endParsing() {
// maybe we have met some mistake, try to flush any sentence that may be valid
while (!sentenceToParseQueue.isEmpty()) {
List<GCLogToken> line = pollSentenceToParse();
if (sentenceIsValid(line)) {
doParseSentence(line);
}
}
}
private boolean sentenceIsValid(List<GCLogToken> sentence) {
if (sentence.isEmpty()) {
return false;
} else if (sentence.size() == 1) {
return sentence.get(0).getType() == TOKEN_LINE_FULL_SENTENCE
|| sentence.get(0).getType() == TOKEN_EMBEDDED_SENTENCE;
} else {
return Arrays.asList(GC_TRACETIME_END_TOKEN_TYPES).contains(sentence.get(sentence.size() - 1).getType());
}
}
@Data
private static class GCLogToken {
private GCLogTokenType type;
private String value; // its corresponding string in original text. Some signs like ',' or ')' may have been removed
private int end; // index of next character after this token in original text
public GCLogToken(String value, int end) {
this.value = value;
this.end = end;
}
@Override
public String toString() {
return value;
}
}
// "2021-11-24T23:23:44.225-0800: "
protected final static GCLogTokenType TOKEN_DATESTAMP = (line, index, parser) -> {
if (line.charAt(index) == ' ') {
index++;
}
if (GCLogUtil.isDatestamp(line, index)
&& GCLogUtil.stringSubEquals(line, index + GCLogUtil.DATESTAMP_LENGTH, ": ")) {
String s = line.substring(index, index + GCLogUtil.DATESTAMP_LENGTH);
return new GCLogToken(s, index + GCLogUtil.DATESTAMP_LENGTH + 2);
} else {
return null;
}
};
// "12.979: "
protected final static GCLogTokenType TOKEN_UPTIME = (line, index, parser) -> {
if (line.charAt(index) == ' ') {
index++;
}
int end = GCLogUtil.isDecimal(line, index, 3);
if (end >= 0 && GCLogUtil.stringSubEquals(line, end, ": ")) {
String s = line.substring(index, end);
return new GCLogToken(s, end + 2);
} else {
return null;
}
};
// "#12: "
protected final static GCLogTokenType TOKEN_GCID = (line, index, parser) -> {
if (line.charAt(index) != '#') {
return null;
}
for (int i = index + 1; i < line.length(); i++) {
char c = line.charAt(i);
if (Character.isDigit(c)) {
continue;
}
if (GCLogUtil.stringSubEquals(line, i, ": ")) {
String s = line.substring(index + 1, i);
return new GCLogToken(s, i + 2);
} else {
return null;
}
}
return null;
};
// 2021-11-24T23:23:55.013-0800: 807.779: [GC (Allocation Failure) 2021-11-24T23:23:55.013-0800: 807.780:
// 2021-05-16T19:49:24.719+0800: 170551.726: [GC pause (GCLocker Initiated GC) (young), 0.0218447 secs]
// 2021-05-16T19:49:31.213+0800: 170558.220: [GC pause (G1 Evacuation Pause) (young), 0.0210546 secs]
// 2021-10-03T22:27:00.414+0800: 528676.801: [Full GC (Allocation Failure) 19G->4441M(20G), 12.4414569 secs]
// 2021-07-02T10:22:48.500+0800: 61076.005: [Full GC 61076.006: [CMS: 368928K->248751K(628736K), 1.3006011 secs] 474459K->248751K(1205120K), [Metaspace: 272682K->272682K(1298432K)], 1.3027769 secs] [Times: user=1.22 sys=0.00, real=1.30 secs]
// 2021-08-25T11:28:31.969+0800: 114402.958: [GC pause (Metadata GC Threshold) (young) (initial-mark), 0.3875850 secs]
// 0.269: [Full GC (Ergonomics) [PSYoungGen: 4096K->0K(55296K)] [ParOldGen: 93741K->67372K(174592K)] 97837K->67372K(229888K), [Metaspace: 3202K->3202K(1056768K)], 0.6862093 secs] [Times: user=2.60 sys=0.02, real=0.69 secs]
// " [1 CMS-initial-mark"
protected final static GCLogTokenType TOKEN_GC_TRACETIME_TITLE = (line, index, parser) -> {
if (line.charAt(index) == ' ') {
index++;// ps full gc has an extra space
}
if (index >= line.length() || line.charAt(index) != '[') {
return null;
}
index++;
if (GCLogUtil.stringSubEquals(line, index, "1 ")) {
index += 2;
}
String title;
if ((title = GCLogUtil.stringSubEqualsAny(line, index, TRACETIME_OTHER_TITLES)) != null) {
return new GCLogToken(title, index + title.length());
} else if ((title = GCLogUtil.stringSubEqualsAny(line, index, TRACETIME_GC_START_TITLES)) != null) {
// gc cause is a part of title
int end = index + title.length();
boolean endWithEmbeddedSentence = false;
while (true) {
if (!GCLogUtil.stringSubEquals(line, end, " (")) {
break;
}
// maybe the () is an embedded sentence
if (GCLogUtil.stringSubEqualsAny(line, end, EMBEDDED_SENTENCE_WITH_BRACKET) != null) {
endWithEmbeddedSentence = true;
break;
}
int rightBracket = GCLogUtil.nextBalancedRightBracket(line, end + 2);
if (rightBracket < 0) {
break;
}
end = rightBracket + 1;
}
if (!endWithEmbeddedSentence && end < line.length() && line.charAt(end) == ' ') {
end++;
}
return new GCLogToken(line.substring(index, end), end);
} else if ((title = GCLogUtil.stringSubEqualsAny(line, index, TRACETIME_GENERATION_TITLES)) != null) {
return new GCLogToken(title, index + title.length());
}
return null;
};
private final static Pattern MEMORY_CHANGE_PATTERN = Pattern.compile("^(:?\\d+[kmgt]?b?(\\(:?\\d+[kmgt]?b?\\))?->)?\\d+[kmgt]?b?(\\(:?\\d+[kmgt]?b?\\))?$");
// " 1922432K->174720K(1922432K)"
// " 1922432->174720K(1922432)"
// " 1922432K(1922432K)->174720K(1922432K)"
// " 1880341K(4019584K)"
protected final static GCLogTokenType TOKEN_MEMORY_CHANGE = (line, index, parser) -> {
if (line.charAt(index) == ':') {
index++;
}
if (index >= line.length() || line.charAt(index) != ' ') {
return null;
}
int end;
for (end = index + 1; end < line.length(); end++) {
char c = line.charAt(end);
if (c == ' ' || c == ',' || c == ']') {// find end position
String memoryChangeString = line.substring(index + 1, end).toLowerCase();
if (MEMORY_CHANGE_PATTERN.matcher(memoryChangeString).matches()) {
return new GCLogToken(memoryChangeString, c == ']' ? end + 1 : end);
} else {
return null;
}
}
}
return null;
};
// ", 0.2240876 secs]"
// ": 0.576/0.611 secs]"
protected final static GCLogTokenType TOKEN_DURATION = (line, index, parser) -> {
if (GCLogUtil.stringSubEquals(line, index, ", ")) {
int end = GCLogUtil.isDecimal(line, index + 2, 7);
if (end >= 0 && GCLogUtil.stringSubEquals(line, end, " secs]")) {
String s = line.substring(index + 2, end);
return new GCLogToken(s, end + " secs]".length());
}
} else if (GCLogUtil.stringSubEquals(line, index, ": ")) {
int slash = GCLogUtil.isDecimal(line, index + 2, 3);
if (slash < 0 || line.charAt(slash) != '/') {
return null;
}
int end = GCLogUtil.isDecimal(line, slash + 1, 3);
if (end >= 0 && GCLogUtil.stringSubEquals(line, end, " secs]")) {
String s = line.substring(slash + 1, end);
return new GCLogToken(s, end + " secs]".length());
}
}
return null;
};
// ", 123 refs"
// return end index if matching, else -1
private static int isReferenceGCToken(String line, int index) {
if (!GCLogUtil.stringSubEquals(line, index, ", ")) {
return -1;
}
int i = index + 2;
while (i < line.length() && Character.isDigit(line.charAt(i))) {
i++;
}
if (i < line.length() && GCLogUtil.stringSubEquals(line, i, " refs")) {
return i + " refs".length();
} else {
return -1;
}
}
// ", 123 refs"
// ", 123 refs, 234 refs" // may appear twice
protected final static GCLogTokenType TOKEN_REFERENCE_GC = (line, index, parser) -> {
int end = isReferenceGCToken(line, index);
if (end < 0) {
return null;
}
int nextEnd = isReferenceGCToken(line, end);
if (nextEnd >= 0) {
end = nextEnd;
}
return new GCLogToken(line.substring(index + 2, end), end);
};
// ", [Metaspace: 246621K->246621K(1273856K)]"
protected final static GCLogTokenType TOKEN_METASPACE = (line, index, parser) -> {
if (GCLogUtil.stringSubEquals(line, index, ", [Metaspace: ")) {
int indexEnd = line.indexOf(']', index);
String s = line.substring(index + ", [Metaspace: ".length(), indexEnd);
return new GCLogToken(s, indexEnd + 1);
} else {
return null;
}
};
// "]"
protected final static GCLogTokenType TOKEN_RIGHT_BRACKET = (line, index, parser) ->
line.charAt(index) == ']' ? new GCLogToken("]", index + 1) : null;
protected final static GCLogTokenType TOKEN_LINE_FULL_SENTENCE = (line, index, parser) -> {
for (String prefix : FULL_LINE_PREFIXES) {
if (line.startsWith(prefix)) {
return new GCLogToken(line, line.length());
}
}
return null;
};
protected final static GCLogTokenType TOKEN_EMBEDDED_SENTENCE = (line, index, parser) -> {
for (String[] beginEnd : EMBEDDED_SENTENCE_BEGIN_END) {
if (GCLogUtil.stringSubEquals(line, index, beginEnd[0])) {
if (beginEnd[1] == null) {
return new GCLogToken(beginEnd[0], index + beginEnd[0].length());
} else {
int end = line.indexOf(beginEnd[1], index + beginEnd[0].length());
if (end >= 0) {
end += beginEnd[1].length();
return new GCLogToken(line.substring(index, end), end);
}
}
}
}
return null;
};
// 0.231: Total time for which application threads were stopped: 0.0001215 seconds, Stopping threads took: 0.0000271 seconds
// 0.248: Application time: 0.0170944 seconds
// safepoint info prints datestamp or timestamp, but it is not printed in [] style
protected final static GCLogTokenType TOKEN_SAFEPOINT = (line, index, parser) -> {
if (GCLogUtil.stringSubEquals(line, index, "Total time for which") ||
GCLogUtil.stringSubEquals(line, index, "Application time:")) {
return new GCLogToken(line.substring(index), line.length());
} else {
return null;
}
};
// order of tokens matters
private static final GCLogTokenType[] GC_TRACETIME_BEGIN_TOKEN_TYPES = {
TOKEN_DATESTAMP,
TOKEN_UPTIME,
TOKEN_GCID,
TOKEN_GC_TRACETIME_TITLE,
};
private static final GCLogTokenType[] GC_TRACETIME_END_TOKEN_TYPES = {
TOKEN_SAFEPOINT,
TOKEN_MEMORY_CHANGE,
TOKEN_REFERENCE_GC,
TOKEN_METASPACE,
TOKEN_DURATION,
TOKEN_RIGHT_BRACKET,
};
private static class LineAssembler {
AbstractPreUnifiedGCLogParser parser;
private final String line;
private int cursor = 0;
private GCLogToken lastToken;
public LineAssembler(AbstractPreUnifiedGCLogParser parser, String line) {
this.parser = parser;
this.line = line;
}
private void doAssemble() {
if (checkNextToken(TOKEN_LINE_FULL_SENTENCE)) {
parser.pushSentenceToParse(List.of(lastToken));
}
while (!endOfLine()) {
if (checkNextToken(TOKEN_EMBEDDED_SENTENCE)) {
parser.pushSentenceToParse(List.of(lastToken));
continue;
}
List<GCLogToken> sentence = null;
for (GCLogTokenType tokenType : GC_TRACETIME_BEGIN_TOKEN_TYPES) {
if (sentence == null && tokenType == TOKEN_GCID) {
// at least one of -XX:+PrintGCDateStamps and -XX:+PrintGCTimeStamps is needed, gcid can not
// occur at beginning
continue;
}
if (checkNextToken(tokenType)) {
if (sentence == null) {
sentence = new ArrayList<>();
}
sentence.add(lastToken);
}
}
if (sentence != null) {
parser.pushSentenceToAssemble(sentence);
parser.pushSentenceToParse(sentence);
continue;
}
for (GCLogTokenType tokenType : GC_TRACETIME_END_TOKEN_TYPES) {
if (!checkNextToken(tokenType)) {
continue;
}
if (sentence == null) {
if (tokenType == TOKEN_SAFEPOINT || tokenType == TOKEN_REFERENCE_GC) {
// They are always printed together with timestamp
sentence = parser.pollSentenceToAssemble();
} else {
// Filter out some invalid sentence. This may be useful when
// the log is using unsupported options
do {
sentence = parser.pollSentenceToAssemble();
} while (sentence != null &&
sentence.get(sentence.size() - 1).getType() != TOKEN_GC_TRACETIME_TITLE);
}
if (sentence == null) {
break; // log is incomplete?
}
}
sentence.add(lastToken);
}
if (sentence != null) {
continue;
}
// should not reach here if we have considered all cases
break;
}
}
private boolean endOfLine() {
return cursor >= line.length();
}
private boolean checkNextToken(GCLogTokenType tokenType) {
if (endOfLine()) {
return false;
}
GCLogToken token = tokenType.parseNextToken(line, cursor, parser);
if (token != null) {
token.setType(tokenType);
cursor = token.end;
lastToken = token;
}
return token != null;
}
}
protected static void copyPhaseDataToStart(GCEvent phaseStart, GCEvent phase) {
if (phaseStart.getDuration() == Constant.UNKNOWN_DOUBLE) {
if (phase.getDuration() != Constant.UNKNOWN_DOUBLE) {
phaseStart.setDuration(phase.getDuration());
} else if (phase.getStartTime() != Constant.UNKNOWN_DOUBLE && phaseStart.getStartTime() != Constant.UNKNOWN_DOUBLE) {
phaseStart.setDuration(phase.getStartTime() - phaseStart.getStartTime());
}
}
if (phase.getMemoryItems() != null && phaseStart.getMemoryItems() == null) {
phaseStart.setMemoryItems(phase.getMemoryItems());
}
if (phase.getCpuTime() != null && phaseStart.getCpuTime() == null) {
phaseStart.setCpuTime(phase.getCpuTime());
}
}
protected static final ParseRule commandLineRule = new PrefixAndValueParseRule("CommandLine flags:",
((parser, context, prefix, flags) -> parser.getModel().setVmOptions(new VmOptions(flags))));
private LinkedList<GCEvent> eventsWaitingForCpuTime = new LinkedList<>();
protected void pushIfWaitingForCpuTime(GCEvent event) {
if (getCPUTimeGCEvent().contains(event.getEventType())) {
eventsWaitingForCpuTime.offerLast(event);
}
}
protected static final ParseRule cpuTimeRule = new PrefixAndValueParseRule(" [Times",
((parser, context, prefix, value) -> {
LinkedList<GCEvent> queue = ((AbstractPreUnifiedGCLogParser)parser).eventsWaitingForCpuTime;
while (!queue.isEmpty()) {
GCEvent event = queue.pollLast();
if (event.getCpuTime() == null) {
CpuTime cpuTime = GCLogUtil.parseCPUTime(value.substring(0, value.length() - 1));
event.setCpuTime(cpuTime);
return;
}
}
}));
}
| 6,753 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/UnifiedZGCLogParser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.ThreadEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.GCMemoryItem;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.model.ZGCModel;
import org.eclipse.jifa.gclog.model.ZGCModel.ZStatistics;
import org.eclipse.jifa.gclog.util.GCLogUtil;
import java.util.ArrayList;
import java.util.List;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
import static org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea.METASPACE;
import static org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea.HEAP;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
import static org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext.GCID;
import static org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext.UPTIME;
public class UnifiedZGCLogParser extends AbstractUnifiedGCLogParser {
/*
* [2021-08-31T08:08:17.108+0800] GC(374) Garbage Collection (Proactive)
* [2021-08-31T08:08:17.114+0800] GC(374) Pause Mark Start 4.459ms
* [2021-08-31T08:08:17.421+0800] GC(374) Concurrent Mark 306.720ms
* [2021-08-31T08:08:17.423+0800] GC(374) Pause Mark End 0.606ms
* [2021-08-31T08:08:17.424+0800] GC(374) Concurrent Process Non-Strong References 1.290ms
* [2021-08-31T08:08:17.425+0800] GC(374) Concurrent Reset Relocation Set 0.550ms
* [2021-08-31T08:08:17.425+0800] GC(374) Concurrent Destroy Detached Pages 0.001ms
* [2021-08-31T08:08:17.427+0800] GC(374) Concurrent Select Relocation Set 2.418ms
* [2021-08-31T08:08:17.433+0800] GC(374) Concurrent Prepare Relocation Set 5.719ms
* [2021-08-31T08:08:17.438+0800] GC(374) Pause Relocate Start 3.791ms
* [2021-08-31T08:08:17.471+0800] GC(374) Concurrent Relocate 32.974ms
* [2021-08-31T08:08:17.471+0800] GC(374) Load: 1.68/1.99/2.04
* [2021-08-31T08:08:17.471+0800] GC(374) MMU: 2ms/0.0%, 5ms/0.0%, 10ms/0.0%, 20ms/0.0%, 50ms/0.0%, 100ms/0.0%
* [2021-08-31T08:08:17.471+0800] GC(374) Mark: 8 stripe(s), 2 proactive flush(es), 1 terminate flush(es), 0 completion(s), 0 continuation(s)
* [2021-08-31T08:08:17.471+0800] GC(374) Relocation: Successful, 359M relocated
* [2021-08-31T08:08:17.471+0800] GC(374) NMethods: 21844 registered, 609 unregistered
* [2021-08-31T08:08:17.471+0800] GC(374) Metaspace: 125M used, 128M capacity, 128M committed, 130M reserved
* [2021-08-31T08:08:17.471+0800] GC(374) Soft: 18634 encountered, 0 discovered, 0 enqueued
* [2021-08-31T08:08:17.471+0800] GC(374) Weak: 56186 encountered, 18454 discovered, 3112 enqueued
* [2021-08-31T08:08:17.471+0800] GC(374) Final: 64 encountered, 16 discovered, 7 enqueued
* [2021-08-31T08:08:17.471+0800] GC(374) Phantom: 1882 encountered, 1585 discovered, 183 enqueued
* [2021-08-31T08:08:17.471+0800] GC(374) Mark Start Mark End Relocate Start Relocate End High Low
* [2021-08-31T08:08:17.471+0800] GC(374) Capacity: 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%)
* [2021-08-31T08:08:17.471+0800] GC(374) Reserve: 96M (0%) 96M (0%) 96M (0%) 96M (0%) 96M (0%) 96M (0%)
* [2021-08-31T08:08:17.471+0800] GC(374) Free: 35250M (86%) 35210M (86%) 35964M (88%) 39410M (96%) 39410M (96%) 35210M (86%)
* [2021-08-31T08:08:17.471+0800] GC(374) Used: 5614M (14%) 5654M (14%) 4900M (12%) 1454M (4%) 5654M (14%) 1454M (4%)
* [2021-08-31T08:08:17.471+0800] GC(374) Live: - 1173M (3%) 1173M (3%) 1173M (3%) - -
* [2021-08-31T08:08:17.471+0800] GC(374) Allocated: - 40M (0%) 40M (0%) 202M (0%) - -
* [2021-08-31T08:08:17.471+0800] GC(374) Garbage: - 4440M (11%) 3686M (9%) 240M (1%) - -
* [2021-08-31T08:08:17.471+0800] GC(374) Reclaimed: - - 754M (2%) 4200M (10%) - -
* [2021-08-31T08:08:17.471+0800] GC(374) Garbage Collection (Proactive) 5614M(14%)->1454M(4%)
* [2021-08-31T08:08:25.209+0800] === Garbage Collection Statistics =======================================================================================================================
* [2021-08-31T08:08:25.210+0800] Last 10s Last 10m Last 10h Total
* [2021-08-31T08:08:25.210+0800] Avg / Max Avg / Max Avg / Max Avg / Max
* [2021-08-31T08:08:25.210+0800] Collector: Garbage Collection Cycle 362.677 / 362.677 365.056 / 529.211 315.229 / 868.961 315.229 / 868.961 ms
* [2021-08-31T08:08:25.210+0800] Contention: Mark Segment Reset Contention 0 / 0 1 / 106 0 / 238 0 / 238 ops/s
* [2021-08-31T08:08:25.210+0800] Contention: Mark SeqNum Reset Contention 0 / 0 0 / 1 0 / 1 0 / 1 ops/s
* [2021-08-31T08:08:25.210+0800] Contention: Relocation Contention 1 / 10 0 / 52 0 / 87 0 / 87 ops/s
* [2021-08-31T08:08:25.210+0800] Critical: Allocation Stall 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms
* [2021-08-31T08:08:25.210+0800] Critical: Allocation Stall 0 / 0 0 / 0 0 / 0 0 / 0 ops/s
* [2021-08-31T08:08:25.210+0800] Critical: GC Locker Stall 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms
* [2021-08-31T08:08:25.210+0800] Critical: GC Locker Stall 0 / 0 0 / 0 0 / 0 0 / 0 ops/s
* [2021-08-31T08:08:25.210+0800] Memory: Allocation Rate 85 / 210 104 / 826 54 / 2628 54 / 2628 MB/s
* [2021-08-31T08:08:25.210+0800] Memory: Heap Used After Mark 5654 / 5654 5727 / 6416 5588 / 14558 5588 / 14558 MB
* [2021-08-31T08:08:25.210+0800] Memory: Heap Used After Relocation 1454 / 1454 1421 / 1814 1224 / 2202 1224 / 2202 MB
* [2021-08-31T08:08:25.210+0800] Memory: Heap Used Before Mark 5614 / 5614 5608 / 6206 5503 / 14268 5503 / 14268 MB
* [2021-08-31T08:08:25.210+0800] Memory: Heap Used Before Relocation 4900 / 4900 4755 / 5516 4665 / 11700 4665 / 11700 MB
* [2021-08-31T08:08:25.210+0800] Memory: Out Of Memory 0 / 0 0 / 0 0 / 0 0 / 0 ops/s
* [2021-08-31T08:08:25.210+0800] Memory: Page Cache Flush 0 / 0 0 / 0 0 / 0 0 / 0 MB/s
* [2021-08-31T08:08:25.210+0800] Memory: Page Cache Hit L1 49 / 105 53 / 439 27 / 1353 27 / 1353 ops/s
* [2021-08-31T08:08:25.210+0800] Memory: Page Cache Hit L2 0 / 0 0 / 0 0 / 0 0 / 0 ops/s
* [2021-08-31T08:08:25.210+0800] Memory: Page Cache Miss 0 / 0 0 / 0 0 / 551 0 / 551 ops/s
* [2021-08-31T08:08:25.210+0800] Memory: Undo Object Allocation Failed 0 / 0 0 / 0 0 / 8 0 / 8 ops/s
* [2021-08-31T08:08:25.210+0800] Memory: Undo Object Allocation Succeeded 1 / 10 0 / 52 0 / 87 0 / 87 ops/s
* [2021-08-31T08:08:25.210+0800] Memory: Undo Page Allocation 0 / 0 0 / 1 0 / 16 0 / 16 ops/s
* [2021-08-31T08:08:25.210+0800] Phase: Concurrent Destroy Detached Pages 0.001 / 0.001 0.001 / 0.001 0.001 / 0.012 0.001 / 0.012 ms
* [2021-08-31T08:08:25.210+0800] Phase: Concurrent Mark 306.720 / 306.720 303.979 / 452.112 255.790 / 601.718 255.790 / 601.718 ms
* [2021-08-31T08:08:25.210+0800] Phase: Concurrent Mark Continue 0.000 / 0.000 0.000 / 0.000 189.372 / 272.607 189.372 / 272.607 ms
* [2021-08-31T08:08:25.210+0800] Phase: Concurrent Prepare Relocation Set 5.719 / 5.719 6.314 / 14.492 6.150 / 36.507 6.150 / 36.507 ms
* [2021-08-31T08:08:25.210+0800] Phase: Concurrent Process Non-Strong References 1.290 / 1.290 1.212 / 1.657 1.179 / 2.334 1.179 / 2.334 ms
* [2021-08-31T08:08:25.210+0800] Phase: Concurrent Relocate 32.974 / 32.974 35.964 / 86.278 31.599 / 101.253 31.599 / 101.253 ms
* [2021-08-31T08:08:25.210+0800] Phase: Concurrent Reset Relocation Set 0.550 / 0.550 0.615 / 0.937 0.641 / 5.411 0.641 / 5.411 ms
* [2021-08-31T08:08:25.210+0800] Phase: Concurrent Select Relocation Set 2.418 / 2.418 2.456 / 3.131 2.509 / 4.753 2.509 / 4.753 ms
* [2021-08-31T08:08:25.210+0800] Phase: Pause Mark End 0.606 / 0.606 0.612 / 0.765 0.660 / 5.543 0.660 / 5.543 ms
* [2021-08-31T08:08:25.210+0800] Phase: Pause Mark Start 4.459 / 4.459 4.636 / 6.500 6.160 / 547.572 6.160 / 547.572 ms
* [2021-08-31T08:08:25.210+0800] Phase: Pause Relocate Start 3.791 / 3.791 3.970 / 5.443 4.047 / 8.993 4.047 / 8.993 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Concurrent Mark 306.253 / 306.593 303.509 / 452.030 254.759 / 601.564 254.759 / 601.564 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Concurrent Mark Idle 1.069 / 1.110 1.527 / 18.317 1.101 / 18.317 1.101 / 18.317 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Concurrent Mark Try Flush 0.554 / 0.685 0.872 / 18.247 0.507 / 18.247 0.507 / 18.247 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Concurrent Mark Try Terminate 0.978 / 1.112 1.386 / 18.318 0.998 / 18.318 0.998 / 18.318 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Concurrent References Enqueue 0.007 / 0.007 0.008 / 0.013 0.009 / 0.037 0.009 / 0.037 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Concurrent References Process 0.628 / 0.628 0.638 / 1.153 0.596 / 1.789 0.596 / 1.789 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Concurrent Weak Roots 0.497 / 0.618 0.492 / 0.670 0.502 / 1.001 0.502 / 1.001 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Concurrent Weak Roots JNIWeakHandles 0.001 / 0.001 0.001 / 0.006 0.001 / 0.007 0.001 / 0.007 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Concurrent Weak Roots StringTable 0.476 / 0.492 0.402 / 0.523 0.400 / 0.809 0.400 / 0.809 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Concurrent Weak Roots VMWeakHandles 0.105 / 0.123 0.098 / 0.150 0.103 / 0.903 0.103 / 0.903 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Mark Try Complete 0.000 / 0.000 0.001 / 0.004 0.156 / 1.063 0.156 / 1.063 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Remap TLABS 0.040 / 0.040 0.046 / 0.073 0.050 / 0.140 0.050 / 0.140 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Retire TLABS 0.722 / 0.722 0.835 / 1.689 0.754 / 1.919 0.754 / 1.919 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots 1.581 / 2.896 1.563 / 3.787 1.592 / 545.902 1.592 / 545.902 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots ClassLoaderDataGraph 1.461 / 2.857 1.549 / 3.782 1.554 / 6.380 1.554 / 6.380 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots CodeCache 1.130 / 1.312 0.999 / 1.556 0.988 / 6.322 0.988 / 6.322 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots JNIHandles 0.010 / 0.015 0.004 / 0.028 0.005 / 1.709 0.005 / 1.709 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots JNIWeakHandles 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots JRFWeak 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots JVMTIExport 0.001 / 0.001 0.001 / 0.003 0.001 / 0.005 0.001 / 0.005 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots JVMTIWeakExport 0.001 / 0.001 0.001 / 0.001 0.001 / 0.012 0.001 / 0.012 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots Management 0.002 / 0.002 0.003 / 0.006 0.003 / 0.305 0.003 / 0.305 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots ObjectSynchronizer 0.000 / 0.000 0.000 / 0.001 0.000 / 0.006 0.000 / 0.006 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots Setup 0.474 / 0.732 0.582 / 1.791 0.526 / 2.610 0.526 / 2.610 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots StringTable 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots SystemDictionary 0.028 / 0.039 0.027 / 0.075 0.033 / 2.777 0.033 / 2.777 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots Teardown 0.003 / 0.005 0.003 / 0.009 0.003 / 0.035 0.003 / 0.035 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots Threads 0.262 / 1.237 0.309 / 1.791 0.358 / 544.610 0.358 / 544.610 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots Universe 0.003 / 0.004 0.003 / 0.009 0.003 / 0.047 0.003 / 0.047 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Roots VMWeakHandles 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Weak Roots 0.000 / 0.003 0.000 / 0.007 0.000 / 0.020 0.000 / 0.020 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Weak Roots JFRWeak 0.001 / 0.001 0.001 / 0.002 0.001 / 0.012 0.001 / 0.012 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Weak Roots JNIWeakHandles 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Weak Roots JVMTIWeakExport 0.001 / 0.001 0.001 / 0.001 0.001 / 0.008 0.001 / 0.008 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Weak Roots Setup 0.000 / 0.000 0.000 / 0.000 0.000 / 0.001 0.000 / 0.001 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Weak Roots StringTable 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Weak Roots SymbolTable 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Weak Roots Teardown 0.001 / 0.001 0.001 / 0.001 0.001 / 0.015 0.001 / 0.015 ms
* [2021-08-31T08:08:25.210+0800] Subphase: Pause Weak Roots VMWeakHandles 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms
* [2021-08-31T08:08:25.210+0800] System: Java Threads 911 / 911 910 / 911 901 / 913 901 / 913 threads
* [2021-08-31T08:08:25.210+0800] =========================================================================================================================================================
* [2021-08-31T11:29:12.823+0800] Allocation Stall (ThreadPoolTaskScheduler-1) 0.204ms
* [2021-08-31T11:29:12.823+0800] Allocation Stall (http-nio-8080-exec-71) 1.032ms
* [2021-08-31T11:29:12.823+0800] Allocation Stall (NioProcessor-2) 0.391ms
* [2021-08-31T11:29:12.823+0800] Allocation Stall (http-nio-8080-exec-85) 0.155ms
* [2021-08-31T11:29:12.823+0800] Allocation Stall (http-nio-8080-exec-49) 277.588ms
* [2021-08-31T11:29:12.825+0800] Out Of Memory (thread 8)
*/
private static List<ParseRule> withGCIDRules;
private static List<ParseRule> withoutGCIDRules;
static {
initializeParseRules();
}
private static void initializeParseRules() {
withoutGCIDRules = new ArrayList<>(AbstractUnifiedGCLogParser.getSharedWithoutGCIDRules());
withoutGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Allocation Stall", UnifiedZGCLogParser::parseAllocationStall));
withoutGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Out Of Memory", UnifiedZGCLogParser::pauseOutOfMemory));
withoutGCIDRules.add(UnifiedZGCLogParser::parseZGCStatisticLine);
withGCIDRules = new ArrayList<>(AbstractUnifiedGCLogParser.getSharedWithGCIDRules());
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Pause Mark Start", UnifiedZGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Concurrent Mark", UnifiedZGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Pause Mark End", UnifiedZGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Concurrent Process Non-Strong References", UnifiedZGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Concurrent Reset Relocation Set", UnifiedZGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Concurrent Destroy Detached Pages", UnifiedZGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Concurrent Select Relocation Set", UnifiedZGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Concurrent Prepare Relocation Set", UnifiedZGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Pause Relocate Start", UnifiedZGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Concurrent Relocate", UnifiedZGCLogParser::parsePhase));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Metaspace", UnifiedZGCLogParser::parseMetaspace));
// some heap items are not listed because we do not use them
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule(" Capacity", UnifiedZGCLogParser::parseHeap));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule(" Used", UnifiedZGCLogParser::parseHeap));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Allocated", UnifiedZGCLogParser::parseHeap));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Reclaimed", UnifiedZGCLogParser::parseHeap));
withGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Garbage Collection", UnifiedZGCLogParser::parseGarbageCollection));
}
@Override
protected void doParseLineWithGCID(String detail, int gcid, double uptime) {
ParseRule.ParseRuleContext context = new ParseRule.ParseRuleContext();
context.put(UPTIME, uptime);
context.put(GCID, gcid);
doParseUsingRules(this, context, detail, withGCIDRules);
}
@Override
protected void doParseLineWithoutGCID(String detail, double uptime) {
ParseRule.ParseRuleContext context = new ParseRule.ParseRuleContext();
context.put(UPTIME, uptime);
doParseUsingRules(this, context, detail, withoutGCIDRules);
}
// [2021-08-31T08:08:17.471+0800] GC(374) Metaspace: 125M used, 128M capacity, 128M committed, 130M reserved
// [0.950s][info][gc,metaspace] GC(0) Metaspace: 0M used, 0M committed, 1032M reserved
private static void parseMetaspace(AbstractGCLogParser parser, ParseRule.ParseRuleContext context, String prefix, String value) {
GCModel model = parser.getModel();
String[] parts = GCLogUtil.splitBySpace(value);
GCEvent event = model.getLastEventOfType(ZGC_GARBAGE_COLLECTION);
if (event == null) {
return;
}
String capacityString = parts.length == 6 ? parts[2] : parts[4];
GCMemoryItem item = new GCMemoryItem(METASPACE, UNKNOWN_INT, UNKNOWN_INT,
GCLogUtil.toByte(parts[0]), GCLogUtil.toByte(capacityString));
event.setMemoryItem(item);
}
// [2021-08-31T11:29:12.825+0800] Out Of Memory (thread 8)
private static void pauseOutOfMemory(AbstractGCLogParser parser, ParseRule.ParseRuleContext context, String prefix, String value) {
GCModel model = parser.getModel();
ThreadEvent event = new ThreadEvent();
event.setThreadName(value.substring(1, value.length() - 1));
event.setStartTime(context.get(UPTIME));
model.addOom(event);
}
/*
* [2021-08-31T08:08:17.471+0800] GC(374) Capacity: 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%) 40960M (100%)
* [2021-08-31T08:08:17.471+0800] GC(374) Reserve: 96M (0%) 96M (0%) 96M (0%) 96M (0%) 96M (0%) 96M (0%)
* [2021-08-31T08:08:17.471+0800] GC(374) Free: 35250M (86%) 35210M (86%) 35964M (88%) 39410M (96%) 39410M (96%) 35210M (86%)
* [2021-08-31T08:08:17.471+0800] GC(374) Used: 5614M (14%) 5654M (14%) 4900M (12%) 1454M (4%) 5654M (14%) 1454M (4%)
* [2021-08-31T08:08:17.471+0800] GC(374) Live: - 1173M (3%) 1173M (3%) 1173M (3%) - -
* [2021-08-31T08:08:17.471+0800] GC(374) Allocated: - 40M (0%) 40M (0%) 202M (0%) - -
* [2021-08-31T08:08:17.471+0800] GC(374) Garbage: - 4440M (11%) 3686M (9%) 240M (1%) - -
* [2021-08-31T08:08:17.471+0800] GC(374) Reclaimed: - - 754M (2%) 4200M (10%) - -
*/
private static void parseHeap(AbstractGCLogParser parser, ParseRule.ParseRuleContext context, String prefix, String value) {
GCModel model = parser.getModel();
prefix = prefix.trim();
String[] parts = GCLogUtil.splitBySpace(value);
GCEvent event = model.getLastEventOfType(ZGC_GARBAGE_COLLECTION);
if (event == null) {
return;
}
switch (prefix) {
case "Capacity":
GCMemoryItem item = new GCMemoryItem(HEAP);
item.setPreCapacity(GCLogUtil.toByte(parts[0]));
item.setPostCapacity(GCLogUtil.toByte(parts[6]));
event.setMemoryItem(item);
break;
case "Used":
item = event.getMemoryItem(HEAP);
item.setPreUsed(GCLogUtil.toByte(parts[0]));
item.setPostUsed(GCLogUtil.toByte(parts[6]));
break;
case "Reclaimed":
event.setReclamation(GCLogUtil.toByte(parts[4]));
break;
case "Allocated":
event.setAllocation(GCLogUtil.toByte(parts[5]));
break;
}
}
/*
* [2021-08-31T08:08:17.108+0800] GC(374) Garbage Collection (Proactive)
* [2021-08-31T08:08:17.471+0800] GC(374) Garbage Collection (Proactive) 5614M(14%)->1454M(4%)
*/
private static void parseGarbageCollection(AbstractGCLogParser parser, ParseRule.ParseRuleContext context, String prefix, String value) {
GCModel model = parser.getModel();
int index = value.indexOf(')');
GCEvent event;
if (index == value.length() - 1) {
event = new GCEvent();
model.putEvent(event);
event.setStartTime(context.get(UPTIME));
event.setEventType(ZGC_GARBAGE_COLLECTION);
event.setCause(value.substring(1, index));
event.setGcid(context.get(GCID));
} else if (value.endsWith("%)")) {
event = model.getLastEventOfType(ZGC_GARBAGE_COLLECTION);
if (event == null) {
return;
}
event.setDuration(context.<Double>get(UPTIME) - event.getStartTime());
// parsing heap change here is done in parseHeap. Don't do that here
}
}
/*
* [2021-08-31T11:29:12.823+0800] Allocation Stall (ThreadPoolTaskScheduler-1) 0.204ms
* [2021-08-31T11:29:12.823+0800] Allocation Stall (http-nio-8080-exec-71) 1.032ms
* [2021-08-31T11:29:12.823+0800] Allocation Stall (NioProcessor-2) 0.391ms
* [2021-08-31T11:29:12.823+0800] Allocation Stall (http-nio-8080-exec-85) 0.155ms
* [2021-08-31T11:29:12.823+0800] Allocation Stall (http-nio-8080-exec-49) 277.588ms
*/
private static void parseAllocationStall(AbstractGCLogParser parser, ParseRule.ParseRuleContext context, String prefix, String value) {
GCModel model = parser.getModel();
String[] parts = GCLogUtil.splitByBracket(value);
ThreadEvent event = new ThreadEvent();
double endTime = context.get(UPTIME);
double duration = GCLogUtil.toMillisecond(parts[1]);
event.setStartTime(endTime - duration);
event.setDuration(duration);
event.setEventType(ZGC_ALLOCATION_STALL);
event.setThreadName(parts[0]);
((ZGCModel) model).addAllocationStalls(event);
}
/*
* [2021-08-31T08:08:17.114+0800] GC(374) Pause Mark Start 4.459ms
* [2021-08-31T08:08:17.421+0800] GC(374) Concurrent Mark 306.720ms
* [2021-08-31T08:08:17.423+0800] GC(374) Pause Mark End 0.606ms
* [2021-08-31T08:08:17.424+0800] GC(374) Concurrent Process Non-Strong References 1.290ms
* [2021-08-31T08:08:17.425+0800] GC(374) Concurrent Reset Relocation Set 0.550ms
* [2021-08-31T08:08:17.425+0800] GC(374) Concurrent Destroy Detached Pages 0.001ms
* [2021-08-31T08:08:17.427+0800] GC(374) Concurrent Select Relocation Set 2.418ms
* [2021-08-31T08:08:17.433+0800] GC(374) Concurrent Prepare Relocation Set 5.719ms
* [2021-08-31T08:08:17.438+0800] GC(374) Pause Relocate Start 3.791ms
* [2021-08-31T08:08:17.471+0800] GC(374) Concurrent Relocate 32.974ms
*/
private static void parsePhase(AbstractGCLogParser parser, ParseRule.ParseRuleContext context, String phaseName, String value) {
GCModel model = parser.getModel();
GCEventType eventType = getGCEventType(phaseName);
GCEvent event = model.getLastEventOfType(eventType.getPhaseParentEventType());
if (event == null) {
// log may be incomplete
return;
}
GCEvent phase = new GCEvent();
double endTime = context.get(UPTIME);
double duration = GCLogUtil.toMillisecond(value);
phase.setGcid(event.getGcid());
phase.setStartTime(endTime - duration);
phase.setDuration(duration);
phase.setEventType(eventType);
model.addPhase(event, phase);
}
/*
* [2021-08-31T08:08:25.210+0800] Collector: Garbage Collection Cycle 362.677 / 362.677 365.056 / 529.211 315.229 / 868.961 315.229 / 868.961 ms
* [2021-08-31T08:08:25.210+0800] Contention: Mark Segment Reset Contention 0 / 0 1 / 106 0 / 238 0 / 238 ops/s
* [2021-08-31T08:08:25.210+0800] Contention: Mark SeqNum Reset Contention 0 / 0 0 / 1 0 / 1 0 / 1 ops/s
* [2021-08-31T08:08:25.210+0800] Contention: Relocation Contention 1 / 10 0 / 52 0 / 87 0 / 87 ops/s
* [2021-08-31T08:08:25.210+0800] Critical: Allocation Stall 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 0.000 / 0.000 ms
* [2021-08-31T08:08:25.210+0800] Critical: Allocation Stall 0 / 0 0 / 0 0 / 0 0 / 0 ops/s
* [10.418s][info][gc,stats ] Memory: Uncommit 0 / 0 0 / 0 0 / 0 0 / 0 MB/s
*/
private static boolean parseZGCStatisticLine(AbstractGCLogParser parser, ParseRule.ParseRuleContext context, String text) {
ZGCModel model = (ZGCModel) parser.getModel();
String[] tokens = GCLogUtil.splitBySpace(text);
int length = tokens.length;
if (length >= 15 && "/".equals(tokens[length - 3]) && "/".equals(tokens[length - 6]) &&
"/".equals(tokens[length - 9]) && "/".equals(tokens[length - 12])) {
// make unit a part of type name to deduplicate
String type = text.substring(0, text.indexOf('/') - 1 - tokens[length - 13].length()).trim()
+ " " + tokens[length - 1];
List<ZStatistics> statisticsList = model.getStatistics();
ZStatistics statistics;
if ("Collector: Garbage Collection Cycle ms".equals(type)) {
statistics = new ZStatistics();
statistics.setStartTime(context.get(UPTIME));
statisticsList.add(statistics);
} else if (statisticsList.isEmpty()) {
// log is incomplete
return true;
} else {
statistics = statisticsList.get(statisticsList.size() - 1);
}
ZGCModel.ZStatisticsItem item = new ZGCModel.ZStatisticsItem(
Double.parseDouble(tokens[length - 13]),
Double.parseDouble(tokens[length - 11]),
Double.parseDouble(tokens[length - 10]),
Double.parseDouble(tokens[length - 8]),
Double.parseDouble(tokens[length - 7]),
Double.parseDouble(tokens[length - 5]),
Double.parseDouble(tokens[length - 4]),
Double.parseDouble(tokens[length - 2]));
statistics.put(type, item);
return true;
} else {
return false;
}
}
private static GCEventType getGCEventType(String eventString) {
switch (eventString) {
case "Pause Mark Start":
return ZGC_PAUSE_MARK_START;
case "Concurrent Mark":
return ZGC_CONCURRENT_MARK;
case "Pause Mark End":
return ZGC_PAUSE_MARK_END;
case "Concurrent Process Non-Strong References":
return ZGC_CONCURRENT_NONREF;
case "Concurrent Reset Relocation Set":
return ZGC_CONCURRENT_RESET_RELOC_SET;
case "Concurrent Destroy Detached Pages":
return ZGC_CONCURRENT_DETATCHED_PAGES;
case "Concurrent Select Relocation Set":
return ZGC_CONCURRENT_SELECT_RELOC_SET;
case "Concurrent Prepare Relocation Set":
return ZGC_CONCURRENT_PREPARE_RELOC_SET;
case "Pause Relocate Start":
return ZGC_PAUSE_RELOCATE_START;
case "Concurrent Relocate":
return ZGC_CONCURRENT_RELOCATE;
default:
ErrorUtil.shouldNotReachHere();
}
return null;
}
}
| 6,754 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/PreUnifiedGenerationalGCLogParser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.GCCause;
import org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea;
import org.eclipse.jifa.gclog.event.evnetInfo.GCMemoryItem;
import org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.util.GCLogUtil;
import java.util.ArrayList;
import java.util.List;
import static org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea.HEAP;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
import static org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext;
import static org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext.EVENT;
import static org.eclipse.jifa.gclog.parser.ParseRule.PrefixAndValueParseRule;
public class PreUnifiedGenerationalGCLogParser extends AbstractPreUnifiedGCLogParser {
private final static GCEventType[] YOUNG_FULL_GC = {YOUNG_GC, FULL_GC};
private final static GCEventType[] REFERENCE_GC_TYPES = {YOUNG_GC, FULL_GC, WEAK_REFS_PROCESSING};
private final static List<GCEventType> CPU_TIME_TYPES = List.of(YOUNG_GC, FULL_GC, CMS_INITIAL_MARK, CMS_CONCURRENT_MARK, CMS_CONCURRENT_PRECLEAN, CMS_CONCURRENT_ABORTABLE_PRECLEAN, CMS_FINAL_REMARK, CMS_CONCURRENT_SWEEP, CMS_CONCURRENT_RESET);
private final static GCEventType[] CMS_FULL = {CMS_CONCURRENT_MARK_SWEPT, FULL_GC};
/*
* 2020-12-15T11:02:47.476+0800: 63471.266: [GC (Allocation Failure) 2020-12-15T11:02:47.476+0800: 63471.267: [ParNew: 1922374K->174720K(1922432K), 0.5852117 secs] 3476475K->1910594K(4019584K), 0.5855206 secs] [Times: user=1.69 sys=0.08, real=0.58 secs]
* 2020-12-15T11:02:48.064+0800: 63471.854: [GC (CMS Initial Mark) [1 CMS-initial-mark: 1735874K(2097152K)] 1925568K(4019584K), 0.0760575 secs] [Times: user=0.17 sys=0.00, real=0.08 secs]
* 2020-12-15T11:02:48.140+0800: 63471.930: [CMS-concurrent-mark-start]
* 2020-12-15T11:02:48.613+0800: 63472.403: [CMS-concurrent-mark: 0.472/0.473 secs] [Times: user=0.68 sys=0.04, real=0.47 secs]
* 2020-12-15T11:02:48.613+0800: 63472.403: [CMS-concurrent-preclean-start]
* 2020-12-15T11:02:48.623+0800: 63472.413: [CMS-concurrent-preclean: 0.010/0.010 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
* 2020-12-15T11:02:48.623+0800: 63472.413: [CMS-concurrent-abortable-preclean-start]
* CMS: abort preclean due to time 2020-12-15T11:02:54.732+0800: 63478.523: [CMS-concurrent-abortable-preclean: 6.102/6.109 secs] [Times: user=6.13 sys=0.09, real=6.11 secs]
* 2020-12-15T11:02:54.734+0800: 63478.524: [GC (CMS Final Remark) [YG occupancy: 388009 K (1922432 K)]2020-12-15T11:02:54.734+0800: 63478.524: [Rescan (parallel) , 0.1034279 secs]
* 2020-12-15T11:02:54.837+0800: 63478.627: [weak refs processing, 0.0063173 secs]
* 2020-12-15T11:02:54.844+0800: 63478.634: [class unloading, 0.1256964 secs]
* 2020-12-15T11:02:54.969+0800: 63478.760: [scrub symbol table, 0.0364073 secs]
* 2020-12-15T11:02:55.006+0800: 63478.796: [scrub string table, 0.0056749 secs][1 CMS-remark: 1735874K(2097152K)] 2123883K(4019584K), 0.3066740 secs] [Times: user=0.54 sys=0.00, real=0.31 secs]
* 2020-12-15T11:02:55.042+0800: 63478.833: [CMS-concurrent-sweep-start]
* 2020-12-15T11:02:56.203+0800: 63479.993: [CMS-concurrent-sweep: 1.160/1.161 secs] [Times: user=1.23 sys=0.03, real=1.16 secs]
* 2020-12-15T11:02:56.203+0800: 63479.993: [CMS-concurrent-reset-start]
* 2020-12-15T11:02:56.218+0800: 63480.008: [CMS-concurrent-reset: 0.015/0.015 secs] [Times: user=0.00 sys=0.01, real=0.02 secs]
* 2020-12-15T11:03:45.384+0800: 63529.175: [GC (Allocation Failure) 2020-12-15T11:03:45.385+0800: 63529.175: [ParNew: 1919804K->174720K(1922432K), 0.5404068 secs] 2298321K->734054K(4019584K), 0.5407823 secs] [Times: user=1.66 sys=0.00, real=0.54 secs]
* 8910.956: [Full GC (Heap Dump Initiated GC) 8910.956: [CMS[YG occupancy: 1212954 K (1843200 K)]8911.637: [weak refs processing, 0.0018945 secs]8911.639: [class unloading, 0.0454119 secs]8911.684: [scrub symbol table, 0.0248340 secs]8911.709: [scrub string table, 0.0033967 secs]: 324459K->175339K(3072000K), 1.0268069 secs] 1537414K->1388294K(4915200K), [Metaspace: 114217K->113775K(1153024K)], 1.0277002 secs] [Times: user=1.71 sys=0.05, real=1.03 secs]
* 2021-09-16T00:00:50.424+0800: 32628.004: [Full GC (GCLocker Initiated GC) 2021-09-16T00:00:50.424+0800: 32628.004: [CMS2021-09-16T00:00:52.070+0800: 32629.650: [CMS-concurrent-mark: 3.106/3.224 secs] [Times: user=17.06 sys=2.91, real=3.22 secs]
* (concurrent mode failure): 4164260K->4013535K(4718592K), 16.9663174 secs] 9450852K->4013535K(10005184K), [Metaspace: 873770K->872947K(1869824K)], 16.9671173 secs] [Times: user=18.54 sys=0.08, real=16.97 secs]
* 2016-03-22T10:02:41.962-0100: 13.396: [GC (Allocation Failure) 2016-03-22T10:02:41.962-0100: 13.396: [ParNew2016-03-22T10:02:41.970-0100: 13.404: [SoftReference, 0 refs, 0.0000260 secs]2016-03-22T10:02:41.970-0100: 13.404: [WeakReference, 59 refs, 0.0000110 secs]2016-03-22T10:02:41.970-0100: 13.404: [FinalReference, 1407 refs, 0.0025979 secs]2016-03-22T10:02:41.973-0100: 13.407: [PhantomReference, 0 refs, 0 refs, 0.0000131 secs]2016-03-22T10:02:41.973-0100: 13.407: [JNI Weak Reference, 0.0000088 secs]: 69952K->8704K(78656K), 0.0104509 secs] 69952K->11354K(253440K), 0.0105137 secs] [Times: user=0.04 sys=0.01, real=0.01 secs]
* 2021-12-23T15:42:48.667+0800: [GC (CMS Final Remark) [YG occupancy: 10073 K (78656 K)]2021-12-23T15:42:48.667+0800: [Rescan (parallel) , 0.0020502 secs]2021-12-23T15:42:48.669+0800: [weak refs processing2021-12-23T15:42:48.669+0800: [SoftReference, 0 refs, 0.0000080 secs]2021-12-23T15:42:48.669+0800: [WeakReference, 0 refs, 0.0000067 secs]2021-12-23T15:42:48.669+0800: [FinalReference, 0 refs, 0.0000060 secs]2021-12-23T15:42:48.669+0800: [PhantomReference, 0 refs, 0 refs, 0.0000067 secs]2021-12-23T15:42:48.669+0800: [JNI Weak Reference, 0.0000164 secs], 0.0000611 secs]2021-12-23T15:42:48.669+0800: [class unloading, 0.0002626 secs]2021-12-23T15:42:48.669+0800: [scrub symbol table, 0.0003540 secs]2021-12-23T15:42:48.669+0800: [scrub string table, 0.0001338 secs][1 CMS-remark: 143081K(174784K)] 153154K(253440K), 0.0029093 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
* */
private static List<ParseRule> fullSentenceRules;
private static List<ParseRule> gcTraceTimeRules;
static {
initializeParseRules();
}
private static void initializeParseRules() {
fullSentenceRules = new ArrayList<>();
fullSentenceRules.add(commandLineRule);
fullSentenceRules.add(cpuTimeRule);
fullSentenceRules.add(new PrefixAndValueParseRule(" (concurrent mode interrupted)", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" (concurrent mode failure)", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" (promotion failed", PreUnifiedGenerationalGCLogParser::parsePromotionFailed));
gcTraceTimeRules = new ArrayList<>();
gcTraceTimeRules.add(PreUnifiedGenerationalGCLogParser::parseGenerationCollection);
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC (CMS Initial Mark)", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("CMS-concurrent-mark", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("CMS-concurrent-preclean", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("CMS-concurrent-abortable-preclean", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC (CMS Final Remark)", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("Rescan", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("weak refs processing", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("class unloading", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("scrub symbol table", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("scrub string table", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("CMS-concurrent-sweep", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("CMS-concurrent-reset", PreUnifiedGenerationalGCLogParser::parseCMSPhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC", PreUnifiedGenerationalGCLogParser::parseYoungFullGC));
gcTraceTimeRules.add(new PrefixAndValueParseRule("Full GC", PreUnifiedGenerationalGCLogParser::parseYoungFullGC));
}
private static void parsePromotionFailed(AbstractGCLogParser parser, ParseRuleContext context, String s, String s1) {
GCModel model = parser.getModel();
GCEvent event = model.getLastEventOfType(YOUNG_FULL_GC);
if (event == null) {
return;
}
event.setTrue(GCEventBooleanType.PROMOTION_FAILED);
}
private static void parseCMSPhase(AbstractGCLogParser parser, ParseRuleContext context, String phaseName, String value) {
GCModel model = parser.getModel();
if (phaseName.startsWith("GC (")) {
// "GC (CMS Final Remark)"
phaseName = phaseName.substring(4, phaseName.length() - 1);
} else if (phaseName.startsWith(" (")) {
// " (concurrent mode interrupted)"
phaseName = phaseName.substring(2, phaseName.length() - 1);
}
GCEventType phaseType = getGCEventType(phaseName);
GCEvent phase = context.get(EVENT);
if (phase == null) {
// " (concurrent mode interrupted)"
phase = new GCEvent();
phase.setEventType(phaseType);
GCEvent gc = model.getLastEventOfType(YOUNG_FULL_GC);
if (gc == null) {
return;
}
phase.setStartTime(gc.getStartTime());
phase.setDuration(0);
}
GCEvent parent;
if (phaseType == CMS_INITIAL_MARK) {
parent = new GCEvent();
parent.setEventType(CMS_CONCURRENT_MARK_SWEPT);
parent.setStartTime(phase.getStartTime());
model.putEvent(parent);
} else {
if (phaseType == WEAK_REFS_PROCESSING || phaseType == CMS_CLASS_UNLOADING ||
phaseType == CMS_SCRUB_STRING_TABLE || phaseType == CMS_SCRUB_SYMBOL_TABLE) {
parent = model.getLastEventOfType(CMS_FULL);
} else {
parent = model.getLastEventOfType(CMS_CONCURRENT_MARK_SWEPT);
}
if (parent == null) {
return;
}
}
if (phaseType == CMS_FINAL_REMARK && parent.getLastPhaseOfType(CMS_FINAL_REMARK) != null) {
// When we see the second cms final remark, this is actually the CMSScavengeBeforeRemark.
// In current implementation, young gc must be put at the first level of event structure
// otherwise it can not be correctly aggregated
phase.setEventType(YOUNG_GC);
phase.setCause(GCCause.CMS_FINAL_REMARK);
phase.setTrue(GCEventBooleanType.IGNORE_PAUSE);
model.putEvent(phase);
((AbstractPreUnifiedGCLogParser)parser).pushIfWaitingForCpuTime(phase);
return;
}
GCEvent phaseStart = parent.getLastPhaseOfType(phaseType);
if (phaseStart == null) {
phase.setEventType(phaseType);
model.addPhase(parent, phase);
if (phaseType == CMS_CONCURRENT_INTERRUPTED || phaseType == CMS_CONCURRENT_FAILURE) {
phase.setDuration(0);
}
((AbstractPreUnifiedGCLogParser)parser).pushIfWaitingForCpuTime(phase);
} else {
copyPhaseDataToStart(phaseStart, phase);
((AbstractPreUnifiedGCLogParser)parser).pushIfWaitingForCpuTime(phaseStart);
}
}
private static void parseYoungFullGC(AbstractGCLogParser parser, ParseRuleContext context, String prefix, String cause) {
GCEventType eventType = prefix.equals("GC") ? YOUNG_GC : FULL_GC;
GCEvent event = context.get(EVENT);
event.setEventType(eventType);
String[] causes = GCLogUtil.splitByBracket(cause);
if (causes.length > 0) {
event.setCause(causes[0]);
}
parser.getModel().putEvent(event);
((AbstractPreUnifiedGCLogParser)parser).pushIfWaitingForCpuTime(event);
}
private static boolean parseGenerationCollection(AbstractGCLogParser parser, ParseRuleContext context, String s) {
MemoryArea area = MemoryArea.getMemoryArea(s);
if (area == null) {
return false;
}
// put the collection on the correct event
GCModel model = parser.getModel();
GCEvent event = model.getLastEventOfType(YOUNG_FULL_GC);
if (event == null) {
return true;
}
GCMemoryItem collection = ((GCEvent) context.get(EVENT)).getMemoryItem(HEAP);
if (collection == null) {
return true;
}
collection.setArea(area);
event.setMemoryItem(collection);
return true;
}
@Override
protected void doParseFullSentence(String sentence) {
doParseUsingRules(this, new ParseRuleContext(), sentence, fullSentenceRules);
}
@Override
protected void doParseGCTraceTime(GCEvent event, String title) {
ParseRuleContext context = new ParseRuleContext();
context.put(EVENT, event);
doParseUsingRules(this, context, title, gcTraceTimeRules);
}
@Override
protected GCEvent getReferenceGCEvent() {
return getModel().getLastEventOfType(REFERENCE_GC_TYPES);
}
@Override
protected List<GCEventType> getCPUTimeGCEvent() {
return CPU_TIME_TYPES;
}
private static GCEventType getGCEventType(String eventString) {
switch (eventString) {
case "concurrent mode interrupted":
return CMS_CONCURRENT_INTERRUPTED;
case "concurrent mode failure":
return CMS_CONCURRENT_FAILURE;
case "CMS Initial Mark":
return CMS_INITIAL_MARK;
case "CMS-concurrent-mark":
return CMS_CONCURRENT_MARK;
case "CMS-concurrent-preclean":
return CMS_CONCURRENT_PRECLEAN;
case "CMS-concurrent-abortable-preclean":
return CMS_CONCURRENT_ABORTABLE_PRECLEAN;
case "CMS Final Remark":
return CMS_FINAL_REMARK;
case "Rescan":
return CMS_RESCAN;
case "weak refs processing":
return WEAK_REFS_PROCESSING;
case "class unloading":
return CMS_CLASS_UNLOADING;
case "scrub symbol table":
return CMS_SCRUB_SYMBOL_TABLE;
case "scrub string table":
return CMS_SCRUB_STRING_TABLE;
case "CMS-concurrent-sweep":
return CMS_CONCURRENT_SWEEP;
case "CMS-concurrent-reset":
return CMS_CONCURRENT_RESET;
default:
ErrorUtil.shouldNotReachHere();
}
return null;
}
}
| 6,755 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/GCLogParser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import org.eclipse.jifa.gclog.model.GCModel;
import java.io.BufferedReader;
public interface GCLogParser {
GCModel parse(BufferedReader br) throws Exception;
}
| 6,756 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/GCLogParserFactory.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.eclipse.jifa.common.JifaException;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.model.modeInfo.GCLogStyle;
import java.io.BufferedReader;
import static org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType.*;
import static org.eclipse.jifa.gclog.model.modeInfo.GCLogStyle.PRE_UNIFIED;
import static org.eclipse.jifa.gclog.model.modeInfo.GCLogStyle.UNIFIED;
public class GCLogParserFactory {
static final int MAX_ATTEMPT_LINE = 1000;
private static final ParserMetadataRule[] rules = {
// style
new ParserMetadataRule("[Times:", PRE_UNIFIED, GCCollectorType.UNKNOWN),
new ParserMetadataRule(": [GC", PRE_UNIFIED, GCCollectorType.UNKNOWN),
new ParserMetadataRule("[info]", UNIFIED, GCCollectorType.UNKNOWN),
new ParserMetadataRule("[gc]", UNIFIED, GCCollectorType.UNKNOWN),
// collector
new ParserMetadataRule("PSYoungGen", GCLogStyle.UNKNOWN, PARALLEL),
new ParserMetadataRule("DefNew", GCLogStyle.UNKNOWN, SERIAL),
new ParserMetadataRule("ParNew", GCLogStyle.UNKNOWN, CMS),
new ParserMetadataRule("CMS", GCLogStyle.UNKNOWN, CMS),
new ParserMetadataRule("Pre Evacuate Collection Set", UNIFIED, G1),
new ParserMetadataRule("G1 Evacuation Pause", GCLogStyle.UNKNOWN, G1),
new ParserMetadataRule("Eden regions", UNIFIED, G1),
new ParserMetadataRule("[GC Worker Start (ms): ", GCLogStyle.UNKNOWN, G1),
new ParserMetadataRule("[concurrent-root-region-scan-start", GCLogStyle.UNKNOWN, G1),
new ParserMetadataRule("Concurrent Scan Root Regions", GCLogStyle.UNKNOWN, G1),
new ParserMetadataRule("Concurrent Reset Relocation Set", UNIFIED, ZGC),
new ParserMetadataRule("=== Garbage Collection Statistics ===", UNIFIED, ZGC),
new ParserMetadataRule("Pause Init Update Refs", UNIFIED, SHENANDOAH),
new ParserMetadataRule("Using Concurrent Mark Sweep", UNIFIED, CMS),
new ParserMetadataRule("Using G1", UNIFIED, G1),
new ParserMetadataRule("Using Parallel", UNIFIED, PARALLEL),
new ParserMetadataRule("Using Serial", UNIFIED, SERIAL),
new ParserMetadataRule("Using Shenandoah", UNIFIED, SHENANDOAH),
new ParserMetadataRule("Using The Z Garbage Collector", UNIFIED, ZGC),
};
public GCLogParser getParser(BufferedReader br) {
GCLogParsingMetadata metadata = getMetadata(br);
return createParser(metadata);
}
private GCLogParsingMetadata getMetadata(BufferedReader br) {
GCLogParsingMetadata result = new GCLogParsingMetadata(GCCollectorType.UNKNOWN, GCLogStyle.UNKNOWN);
try {
complete:
for (int i = 0; i < MAX_ATTEMPT_LINE; i++) {
String line = br.readLine();
if (line == null) {
break;
}
// Don't read this line in case users are using wrong arguments
if (line.startsWith("CommandLine flags: ")) {
continue;
}
for (ParserMetadataRule rule : rules) {
if (!line.contains(rule.getText())) {
continue;
}
if (result.getStyle() == GCLogStyle.UNKNOWN) {
result.setStyle(rule.getStyle());
}
if (result.getCollector() == GCCollectorType.UNKNOWN) {
result.setCollector(rule.getCollector());
}
if (result.getCollector() != GCCollectorType.UNKNOWN && result.getStyle() != GCLogStyle.UNKNOWN) {
break complete;
}
}
}
} catch (Exception e) {
// do nothing, hopefully we have got enough information
}
return result;
}
private GCLogParser createParser(GCLogParsingMetadata metadata) {
AbstractGCLogParser parser = null;
if (metadata.getStyle() == PRE_UNIFIED) {
switch (metadata.getCollector()) {
case SERIAL:
case PARALLEL:
case CMS:
case UNKNOWN:
parser = new PreUnifiedGenerationalGCLogParser();
break;
case G1:
parser = new PreUnifiedG1GCLogParser();
break;
default:
ErrorUtil.shouldNotReachHere();
}
} else if (metadata.getStyle() == UNIFIED) {
switch (metadata.getCollector()) {
case SERIAL:
case PARALLEL:
case CMS:
case UNKNOWN:
parser = new UnifiedGenerationalGCLogParser();
break;
case G1:
parser = new UnifiedG1GCLogParser();
break;
case ZGC:
parser = new UnifiedZGCLogParser();
break;
case SHENANDOAH:
throw new JifaException("Shenandoah is not supported.");
default:
ErrorUtil.shouldNotReachHere();
}
} else {
throw new JifaException("Can not recognize format. Is this really a gc log?");
}
parser.setMetadata(metadata);
return parser;
}
@Data
@AllArgsConstructor
private static class ParserMetadataRule {
private String text;
private GCLogStyle style;
private GCCollectorType collector;
}
}
| 6,757 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/ParseRule.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import org.eclipse.jifa.gclog.util.FourConsumer;
import org.eclipse.jifa.gclog.util.GCLogUtil;
import org.eclipse.jifa.gclog.util.TriConsumer;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public interface ParseRule {
/**
* parse rule itself should be stateless, so that it can be shared by threads
*
* @param parser to save any parse result and state
* @param text text to parse
* @param context provide addition information. or enable acceptRule to pass some result to doParse if return true
* @return true if this rule can parse the text
*/
boolean doParse(AbstractGCLogParser parser, ParseRuleContext context, String text);
class ParseRuleContext {
public static final String UPTIME = "uptime";
public static final String GCID = "gcid";
public static final String EVENT = "event";
private Map<String, Object> map;
public void put(String key, Object value) {
map.put(key, value);
}
@SuppressWarnings("unchecked")
public <T> T get(String key) {
return (T) map.getOrDefault(key, null);
}
public ParseRuleContext() {
this.map = new HashMap<>();
}
}
// here we encapsulate some common types of rules
// e.g as to "Heap: 1g" then prefix is "Heap" or "Heap:", value is "1g"
class PrefixAndValueParseRule implements ParseRule {
private String prefix;
private FourConsumer<AbstractGCLogParser, ParseRuleContext, String, String> consumer;
public PrefixAndValueParseRule(String prefix, FourConsumer<AbstractGCLogParser, ParseRuleContext, String, String> consumer) {
this.prefix = prefix;
this.consumer = consumer;
}
@Override
public boolean doParse(AbstractGCLogParser parser, ParseRuleContext context, String text) {
if (!text.startsWith(prefix)) {
return false;
}
consumer.accept(parser, context, prefix, GCLogUtil.parseValueOfPrefix(text, prefix));
return true;
}
}
class RegexParseRules implements ParseRule {
private Pattern pattern;
TriConsumer<AbstractGCLogParser, ParseRuleContext, Matcher> consumer;
public RegexParseRules(String pattern, TriConsumer<AbstractGCLogParser, ParseRuleContext, Matcher> consumer) {
this.pattern = Pattern.compile(pattern);
this.consumer = consumer;
}
@Override
public boolean doParse(AbstractGCLogParser parser, ParseRuleContext context, String text) {
Matcher matcher = pattern.matcher(text);
if (!matcher.matches()) {
return false;
}
consumer.accept(parser, context, matcher);
return false;
}
}
class FixedContentParseRule implements ParseRule {
private String content;
private BiConsumer<AbstractGCLogParser, ParseRuleContext> consumer;
public FixedContentParseRule(String content, BiConsumer<AbstractGCLogParser, ParseRuleContext> consumer) {
this.content = content;
this.consumer = consumer;
}
@Override
public boolean doParse(AbstractGCLogParser parser, ParseRuleContext context, String text) {
if (!text.equals(content)) {
return false;
}
consumer.accept(parser, context);
return true;
}
}
}
| 6,758 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/PreUnifiedG1GCLogParser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea;
import org.eclipse.jifa.gclog.event.evnetInfo.GCMemoryItem;
import org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.util.GCLogUtil;
import java.util.ArrayList;
import java.util.List;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
import static org.eclipse.jifa.gclog.parser.ParseRule.*;
import static org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext.EVENT;
public class PreUnifiedG1GCLogParser extends AbstractPreUnifiedGCLogParser {
private final static GCEventType[] REF_GC_TYPES = {YOUNG_GC, FULL_GC, G1_MIXED_GC, G1_REMARK};
private final static GCEventType[] YOUNG_MIXED = {YOUNG_GC, G1_MIXED_GC};
private final static GCEventType[] YOUNG_MIXED_FULL = {YOUNG_GC, G1_MIXED_GC, FULL_GC};
private final static List<GCEventType> CPU_TIME_TYPES = List.of(YOUNG_GC, FULL_GC, G1_MIXED_GC, G1_REMARK, G1_PAUSE_CLEANUP);
/*
* 2021-05-19T22:52:16.311+0800: 3.960: [GC pause (G1 Evacuation Pause) (young)2021-05-19T22:52:16.351+0800: 4.000: [SoftReference, 0 refs, 0.0000435 secs]2021-05-19T22:52:16.352+0800: 4.000: [WeakReference, 374 refs, 0.0002082 secs]2021-05-19T22:52:16.352+0800: 4.001: [FinalReference, 5466 refs, 0.0141707 secs]2021-05-19T22:52:16.366+0800: 4.015: [PhantomReference, 0 refs, 0 refs, 0.0000253 secs]2021-05-19T22:52:16.366+0800: 4.015: [JNI Weak Reference, 0.0000057 secs], 0.0563085 secs]
* [Parallel Time: 39.7 ms, GC Workers: 4]
* [GC Worker Start (ms): Min: 3959.8, Avg: 3959.9, Max: 3960.1, Diff: 0.2]
* [Ext Root Scanning (ms): Min: 2.6, Avg: 10.1, Max: 17.9, Diff: 15.2, Sum: 40.4]
* [Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
* [Processed Buffers: Min: 0, Avg: 0.0, Max: 0, Diff: 0, Sum: 0]
* [Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
* [Code Root Scanning (ms): Min: 0.0, Avg: 0.5, Max: 2.1, Diff: 2.1, Sum: 2.1]
* [Object Copy (ms): Min: 18.1, Avg: 26.2, Max: 33.7, Diff: 15.6, Sum: 104.9]
* [Termination (ms): Min: 0.0, Avg: 1.5, Max: 3.5, Diff: 3.5, Sum: 6.2]
* [Termination Attempts: Min: 1, Avg: 21.8, Max: 51, Diff: 50, Sum: 87]
* [GC Worker Other (ms): Min: 0.0, Avg: 0.1, Max: 0.1, Diff: 0.0, Sum: 0.2]
* [GC Worker Total (ms): Min: 38.0, Avg: 38.5, Max: 39.5, Diff: 1.5, Sum: 153.8]
* [GC Worker End (ms): Min: 3998.0, Avg: 3998.4, Max: 3999.4, Diff: 1.4]
* [Code Root Fixup: 0.2 ms]
* [Code Root Purge: 0.2 ms]
* [Clear CT: 0.2 ms]
* [Other: 16.0 ms]
* [Evacuation Failure: 629.5 ms]
* [Choose CSet: 0.0 ms]
* [Ref Proc: 15.1 ms]
* [Ref Enq: 0.2 ms]
* [Redirty Cards: 0.1 ms]
* [Humongous Register: 0.0 ms]
* [Humongous Reclaim: 0.0 ms]
* [Free CSet: 0.3 ms]
* [Eden: 184.0M(184.0M)->0.0B(160.0M) Survivors: 0.0B->24.0M Heap: 184.0M(3800.0M)->19.3M(3800.0M)]
* [Times: user=0.07 sys=0.01, real=0.06 secs]
* 2021-09-25T08:01:03.268+0800: 78304.230: [GC concurrent-root-region-scan-start]
* 2021-09-25T08:01:03.429+0800: 78304.391: [GC concurrent-root-region-scan-end, 0.1608430 secs]
* 2021-09-25T08:01:03.429+0800: 78304.391: [GC concurrent-mark-start]
* 2021-09-25T08:01:06.138+0800: 78307.101: [GC concurrent-mark-reset-for-overflow]
* 2021-08-25T11:28:23.995+0800: 114394.984: [GC concurrent-mark-abort]
* 2021-09-25T08:01:18.109+0800: 78319.072: [GC concurrent-mark-end, 14.6803750 secs]
* 2021-09-25T08:01:18.115+0800: 78319.078: [GC remark 2021-09-25T08:01:18.115+0800: 78319.078: [Finalize Marking, 0.1774665 secs] 2021-09-25T08:01:18.293+0800: 78319.255: [GC ref-proc, 0.1648116 secs] 2021-09-25T08:01:18.457+0800: 78319.420: [Unloading, 0.1221964 secs], 0.4785858 secs]
* [Times: user=1.47 sys=0.31, real=0.48 secs]
* 2021-09-25T08:01:18.601+0800: 78319.563: [GC cleanup 11G->9863M(20G), 0.0659638 secs]
* [Times: user=0.20 sys=0.01, real=0.07 secs]
* 2021-09-25T08:01:18.667+0800: 78319.630: [GC concurrent-cleanup-start]
* 2021-09-25T08:01:18.668+0800: 78319.631: [GC concurrent-cleanup-end, 0.0010377 secs]
* 2021-05-25T22:41:05.357+0800: 190.521: [Full GC (Allocation Failure) 2691M->476M(2724M), 1.9820132 secs]
* [Eden: 0.0B(1024.0M)->0.0B(1024.0M) Survivors: 0.0B->0.0B Heap: 2691.5M(2724.0M)->476.6M(2724.0M)], [Metaspace: 31984K->31982K(1079296K)]
* [Times: user=2.64 sys=0.17, real=1.98 secs]
* 2021-08-26T15:47:09.545+0800: 414187.453: [GC pause (G1 Evacuation Pause) (young)2021-08-26T15:47:09.611+0800: 414187.519: [SoftReference, 0 refs, 0.0000435 secs]2021-08-26T15:47:09.611+0800: 414187.519: [WeakReference, 0 refs, 0.0000062 secs]2021-08-26T15:47:09.611+0800: 414187.519: [FinalReference, 0 refs, 0.0000052 secs]2021-08-26T15:47:09.611+0800: 414187.519: [PhantomReference, 0 refs, 0 refs, 0.0000056 secs]2021-08-26T15:47:09.611+0800: 414187.519: [JNI Weak Reference, 0.0000129 secs] (to-space exhausted), 0.1011364 secs]
* 2021-08-26T15:47:01.710+0800: 414179.619: [GC pause (G1 Evacuation Pause) (mixed)2021-08-26T15:47:01.727+0800: 414179.636: [SoftReference, 0 refs, 0.0000415 secs]2021-08-26T15:47:01.727+0800: 414179.636: [WeakReference, 0 refs, 0.0000061 secs]2021-08-26T15:47:01.727+0800: 414179.636: [FinalReference, 0 refs, 0.0000049 secs]2021-08-26T15:47:01.727+0800: 414179.636: [PhantomReference, 0 refs, 0 refs, 0.0000052 secs]2021-08-26T15:47:01.727+0800: 414179.636: [JNI Weak Reference, 0.0000117 secs] (to-space exhausted), 0.0264971 secs]
* 2021-08-26T15:27:21.061+0800: 243.497: [GC remark 2021-08-26T15:27:21.061+0800: 243.497: [Finalize Marking, 0.0008929 secs] 2021-08-26T15:27:21.062+0800: 243.497: [GC ref-proc2021-08-26T15:27:21.062+0800: 243.497: [SoftReference, 0 refs, 0.0000304 secs]2021-08-26T15:27:21.062+0800: 243.498: [WeakReference, 560 refs, 0.0001581 secs]2021-08-26T15:27:21.062+0800: 243.498: [FinalReference, 22 refs, 0.0000966 secs]2021-08-26T15:27:21.062+0800: 243.498: [PhantomReference, 0 refs, 416 refs, 0.0001386 secs]2021-08-26T15:27:21.062+0800: 243.498: [JNI Weak Reference, 0.0000471 secs], 0.0005083 secs] 2021-08-26T15:27:21.062+0800: 243.498: [Unloading, 0.0150698 secs], 0.0414751 secs]
*/
private static List<ParseRule> fullSentenceRules;
private static List<ParseRule> gcTraceTimeRules;
static {
initializeParseRules();
}
private static void initializeParseRules() {
fullSentenceRules = new ArrayList<>();
fullSentenceRules.add(commandLineRule);
fullSentenceRules.add(cpuTimeRule);
fullSentenceRules.add(new FixedContentParseRule(" (to-space exhausted)", PreUnifiedG1GCLogParser::parseToSpaceExhausted));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Eden", PreUnifiedG1GCLogParser::parseMemoryChange));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Parallel Time", PreUnifiedG1GCLogParser::parseParallelWorker));
// some phases are ignored
fullSentenceRules.add(new PrefixAndValueParseRule(" [Ext Root Scanning", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Update RS", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Scan RS", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Code Root Scanning", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Object Copy", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Termination", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Code Root Fixup", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Code Root Purge", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Clear CT", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Evacuation Failure", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Choose CSet", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Ref Proc", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Ref Enq", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Redirty Cards", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Humongous Register", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Humongous Reclaim", PreUnifiedG1GCLogParser::parseYoungGCPhase));
fullSentenceRules.add(new PrefixAndValueParseRule(" [Free CSet", PreUnifiedG1GCLogParser::parseYoungGCPhase));
gcTraceTimeRules = new ArrayList<>();
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC concurrent-root-region-scan", PreUnifiedG1GCLogParser::parseConcurrentCyclePhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC concurrent-mark-reset-for-overflow", PreUnifiedG1GCLogParser::parseConcurrentCyclePhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC concurrent-mark-abort", PreUnifiedG1GCLogParser::parseConcurrentCyclePhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC concurrent-mark", PreUnifiedG1GCLogParser::parseConcurrentCyclePhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC remark", PreUnifiedG1GCLogParser::parseConcurrentCyclePhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("Finalize Marking", PreUnifiedG1GCLogParser::parseConcurrentCyclePhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC ref-proc", PreUnifiedG1GCLogParser::parseConcurrentCyclePhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("Unloading", PreUnifiedG1GCLogParser::parseConcurrentCyclePhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC cleanup", PreUnifiedG1GCLogParser::parseConcurrentCyclePhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC concurrent-cleanup", PreUnifiedG1GCLogParser::parseConcurrentCyclePhase));
gcTraceTimeRules.add(new PrefixAndValueParseRule("GC pause", PreUnifiedG1GCLogParser::parseYoungMixedFullGC));
gcTraceTimeRules.add(new PrefixAndValueParseRule("Full GC", PreUnifiedG1GCLogParser::parseYoungMixedFullGC));
}
private static void parseParallelWorker(AbstractGCLogParser parser, ParseRuleContext context, String prefix, String value) {
int worker = Integer.parseInt(value.substring(value.lastIndexOf(' ') + 1, value.length() - 1));
parser.getModel().setParallelThread(worker);
}
private static void parseConcurrentCyclePhase(AbstractGCLogParser parser, ParseRuleContext context, String phaseName, String value) {
GCModel model = parser.getModel();
GCEventType phaseType = getGCEventType(phaseName);
GCEvent phase = context.get(EVENT);
GCEvent parent;
if (phaseType == G1_CONCURRENT_SCAN_ROOT_REGIONS && "-start".equals(value)) {
parent = new GCEvent();
parent.setEventType(G1_CONCURRENT_CYCLE);
parent.setStartTime(phase.getStartTime());
model.putEvent(parent);
} else {
parent = model.getLastEventOfType(G1_CONCURRENT_CYCLE);
}
GCEvent phaseStart = parent.getLastPhaseOfType(phaseType);
if (phaseStart == null) {
phase.setEventType(phaseType);
model.addPhase(parent, phase);
if (phaseType == G1_CONCURRENT_MARK_RESET_FOR_OVERFLOW || phaseType == G1_CONCURRENT_MARK_ABORT) {
phase.setDuration(0);
}
((AbstractPreUnifiedGCLogParser) parser).pushIfWaitingForCpuTime(phase);
} else {
copyPhaseDataToStart(phaseStart, phase);
((AbstractPreUnifiedGCLogParser) parser).pushIfWaitingForCpuTime(phaseStart);
}
}
// " [Eden: 0.0B(1760.0M)->0.0B(2304.0M) Survivors: 544.0M->0.0B Heap: 7521.7M(46144.0M)->7002.8M(46144.0M)], [Metaspace: 1792694K->291615K(698368K)]"
private static void parseMemoryChange(AbstractGCLogParser parser, ParseRuleContext context, String prefix, String value) {
GCEvent event = parser.getModel().getLastEventOfType(YOUNG_MIXED_FULL);
if (event == null) {
return;
}
String[] parts = GCLogUtil.splitBySpace(" [Eden: " + value);
for (int i = 0; i < parts.length; i += 2) {
String areaString = StringUtils.strip(parts[i], "[:");
MemoryArea area = MemoryArea.getMemoryArea(areaString);
String memoryChangeString = StringUtils.strip(parts[i + 1], ",]");
long[] memories = GCLogUtil.parseMemorySizeFromTo(memoryChangeString);
GCMemoryItem item = new GCMemoryItem(area, memories);
event.setMemoryItem(item, true);
}
}
private static void parseToSpaceExhausted(AbstractGCLogParser parser, ParseRuleContext context) {
GCEvent event = parser.getModel().getLastEventOfType(YOUNG_MIXED);
if (event == null) {
return;
}
event.setTrue(GCEventBooleanType.TO_SPACE_EXHAUSTED);
}
@Override
protected void doParseFullSentence(String sentence) {
doParseUsingRules(this, new ParseRuleContext(), sentence, fullSentenceRules);
}
@Override
protected void doParseGCTraceTime(GCEvent event, String title) {
ParseRuleContext context = new ParseRuleContext();
context.put(EVENT, event);
doParseUsingRules(this, context, title, gcTraceTimeRules);
}
// [Ext Root Scanning (ms): Min: 2.6, Avg: 10.1, Max: 17.9, Diff: 15.2, Sum: 40.4]
// [Code Root Fixup: 0.2 ms]
private static void parseYoungGCPhase(AbstractGCLogParser parser, ParseRuleContext context, String prefix, String value) {
GCEvent parent = parser.getModel().getLastEventOfType(YOUNG_MIXED);
if (parent == null) {
return;
}
GCEvent phase = new GCEvent();
// no way to know it exactly, just copy parent's
phase.setStartTime(parent.getStartTime());
String phaseName = prefix.substring(prefix.indexOf('[') + 1);
phase.setEventType(getGCEventType(phaseName));
int durationIndexBegin, durationIndexEnd;
if (value.endsWith(" ms]")) {
durationIndexEnd = value.length() - " ms]".length();
durationIndexBegin = value.lastIndexOf(' ', durationIndexEnd - 1) + 1;
} else {
durationIndexBegin = value.indexOf("Avg: ") + "Avg: ".length();
durationIndexEnd = value.indexOf(',', durationIndexBegin);
}
double duration = Double.parseDouble(value.substring(durationIndexBegin, durationIndexEnd));
phase.setDuration(duration);
parser.getModel().addPhase(parent, phase);
}
private static void parseYoungMixedFullGC(AbstractGCLogParser parser, ParseRuleContext context, String prefix, String value) {
GCEventType eventType = prefix.equals("GC pause") ? YOUNG_GC : FULL_GC;
GCEvent event = context.get(EVENT);
String[] causes = GCLogUtil.splitByBracket(value);
for (int i = 0; i < causes.length; i++) {
String cause = causes[i];
// to space exhausted is not considered here because it is not printed together with other brackets
if (cause.equals("mixed")) {
eventType = G1_MIXED_GC;
} else if (cause.equals("young")) {
eventType = YOUNG_GC;
} else if (cause.equals("initial-mark")) {
event.setTrue(GCEventBooleanType.INITIAL_MARK);
} else if (i == 0) {
event.setCause(cause);
}
}
event.setEventType(eventType);
parser.getModel().putEvent(event);
((AbstractPreUnifiedGCLogParser) parser).pushIfWaitingForCpuTime(event);
}
@Override
protected GCEvent getReferenceGCEvent() {
return getModel().getLastEventOfType(REF_GC_TYPES);
}
@Override
protected List<GCEventType> getCPUTimeGCEvent() {
return CPU_TIME_TYPES;
}
private static GCEventType getGCEventType(String eventString) {
switch (eventString) {
case "Ext Root Scanning":
return G1_EXT_ROOT_SCANNING;
case "Update RS":
return G1_UPDATE_RS;
case "Scan RS":
return G1_SCAN_RS;
case "Code Root Scanning":
return G1_CODE_ROOT_SCANNING;
case "Object Copy":
return G1_OBJECT_COPY;
case "Termination":
return G1_TERMINATION;
case "Code Root Fixup":
return G1_CODE_ROOT_FIXUP;
case "Code Root Purge":
return G1_CODE_ROOT_PURGE;
case "Clear CT":
return G1_CLEAR_CT;
case "Evacuation Failure":
return G1_EVACUATION_FAILURE;
case "Choose CSet":
return G1_CHOOSE_CSET;
case "Ref Proc":
case "GC ref-proc":
return G1_GC_REFPROC;
case "Ref Enq":
return G1_REF_ENQ;
case "Redirty Cards":
return G1_REDIRTY_CARDS;
case "Humongous Register":
return G1_HUMONGOUS_REGISTER;
case "Humongous Reclaim":
return G1_HUMONGOUS_RECLAIM;
case "Free CSet":
return G1_FREE_CSET;
case "GC concurrent-root-region-scan":
return G1_CONCURRENT_SCAN_ROOT_REGIONS;
case "GC concurrent-mark":
return G1_CONCURRENT_MARK;
case "GC concurrent-mark-reset-for-overflow":
return G1_CONCURRENT_MARK_RESET_FOR_OVERFLOW;
case "GC concurrent-mark-abort":
return G1_CONCURRENT_MARK_ABORT;
case "GC remark":
return G1_REMARK;
case "Finalize Marking":
return G1_FINALIZE_MARKING;
case "Unloading":
return G1_UNLOADING;
case "GC cleanup":
return G1_PAUSE_CLEANUP;
case "GC concurrent-cleanup":
return G1_CONCURRENT_CLEANUP_FOR_NEXT_MARK;
default:
ErrorUtil.shouldNotReachHere();
}
return null;
}
}
| 6,759 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/GCLogParsingMetadata.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.model.modeInfo.GCLogStyle;
@Data
@AllArgsConstructor
public class GCLogParsingMetadata {
private GCCollectorType collector;
private GCLogStyle style;
}
| 6,760 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/AbstractUnifiedGCLogParser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import com.google.common.collect.Sets;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.util.Constant;
import org.eclipse.jifa.gclog.util.GCLogUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import static org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext.UPTIME;
/*
* Currently, we only consider -Xlog:gc*=info. We will continue support for cases in the future.
*/
public abstract class AbstractUnifiedGCLogParser extends AbstractGCLogParser {
private static List<ParseRule> withoutGCIDRules;
private static List<ParseRule> withGCIDRules;
public static List<ParseRule> getSharedWithoutGCIDRules() {
return withoutGCIDRules;
}
public static List<ParseRule> getSharedWithGCIDRules() {
return withGCIDRules;
}
static {
initializeParseRules();
}
private static void initializeParseRules() {
withoutGCIDRules = new ArrayList<>();
withoutGCIDRules.add(new ParseRule.PrefixAndValueParseRule("Total time for which application",
(parser, context, prefix, s) -> parser.parseSafepointStop(context.get(UPTIME), s)));
withGCIDRules = new ArrayList<>();
// subclass will add more rules
}
@Override
protected final void doParseLine(String line) {
JDK11LogLine logLine = parseJDK11LogLine(line);
if (logLine == null || !logLine.isValid()) {
return;
}
doBeforeParsingLine(logLine);
if (logLine.getGcid() == Constant.UNKNOWN_INT) {
doParseLineWithoutGCID(logLine.getDetail(), logLine.getUptime());
} else {
// in jdk11 gcid is always logged
doParseLineWithGCID(logLine.getDetail(), logLine.getGcid(), logLine.getUptime());
}
}
protected abstract void doParseLineWithGCID(String detail, int gcid, double uptime);
protected abstract void doParseLineWithoutGCID(String detail, double uptime);
private void doBeforeParsingLine(JDK11LogLine logLine) {
double uptime = logLine.getUptime();
GCModel model = getModel();
// set model reference timestamp
if (model.getReferenceTimestamp() == Constant.UNKNOWN_LONG && logLine.getTimestamp() != Constant.UNKNOWN_LONG) {
double startTimestamp = uptime == Constant.UNKNOWN_DOUBLE ? logLine.getTimestamp()
: logLine.getTimestamp() - uptime;
model.setReferenceTimestamp(startTimestamp);
}
// set event start time
if (logLine.getUptime() == Constant.UNKNOWN_DOUBLE) {
logLine.setUptime(logLine.getTimestamp() - model.getReferenceTimestamp());
}
// set model start and end time
if (model.getStartTime() == Constant.UNKNOWN_DOUBLE) {
model.setStartTime(uptime);
}
model.setEndTime(Math.max(uptime, model.getEndTime()));
}
@Data
@AllArgsConstructor
@NoArgsConstructor
private static class JDK11LogLine {
private String timestampString = null;
private long timestamp = Constant.UNKNOWN_LONG;
private double uptime = Constant.UNKNOWN_DOUBLE;
private String loglevel;
private List<String> tags;
private int gcid = Constant.UNKNOWN_INT;
private String detail;
// parsing timestamp is expensive, do it lazily
public long getTimestamp() {
if (timestamp == Constant.UNKNOWN_LONG && timestampString != null) {
timestamp = GCLogUtil.parseDateStamp(timestampString);
}
return timestamp;
}
public boolean isValid() {
if (timestamp == Constant.UNKNOWN_LONG && timestampString == null
&& getUptime() == Constant.UNKNOWN_DOUBLE) { // need at least one
return false;
}
if (getLoglevel() != null && !"info".equals(getLoglevel())) { // parse info level only now
return false;
}
if (getTags() != null && !getTags().contains("gc")) { // need gc tag
return false;
}
return true;
}
}
/**
* [2021-05-06T11:25:16.508+0800][2021-05-06T03:25:16.508+0000][0.202s][1620271516508ms][202ms][1489353078113131ns][201765461ns][B-K0S4ML7L-0237.local][45473][14083][info][gc,start ] GC(0) Pause Young (Normal) (G1 Evacuation Pause)
* A line in log may have multiple optimal decorations and some of them are redundant.
* timestamp: [2021-05-06T11:25:16.508+0800][2021-05-06T03:25:16.508+0000][1620271516508ms][1489353078113131ns][201765461ns]
* uptime: [0.202s][202ms]
* logLevel: info
* tags: gc,start
* detail: GC(0) Pause Young (Normal) (G1 Evacuation Pause)
* Either timestamp or uptime is necessary. Detail is necessary.
* Other decorations are useless to us.
* see https://docs.oracle.com/javase/9/tools/java.htm#JSWOR-GUID-9569449C-525F-4474-972C-4C1F63D5C357 Decorations chapter
*/
private JDK11LogLine parseJDK11LogLine(String line) {
if (StringUtils.isBlank(line)) {
return null;
}
JDK11LogLine logLine = new JDK11LogLine();
int leftBracketIndex = line.indexOf('[');
int rightBracketIndex = -1;
while (leftBracketIndex != -1) {
rightBracketIndex = line.indexOf(']', leftBracketIndex + 1);
String decoration = line.substring(leftBracketIndex + 1, rightBracketIndex).trim();
parseDecoration(logLine, decoration);
leftBracketIndex = line.indexOf('[', rightBracketIndex + 1);
}
String remains = line.substring(rightBracketIndex + 1).trim();
if (remains.startsWith("GC(")) {
int right = remains.indexOf(')');
logLine.setGcid(Integer.parseInt(remains.substring(3, right)));
logLine.setDetail(remains.substring(right + 2));
} else {
logLine.setDetail(remains);
}
return logLine;
}
// parse and fill a decoration
// return false if there is no need to continue parsing other info
private static final double TEN_YEAR_MILLISECOND = 10 * 365.25 * 24 * 60 * 60 * 1000;
private void parseDecoration(JDK11LogLine logLine, String decoration) {
if (GCLogUtil.isDatestamp(decoration)) {
logLine.setTimestampString(decoration);
} else if (Character.isDigit(decoration.charAt(0)) && decoration.endsWith("s")) {
double period = GCLogUtil.toMillisecond(decoration);
// this may be either a timestamp or an uptime. we have no way to know which.
// just assume period longer than 10 years as timestamp
if (period > TEN_YEAR_MILLISECOND) {
logLine.setTimestamp((long) period);
} else {
logLine.setUptime(period);
}
} else if (isLoglevel(decoration)) {
logLine.setLoglevel(decoration);
} else if (decoration.contains("gc")) {
logLine.setTags(Arrays.asList(decoration.trim().split(",")));
}
}
private final static Set<String> LOG_LEVEL_SET = Sets.newHashSet("error", "warning", "info", "debug", "trace");
private boolean isLoglevel(String decoration) {
return LOG_LEVEL_SET.contains(decoration);
}
}
| 6,761 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/parser/AbstractGCLogParser.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.parser;
import org.eclipse.jifa.gclog.event.Safepoint;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.model.GCModelFactory;
import org.eclipse.jifa.gclog.parser.ParseRule.ParseRuleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.util.List;
import static org.eclipse.jifa.gclog.util.Constant.MS2S;
public abstract class AbstractGCLogParser implements GCLogParser {
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractGCLogParser.class);
private GCModel model;
private GCLogParsingMetadata metadata;
public GCLogParsingMetadata getMetadata() {
return metadata;
}
public void setMetadata(GCLogParsingMetadata metadata) {
this.metadata = metadata;
}
protected GCModel getModel() {
return model;
}
// for the sake of performance, will try to use less regular expression
public final GCModel parse(BufferedReader br) throws Exception {
model = GCModelFactory.getModel(metadata.getCollector());
model.setLogStyle(metadata.getStyle());
String line;
while ((line = br.readLine()) != null) {
try {
if (line.length() > 0) {
doParseLine(line);
}
} catch (Exception e) {
LOGGER.debug("fail to parse \"{}\", {}", line, e.getMessage());
}
}
try {
endParsing();
} catch (Exception e) {
LOGGER.debug("fail to parse \"{}\", {}", line, e.getMessage());
}
return model;
}
protected abstract void doParseLine(String line);
protected void endParsing() {
}
// return true if text can be parsed by any rule
// order of rules matters
protected boolean doParseUsingRules(AbstractGCLogParser parser, ParseRuleContext context, String text, List<ParseRule> rules) {
for (ParseRule rule : rules) {
if (rule.doParse(parser, context, text)) {
return true;
}
}
return false;
}
// Total time for which application threads were stopped: 0.0001215 seconds, Stopping threads took: 0.0000271 seconds
protected void parseSafepointStop(double uptime, String s) {
int begin = s.indexOf("stopped: ") + "stopped: ".length();
int end = s.indexOf(" seconds, ");
double duration = Double.parseDouble(s.substring(begin, end)) * MS2S;
begin = s.lastIndexOf("took: ") + "took: ".length();
end = s.lastIndexOf(" seconds");
double timeToEnter = Double.parseDouble(s.substring(begin, end)) * MS2S;
Safepoint safepoint = new Safepoint();
// safepoint is printed at the end of it
safepoint.setStartTime(uptime - duration);
safepoint.setDuration(duration);
safepoint.setTimeToEnter(timeToEnter);
getModel().addSafepoint(safepoint);
}
}
| 6,762 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/G1GCModel.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType;
import org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea;
import org.eclipse.jifa.gclog.event.evnetInfo.GCMemoryItem;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.model.modeInfo.GCLogStyle;
import org.eclipse.jifa.gclog.util.LongData;
import org.eclipse.jifa.gclog.vo.TimeRange;
import java.util.Arrays;
import java.util.List;
import static org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType.*;
import static org.eclipse.jifa.gclog.util.Constant.*;
import static org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea.*;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
public class G1GCModel extends GCModel {
private long heapRegionSize = UNKNOWN_INT; // in b
private boolean regionSizeExact = false;
private static GCCollectorType collector = GCCollectorType.G1;
public void setRegionSizeExact(boolean regionSizeExact) {
this.regionSizeExact = regionSizeExact;
}
public void setHeapRegionSize(long heapRegionSize) {
this.heapRegionSize = heapRegionSize;
}
public long getHeapRegionSize() {
return heapRegionSize;
}
public G1GCModel() {
super(collector);
}
private static List<GCEventType> allEventTypes = GCModel.calcAllEventTypes(collector);
private static List<GCEventType> pauseEventTypes = GCModel.calcPauseEventTypes(collector);
private static List<GCEventType> mainPauseEventTypes = GCModel.calcMainPauseEventTypes(collector);
private static List<GCEventType> parentEventTypes = GCModel.calcParentEventTypes(collector);
private static List<GCEventType> importantEventTypes = List.of(YOUNG_GC, G1_MIXED_GC, FULL_GC, G1_CONCURRENT_CYCLE,
G1_CONCURRENT_MARK, G1_REMARK, G1_CONCURRENT_REBUILD_REMEMBERED_SETS, G1_PAUSE_CLEANUP, G1_CONCURRENT_UNDO_CYCLE);
@Override
protected List<GCEventType> getAllEventTypes() {
return allEventTypes;
}
@Override
protected List<GCEventType> getPauseEventTypes() {
return pauseEventTypes;
}
@Override
protected List<GCEventType> getMainPauseEventTypes() {
return mainPauseEventTypes;
}
@Override
protected List<GCEventType> getImportantEventTypes() {
return importantEventTypes;
}
@Override
protected List<GCEventType> getParentEventTypes() {
return parentEventTypes;
}
private boolean collectionResultUsingRegion(GCEvent event) {
GCEventType type = event.getEventType();
return (type == YOUNG_GC || type == FULL_GC || type == G1_MIXED_GC) && event.getMemoryItems() != null;
}
private static List<MemoryArea> AREAS_COUNTED_BY_REGION = List.of(EDEN, SURVIVOR, OLD, HUMONGOUS, ARCHIVE);
private void inferHeapRegionSize() {
if (heapRegionSize != UNKNOWN_INT) {
return;
}
for (int i = getGcEvents().size() - 1; i >= 0; i--) {
GCEvent event = getGcEvents().get(i);
if (!collectionResultUsingRegion(event)) {
continue;
}
if (event.getMemoryItem(HEAP).getPreUsed() == UNKNOWN_INT) {
continue;
}
long regionCount = Arrays.stream(event.getMemoryItems())
.filter(item -> item != null && AREAS_COUNTED_BY_REGION.contains(item.getArea())
&& item.getPreUsed() != UNKNOWN_INT)
.mapToLong(GCMemoryItem::getPreUsed)
.sum();
if (regionCount < 3) {
continue;
}
double bytesPerRegion = event.getMemoryItem(HEAP).getPreUsed() / (double) regionCount;
heapRegionSize = (long) Math.pow(2, Math.ceil(Math.log(bytesPerRegion) / Math.log(2)));
return;
}
}
private void adjustMemoryInfo() {
if (heapRegionSize == UNKNOWN_INT) {
return;
}
for (GCEvent event : getGcEvents()) {
if (!collectionResultUsingRegion(event)) {
continue;
}
for (GCMemoryItem item : event.getMemoryItems()) {
if (item != null && AREAS_COUNTED_BY_REGION.contains(item.getArea())) {
item.multiply(heapRegionSize);
}
}
}
}
@Override
protected void doBeforeCalculatingDerivedInfo() {
if (getLogStyle() == GCLogStyle.UNIFIED) {
inferHeapRegionSize();
adjustMemoryInfo();
}
}
@Override
protected void doAfterCalculatingDerivedInfo() {
decideGCsAfterOldGC();
}
private void decideGCsAfterOldGC() {
GCEvent lastGCInCycle = null;
double lastRemarkEndTime = Double.MAX_VALUE;
double lastConcCycleEndTime = Double.MAX_VALUE;
for (GCEvent event : getGcEvents()) {
GCEventType type = event.getEventType();
if (type == G1_CONCURRENT_UNDO_CYCLE) {
continue;
}
if (type == G1_CONCURRENT_CYCLE) {
if (event.containPhase(G1_CONCURRENT_MARK_ABORT)) {
return;
}
lastConcCycleEndTime = event.getEndTime();
GCEvent remark = event.getLastPhaseOfType(G1_REMARK);
if (remark != null) {
lastRemarkEndTime = remark.getEndTime();
}
}
if (type == FULL_GC || type == YOUNG_GC || type == G1_MIXED_GC) {
if (event.getStartTime() > lastRemarkEndTime) {
event.setTrue(GCEventBooleanType.GC_AFTER_REMARK);
lastRemarkEndTime = Double.MAX_VALUE;
}
if (event.getStartTime() >= lastConcCycleEndTime) {
if (type == FULL_GC) {
// a full gc interrupts mixed gcs
event.setTrue(GC_AT_END_OF_OLD_CYCLE);
lastGCInCycle = null;
lastConcCycleEndTime = Double.MAX_VALUE;
} else if (lastGCInCycle == null) {
lastGCInCycle = event;
if (type == YOUNG_GC && getLogStyle() == GCLogStyle.PRE_UNIFIED) {
// jdk8 does not print Prepare Mixed, add this sign for easier
// future analysis
event.setTrue(GCEventBooleanType.PREPARE_MIXED);
}
} else if (type == YOUNG_GC) {
// we have found the end of mixed gcs
lastGCInCycle.setTrue(GC_AT_END_OF_OLD_CYCLE);
lastGCInCycle = null;
lastConcCycleEndTime = Double.MAX_VALUE;
} else if (type == G1_MIXED_GC) {
lastGCInCycle = event;
}
}
}
}
}
@Override
protected void calculateUsedAvgAfterOldGC(TimeRange range, LongData[][] data) {
iterateEventsWithinTimeRange(getGcEvents(), range, event -> {
// read old from the last gc of old gc cycle
if (event.isTrue(GC_AT_END_OF_OLD_CYCLE) && event.getMemoryItem(OLD) != null) {
data[1][3].add(event.getMemoryItem(OLD).getPostUsed());
}
// read humongous and metaspace from the gc after remark
if (event.isTrue(GC_AFTER_REMARK)) {
if (event.getMemoryItem(HUMONGOUS) != null) {
data[2][3].add(event.getMemoryItem(HUMONGOUS).getPreUsed());
}
if (event.getMemoryItem(METASPACE) != null) {
data[4][3].add(event.getMemoryItem(METASPACE).getPreUsed());
}
}
});
}
}
| 6,763 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/UnknownGCModel.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import java.util.List;
import static org.eclipse.jifa.gclog.model.GCEventType.FULL_GC;
import static org.eclipse.jifa.gclog.model.GCEventType.YOUNG_GC;
// If we can not recognize collector of the log, it is very likely to be cms/serial/parallel
public class UnknownGCModel extends GenerationalGCModel {
private static GCCollectorType collector = GCCollectorType.UNKNOWN;
public UnknownGCModel() {
super(collector);
}
private static List<GCEventType> allEventTypes = GCModel.calcAllEventTypes(collector);
private static List<GCEventType> pauseEventTypes = GCModel.calcPauseEventTypes(collector);
private static List<GCEventType> mainPauseEventTypes = GCModel.calcMainPauseEventTypes(collector);
private static List<GCEventType> parentEventTypes = GCModel.calcParentEventTypes(collector);
private static List<GCEventType> importantEventTypes = List.of(YOUNG_GC, FULL_GC);
@Override
protected List<GCEventType> getAllEventTypes() {
return allEventTypes;
}
@Override
protected List<GCEventType> getPauseEventTypes() {
return pauseEventTypes;
}
@Override
protected List<GCEventType> getMainPauseEventTypes() {
return mainPauseEventTypes;
}
@Override
protected List<GCEventType> getImportantEventTypes() {
return importantEventTypes;
}
@Override
protected List<GCEventType> getParentEventTypes() {
return parentEventTypes;
}
}
| 6,764 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/GCEventType.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model;
import org.eclipse.jifa.gclog.event.evnetInfo.GCEventLevel;
import org.eclipse.jifa.gclog.event.evnetInfo.GCPause;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.eclipse.jifa.gclog.event.evnetInfo.GCEventLevel.EVENT;
import static org.eclipse.jifa.gclog.event.evnetInfo.GCEventLevel.PHASE;
import static org.eclipse.jifa.gclog.event.evnetInfo.GCPause.*;
/*
* store all info that may affect the way model is organized and explained
*/
public class GCEventType {
private static List<GCEventType> allEventTypes = new ArrayList<>();
private String name;
private GCPause pause;
private GCEventType[] phaseParentEventType;
private GCEventLevel level;
private List<GCCollectorType> gcs; // which gcs do this event type may occur?
public static final GCEventType UNDEFINED = new GCEventType("Undefined", GCPause.PARTIAL, new GCCollectorType[]{});
// shared gc arrays
private static GCCollectorType[] SERIAL = new GCCollectorType[]{GCCollectorType.SERIAL};
private static GCCollectorType[] PARALLEL = new GCCollectorType[]{GCCollectorType.PARALLEL};
private static GCCollectorType[] CMS = new GCCollectorType[]{GCCollectorType.CMS};
private static GCCollectorType[] G1 = new GCCollectorType[]{GCCollectorType.G1};
private static GCCollectorType[] SHENANDOAH = new GCCollectorType[]{GCCollectorType.SHENANDOAH};
private static GCCollectorType[] ZGC = new GCCollectorType[]{GCCollectorType.ZGC};
private static GCCollectorType[] SERIAL_AND_CMS = new GCCollectorType[]{GCCollectorType.SERIAL, GCCollectorType.CMS};
private static GCCollectorType[] ALL_GCS = new GCCollectorType[]{GCCollectorType.SERIAL, GCCollectorType.PARALLEL, GCCollectorType.G1, GCCollectorType.SHENANDOAH, GCCollectorType.ZGC, GCCollectorType.CMS, GCCollectorType.UNKNOWN};
private static GCCollectorType[] GENERATIONAL_GCS = new GCCollectorType[]{GCCollectorType.SERIAL, GCCollectorType.PARALLEL, GCCollectorType.G1, GCCollectorType.CMS, GCCollectorType.UNKNOWN};
// external event types
public static final GCEventType YOUNG_GC = new GCEventType("Young GC", PAUSE, GENERATIONAL_GCS);
public static final GCEventType G1_MIXED_GC = new GCEventType("Mixed GC", PAUSE, G1);
public static final GCEventType FULL_GC = new GCEventType("Full GC", PAUSE, GENERATIONAL_GCS);
public static final GCEventType G1_CONCURRENT_CYCLE = new GCEventType("Concurrent Mark Cycle", GCPause.PARTIAL, G1);
public static final GCEventType G1_CONCURRENT_UNDO_CYCLE = new GCEventType("Concurrent Undo Cycle", GCPause.PARTIAL, G1);
public static final GCEventType CMS_CONCURRENT_MARK_SWEPT = new GCEventType("CMS", GCPause.PARTIAL, CMS);
public static final GCEventType ZGC_GARBAGE_COLLECTION = new GCEventType("Garbage Collection", PARTIAL, ZGC);
// shared parent
private static final GCEventType[] PARENT_CONCURRENT_MARK_CYCLE = {G1_CONCURRENT_CYCLE, CMS_CONCURRENT_MARK_SWEPT, ZGC_GARBAGE_COLLECTION};
private static final GCEventType[] PARENT_YOUNG_OLD_FULL_GC = {YOUNG_GC, FULL_GC, G1_MIXED_GC};
private static final GCEventType[] PARENT_ZGC = {ZGC_GARBAGE_COLLECTION};
// internal phase types
// shared by serial and cms
public static final GCEventType SERIAL_MARK_LIFE_OBJECTS = new GCEventType("Mark live objects", PAUSE, PARENT_YOUNG_OLD_FULL_GC, SERIAL_AND_CMS);
public static final GCEventType SERIAL_COMPUTE_NEW_OBJECT_ADDRESSES = new GCEventType("Compute new object addresses", PAUSE, PARENT_YOUNG_OLD_FULL_GC, SERIAL_AND_CMS);
public static final GCEventType SERIAL_ADJUST_POINTERS = new GCEventType("Adjust pointers", PAUSE, PARENT_YOUNG_OLD_FULL_GC, SERIAL_AND_CMS);
public static final GCEventType SERIAL_MOVE_OBJECTS = new GCEventType("Move objects", PAUSE, PARENT_YOUNG_OLD_FULL_GC, SERIAL_AND_CMS);
public static final GCEventType WEAK_REFS_PROCESSING = new GCEventType("Reference Processing", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, GCEventLevel.SUBPHASE, CMS);
// Parallel
public static final GCEventType PARALLEL_PHASE_MARKING = new GCEventType("Marking Phase", PAUSE, PARENT_YOUNG_OLD_FULL_GC, PARALLEL);
public static final GCEventType PARALLEL_PHASE_SUMMARY = new GCEventType("Summary Phase", PAUSE, PARENT_YOUNG_OLD_FULL_GC, PARALLEL);
public static final GCEventType PARALLEL_PHASE_ADJUST_ROOTS = new GCEventType("Adjust Roots", PAUSE, PARENT_YOUNG_OLD_FULL_GC, PARALLEL);
public static final GCEventType PARALLEL_PHASE_COMPACTION = new GCEventType("Compaction Phase", PAUSE, PARENT_YOUNG_OLD_FULL_GC, PARALLEL);
public static final GCEventType PARALLEL_PHASE_POST_COMPACT = new GCEventType("Post Compact", PAUSE, PARENT_YOUNG_OLD_FULL_GC, PARALLEL);
// G1
public static final GCEventType G1_COLLECT_PRE_EVACUATION = new GCEventType("Pre Evacuate Collection Set", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_MERGE_HEAP_ROOTS = new GCEventType("Merge Heap Roots", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_COLLECT_EVACUATION = new GCEventType("Evacuate Collection Set", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_COLLECT_POST_EVACUATION = new GCEventType("Post Evacuate Collection Set", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_COLLECT_OTHER = new GCEventType("Other", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_CONCURRENT_CLEAR_CLAIMED_MARKS = new GCEventType("Concurrent Clear Claimed Marks", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, G1);
public static final GCEventType G1_CONCURRENT_SCAN_ROOT_REGIONS = new GCEventType("Root Region Scanning", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, G1);
public static final GCEventType G1_CONCURRENT_MARK_FROM_ROOTS = new GCEventType("Concurrent Mark From Roots", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, G1);
public static final GCEventType G1_CONCURRENT_PRECLEAN = new GCEventType("Concurrent Preclean", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, G1);
public static final GCEventType G1_CONCURRENT_MARK = new GCEventType("Concurrent Mark", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, G1);
public static final GCEventType G1_CONCURRENT_MARK_RESET_FOR_OVERFLOW = new GCEventType("Concurrent Mark Reset For Overflow", CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, G1);
public static final GCEventType G1_REMARK = new GCEventType("Pause Remark", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, G1);
public static final GCEventType G1_CONCURRENT_REBUILD_REMEMBERED_SETS = new GCEventType("Concurrent Rebuild Remembered Sets", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, G1);
public static final GCEventType G1_PAUSE_CLEANUP = new GCEventType("Pause Cleanup", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, G1);
public static final GCEventType G1_CONCURRENT_CLEANUP_FOR_NEXT_MARK = new GCEventType("Concurrent Cleanup", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, G1);
public static final GCEventType G1_FINALIZE_MARKING = new GCEventType("Finalize Marking", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, GCEventLevel.SUBPHASE, G1);
public static final GCEventType G1_UNLOADING = new GCEventType("Class Unloading", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, GCEventLevel.SUBPHASE, G1);
public static final GCEventType G1_GC_REFPROC = new GCEventType("Reference Processing", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, GCEventLevel.SUBPHASE, G1);
public static final GCEventType G1_CONCURRENT_MARK_ABORT = new GCEventType("Concurrent Mark Abort", CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, G1);
public static final GCEventType G1_MARK_LIVE_OBJECTS = new GCEventType("Mark Live Objects", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_PREPARE_FOR_COMPACTION = new GCEventType("Prepare for Compaction", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_ADJUST_POINTERS = new GCEventType("Adjust Pointers", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_COMPACT_HEAP = new GCEventType("Compact Heap", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_EXT_ROOT_SCANNING = new GCEventType("Ext Root Scanning", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_UPDATE_RS = new GCEventType("Update Remember Set", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_SCAN_RS = new GCEventType("Scan Remember Set", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_CODE_ROOT_SCANNING = new GCEventType("Code Root Scanning", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_OBJECT_COPY = new GCEventType("Object Copy", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_TERMINATION = new GCEventType("Termination", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_CODE_ROOT_FIXUP = new GCEventType("Code Root Fixup", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_CODE_ROOT_PURGE = new GCEventType("Code Root Purge", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_CLEAR_CT = new GCEventType("Clear Card Table", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_CHOOSE_CSET = new GCEventType("Choose Collection Set", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_EVACUATION_FAILURE = new GCEventType("Evacuation Failure", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_REF_ENQ = new GCEventType("Ref Enq", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_REDIRTY_CARDS = new GCEventType("Redirty Cards", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_HUMONGOUS_REGISTER = new GCEventType("Humongous Register", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_HUMONGOUS_RECLAIM = new GCEventType("Humongous Reclaim", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
public static final GCEventType G1_FREE_CSET = new GCEventType("Free Collection Set", PAUSE, PARENT_YOUNG_OLD_FULL_GC, G1);
// CMS
public static final GCEventType CMS_INITIAL_MARK = new GCEventType("Initial Mark", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, CMS);
public static final GCEventType CMS_CONCURRENT_PRECLEAN = new GCEventType("Concurrent Preclean", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, CMS);
public static final GCEventType CMS_CONCURRENT_ABORTABLE_PRECLEAN = new GCEventType("Concurrent Abortable preclean", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, CMS);
public static final GCEventType CMS_CONCURRENT_MARK = new GCEventType("Concurrent Mark", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, CMS);
public static final GCEventType CMS_FINAL_REMARK = new GCEventType("Final Remark", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, CMS);
public static final GCEventType CMS_CONCURRENT_SWEEP = new GCEventType("Concurrent Sweep", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, CMS);
public static final GCEventType CMS_CONCURRENT_RESET = new GCEventType("Concurrent Reset", GCPause.CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, CMS);
public static final GCEventType CMS_CONCURRENT_INTERRUPTED = new GCEventType("Concurrent Mode Interrupted", CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, CMS);
public static final GCEventType CMS_CONCURRENT_FAILURE = new GCEventType("Concurrent Mode Failure", CONCURRENT, PARENT_CONCURRENT_MARK_CYCLE, CMS);
public static final GCEventType CMS_RESCAN = new GCEventType("Rescan", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, GCEventLevel.SUBPHASE, CMS);
public static final GCEventType CMS_CLASS_UNLOADING = new GCEventType("Class unloading", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, GCEventLevel.SUBPHASE, CMS);
public static final GCEventType CMS_SCRUB_SYMBOL_TABLE = new GCEventType("Scrub Symbol Table", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, GCEventLevel.SUBPHASE, CMS);
public static final GCEventType CMS_SCRUB_STRING_TABLE = new GCEventType("Scrub String Table", PAUSE, PARENT_CONCURRENT_MARK_CYCLE, GCEventLevel.SUBPHASE, CMS);
// ZGC
public static final GCEventType ZGC_PAUSE_MARK_START = new GCEventType("Pause Mark Start", PAUSE, PARENT_ZGC, ZGC);
public static final GCEventType ZGC_CONCURRENT_MARK = new GCEventType("Concurrent Mark", CONCURRENT, PARENT_ZGC, ZGC);
public static final GCEventType ZGC_PAUSE_MARK_END = new GCEventType("Pause Mark End", PAUSE, PARENT_ZGC, ZGC);
public static final GCEventType ZGC_CONCURRENT_NONREF = new GCEventType("Concurrent Process Non-Strong References", CONCURRENT, PARENT_ZGC, ZGC);
public static final GCEventType ZGC_CONCURRENT_RESET_RELOC_SET = new GCEventType("Concurrent Reset Relocation Set", CONCURRENT, PARENT_ZGC, ZGC);
public static final GCEventType ZGC_CONCURRENT_DETATCHED_PAGES = new GCEventType("Concurrent Destroy Detached Pages", CONCURRENT, PARENT_ZGC, ZGC);
public static final GCEventType ZGC_CONCURRENT_SELECT_RELOC_SET = new GCEventType("Concurrent Select Relocation Set", CONCURRENT, PARENT_ZGC, ZGC);
public static final GCEventType ZGC_CONCURRENT_PREPARE_RELOC_SET = new GCEventType("Concurrent Prepare Relocation Set", CONCURRENT, PARENT_ZGC, ZGC);
public static final GCEventType ZGC_PAUSE_RELOCATE_START = new GCEventType("Pause Relocate Start", PAUSE, PARENT_ZGC, ZGC);
public static final GCEventType ZGC_CONCURRENT_RELOCATE = new GCEventType("Concurrent Relocate", CONCURRENT, PARENT_ZGC, ZGC);
public static final GCEventType ZGC_ALLOCATION_STALL = new GCEventType("Allocation Stall", PAUSE, ZGC);
// other
public static final GCEventType SAFEPOINT = new GCEventType("Safepoint", PAUSE, ALL_GCS);
public static final GCEventType OUT_OF_MEMORY = new GCEventType("Out Of Memory", PAUSE, ALL_GCS);
public boolean hasObjectPromotion() {
return this == YOUNG_GC || this == G1_MIXED_GC;
}
public GCPause getPause() {
return pause;
}
public String getName() {
return name;
}
public GCEventType[] getPhaseParentEventType() {
return phaseParentEventType;
}
// construction from outside not allowed, all instances are created in advance
private GCEventType(String name, GCPause pause, GCCollectorType[] gcs) {
this(name, pause, null, EVENT, gcs);
}
private GCEventType(String name, GCPause pause, GCEventType[] phaseParentEventType,
GCCollectorType[] gcs) {
this(name, pause, phaseParentEventType,
phaseParentEventType == null ? EVENT : GCEventLevel.PHASE, gcs);
}
public GCEventType(String name, GCPause pause, GCEventType[] phaseParentEventType,
GCEventLevel level, GCCollectorType[] gcs) {
this.name = name;
this.pause = pause;
this.phaseParentEventType = phaseParentEventType;
this.level = level;
this.gcs = Arrays.asList(gcs);
allEventTypes.add(this);
}
@Override
public String toString() {
return name;
}
public GCEventLevel getLevel() {
return level;
}
public List<GCCollectorType> getGcs() {
return gcs;
}
public static List<GCEventType> getAllEventTypes() {
return allEventTypes;
}
public boolean isMainPauseEventType() {
if (getPause() != PAUSE) {
return false;
}
if (level == EVENT) {
return true;
}
return level == PHASE && (phaseParentEventType == PARENT_ZGC || phaseParentEventType == PARENT_CONCURRENT_MARK_CYCLE);
}
public boolean isYoungGC() {
return this == GCEventType.YOUNG_GC || this == GCEventType.G1_MIXED_GC;
}
public boolean isOldGC() {
return this == GCEventType.G1_CONCURRENT_CYCLE || this == GCEventType.CMS_CONCURRENT_MARK_SWEPT;
}
public boolean isFullGC() {
return this == GCEventType.FULL_GC || this == ZGC_GARBAGE_COLLECTION;
}
public static List<GCEventType> badEventTypes = List.of(
FULL_GC,
G1_CONCURRENT_MARK_ABORT,
G1_EVACUATION_FAILURE,
CMS_CONCURRENT_FAILURE,
CMS_CONCURRENT_INTERRUPTED,
OUT_OF_MEMORY,
ZGC_ALLOCATION_STALL,
G1_CONCURRENT_MARK_RESET_FOR_OVERFLOW);
public boolean isBad() {
return badEventTypes.contains(this);
}
}
| 6,765 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/GCModel.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model;
import io.vertx.ext.web.impl.ConcurrentLRUCache;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.eclipse.jifa.common.listener.ProgressListener;
import org.eclipse.jifa.common.request.PagingRequest;
import org.eclipse.jifa.common.vo.PageView;
import org.eclipse.jifa.gclog.diagnoser.AnalysisConfig;
import org.eclipse.jifa.gclog.diagnoser.EventAbnormalDetector;
import org.eclipse.jifa.gclog.diagnoser.GlobalDiagnoseInfo;
import org.eclipse.jifa.gclog.diagnoser.GlobalDiagnoser;
import org.eclipse.jifa.gclog.event.*;
import org.eclipse.jifa.gclog.event.evnetInfo.*;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.model.modeInfo.GCLogMetadata;
import org.eclipse.jifa.gclog.model.modeInfo.GCLogStyle;
import org.eclipse.jifa.gclog.model.modeInfo.VmOptions;
import org.eclipse.jifa.gclog.util.Constant;
import org.eclipse.jifa.gclog.util.DoubleData;
import org.eclipse.jifa.gclog.util.LongData;
import org.eclipse.jifa.gclog.vo.*;
import org.eclipse.jifa.gclog.vo.MemoryStatistics.MemoryStatisticsItem;
import org.eclipse.jifa.gclog.vo.PhaseStatistics.ParentStatisticsInfo;
import org.eclipse.jifa.gclog.vo.PhaseStatistics.PhaseStatisticItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea.*;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
import static org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType.*;
/**
* GCModel contains all direct information from log and analysed data for query
*/
public abstract class GCModel {
protected static final Logger LOGGER = LoggerFactory.getLogger(GCModel.class);
// These 3 event lists below are used to support events like young/mixed/old/full. Other events. like
// safepoint, allocation stall will be save in other lists. gcEvents and allEvents may be used in parsing.
// When calculating derived info, gcEvents may be transformed, and allEvents and gcCollectionEvents will be
// rebuilt.
private List<GCEvent> gcEvents = new ArrayList<>(); // store parent events only
private List<GCEvent> allEvents = new ArrayList<>(); // store all events, order by their appearance in log
private List<GCEvent> gcCollectionEvents = new ArrayList<>(); // store events that contain collection info
private List<Safepoint> safepoints = new ArrayList<>();
private List<ThreadEvent> ooms = new ArrayList<>();
// time from beginning of program
private double startTime = Constant.UNKNOWN_DOUBLE;
private double endTime = Constant.UNKNOWN_DOUBLE;
private int parallelThread = Constant.UNKNOWN_INT;
private int concurrentThread = Constant.UNKNOWN_INT;
// in ms. referenceTimestamp + uptime of events is the true timestamp of events.
// notice that uptime may not begin from 0
private double referenceTimestamp = Constant.UNKNOWN_DOUBLE;
//shared basic info among different collectors
private VmOptions vmOptions;
private GCCollectorType collectorType;
private GCLogStyle logStyle;
private GCLogMetadata metadata;
private ConcurrentLRUCache<AnalysisConfig, GlobalDiagnoseInfo> globalDiagnoseInfoCache = new ConcurrentLRUCache<>(3);
private boolean metaspaceCapacityReliable = false;
public GCModel() {
}
public GCModel(GCCollectorType collectorType) {
this.collectorType = collectorType;
}
public void setCollectorType(GCCollectorType collectorType) {
this.collectorType = collectorType;
}
public GCCollectorType getCollectorType() {
return collectorType;
}
public GCLogStyle getLogStyle() {
return logStyle;
}
public void setLogStyle(GCLogStyle logStyle) {
this.logStyle = logStyle;
}
public List<GCEvent> getGcCollectionEvents() {
return gcCollectionEvents;
}
public double getStartTime() {
return startTime;
}
public double getEndTime() {
return endTime;
}
private static final double START_TIME_ZERO_THRESHOLD = 60000;
public void setStartTime(double startTime) {
if (startTime < START_TIME_ZERO_THRESHOLD) {
startTime = 0;
}
this.startTime = startTime;
}
public boolean isGenerational() {
return collectorType != ZGC;
}
public boolean isPauseless() {
return collectorType == ZGC;
}
public List<GCEvent> getAllEvents() {
return allEvents;
}
public void setEndTime(double endTime) {
this.endTime = endTime;
}
public double getDuration() {
return getEndTime() - getStartTime();
}
public boolean isEmpty() {
return gcEvents.isEmpty();
}
public List<GCEvent> getGcEvents() {
return gcEvents;
}
public void setGcEvents(List<GCEvent> gcEvents) {
this.gcEvents = gcEvents;
}
public GCEvent createAndGetEvent() {
GCEvent event = new GCEvent();
gcEvents.add(event);
return event;
}
public boolean hasHumongousArea() {
return collectorType == G1 && logStyle == GCLogStyle.UNIFIED;
}
public boolean hasOldGC() {
return collectorType == G1 || collectorType == CMS;
}
public <T extends TimedEvent> void iterateEventsWithinTimeRange(List<T> eventList, TimeRange range, Consumer<T> consumer) {
int indexLow = binarySearchEventIndex(eventList, range.getStart(), true);
int indexHigh = binarySearchEventIndex(eventList, range.getEnd(), false);
for (int i = indexLow; i < indexHigh; i++) {
consumer.accept(eventList.get(i));
}
}
// Return index of the first event after time if searchLow, first event after time if !searchLow .
// eventList must be ordered by startTime.
private int binarySearchEventIndex(List<? extends TimedEvent> eventList, double time, boolean searchLow) {
if (searchLow && time <= getStartTime()) {
return 0;
} else if (!searchLow && time >= getEndTime()) {
return eventList.size();
}
TimedEvent eventForSearching = new TimedEvent(time);
int result = Collections.binarySearch(eventList, eventForSearching, Comparator.comparingDouble(TimedEvent::getStartTime));
if (result < 0) {
return -(result + 1);
} else {
if (searchLow) {
while (result >= 0 && eventList.get(result).getStartTime() >= time) {
result--;
}
return result + 1;
} else {
while (result < eventList.size() && eventList.get(result).getStartTime() <= time) {
result++;
}
return result;
}
}
}
public List<Safepoint> getSafepoints() {
return safepoints;
}
public void addSafepoint(Safepoint safepoint) {
safepoints.add(safepoint);
}
public List<ThreadEvent> getOoms() {
return ooms;
}
public void addOom(ThreadEvent oom) {
ooms.add(oom);
}
private TimeRange makeValidTimeRange(TimeRange range) {
if (range == null) {
return new TimeRange(getStartTime(), getEndTime());
}
double start = Math.max(range.getStart(), getStartTime());
double end = Math.min(range.getEnd(), getEndTime());
return new TimeRange(start, end);
}
private void putPhaseStatisticData(GCEvent event, String name, Map<String, DoubleData[]> map, boolean phase) {
DoubleData[] data = map.getOrDefault(name, null);
if (data == null) {
data = new DoubleData[2];
data[0] = new DoubleData();
data[1] = new DoubleData();
map.put(name, data);
}
data[0].add(phase ? event.getInterval() : event.getCauseInterval());
data[1].add(event.getDuration());
}
private PhaseStatisticItem makePhaseStatisticItem(String name, DoubleData[] data) {
return new PhaseStatisticItem(name, data[1].getN(), data[0].average(), data[0].getMin()
, data[1].average(), data[1].getMax(), data[1].getSum());
}
public PhaseStatistics getPhaseStatistics(TimeRange range) {
range = makeValidTimeRange(range);
List<GCEventType> parents = getParentEventTypes();
// DoubleData[] is an array of interval and duration
Map<String, DoubleData[]> parentData = new HashMap<>();
List<Map<String, DoubleData[]>> phaseData = new ArrayList<>();
List<Map<String, DoubleData[]>> causeData = new ArrayList<>();
for (int i = 0; i < parents.size(); i++) {
phaseData.add(new HashMap<>());
causeData.add(new HashMap<>());
}
iterateEventsWithinTimeRange(gcEvents, range, event -> {
int index = parents.indexOf(event.getEventType());
if (index < 0) {
return;
}
putPhaseStatisticData(event, event.getEventType().getName(), parentData, true);
if (event.getCause() != null) {
putPhaseStatisticData(event, event.getCause().getName(), causeData.get(index), false);
}
event.phasesDoDFS(phase -> putPhaseStatisticData(phase, phase.getEventType().getName(),
phaseData.get(index), true));
});
List<ParentStatisticsInfo> result = new ArrayList<>();
for (int i = 0; i < parents.size(); i++) {
String name = parents.get(i).getName();
if (parentData.containsKey(name)) {
result.add(new ParentStatisticsInfo(
makePhaseStatisticItem(parents.get(i).getName(), parentData.get(name)),
phaseData.get(i).entrySet().stream().map(entry -> makePhaseStatisticItem(entry.getKey(), entry.getValue())).collect(Collectors.toList()),
causeData.get(i).entrySet().stream().map(entry -> makePhaseStatisticItem(entry.getKey(), entry.getValue())).collect(Collectors.toList())
));
}
}
return new PhaseStatistics(result);
}
public PauseStatistics getPauseStatistics(TimeRange range) {
range = makeValidTimeRange(range);
DoubleData pause = new DoubleData(true);
iterateEventsWithinTimeRange(gcEvents, range, e -> {
e.pauseEventOrPhasesDo(event -> pause.add(event.getPause()));
});
return new PauseStatistics(
pause.getN() == 0 ? Constant.UNKNOWN_DOUBLE : 1 - pause.getSum() / range.length(),
pause.average(),
pause.getMedian(),
pause.getPercentile(0.99),
pause.getPercentile(0.999),
pause.getMax());
}
public Map<String, int[]> getPauseDistribution(TimeRange range, int[] partitions) {
range = makeValidTimeRange(range);
Map<String, int[]> distribution = new HashMap<>();
iterateEventsWithinTimeRange(gcEvents, range, e -> {
e.pauseEventOrPhasesDo(event -> {
if (event.getPause() >= 0) {
String eventType = event.getEventType().getName();
int pause = (int) event.getPause();
int index = Arrays.binarySearch(partitions, pause);
if (index < 0) {
index = -index - 2;
}
if (index < 0) {
return;
}
int[] nums = distribution.getOrDefault(eventType, null);
if (nums == null) {
nums = new int[partitions.length];
distribution.put(eventType, nums);
}
nums[index]++;
}
});
});
return distribution;
}
public MemoryStatistics getMemoryStatistics(TimeRange range) {
range = makeValidTimeRange(range);
// 1st dimension is generation, see definition of MemoryStatistics
// 2nd dimension is capacityAvg, usedMax, usedAvgAfterFullGC,usedAvgAfterOldGC see definition of MemoryStatisticsItem
// usedAvgAfterOldGC is more complicated, will deal with it afterwards
LongData[][] data = new LongData[5][4];
MemoryArea[] generations = {YOUNG, OLD, HUMONGOUS, HEAP, METASPACE};
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4; j++) {
data[i][j] = new LongData();
}
}
iterateEventsWithinTimeRange(gcCollectionEvents, range, event -> {
for (int genIndex = 0; genIndex < generations.length; genIndex++) {
MemoryArea generation = generations[genIndex];
GCMemoryItem memory = event.getMemoryItem(generation);
if (memory != null) {
data[genIndex][0].add(memory.getPostCapacity());
data[genIndex][1].add(Math.max(memory.getPreUsed(), memory.getPostUsed()));
if (event.isFullGC() && generation != YOUNG) {
data[genIndex][2].add(memory.getPostUsed());
}
}
}
});
calculateUsedAvgAfterOldGC(range, data);
// generate result
MemoryStatistics statistics = new MemoryStatistics();
statistics.setYoung(new MemoryStatisticsItem((long) data[0][0].average(), data[0][1].getMax(), Constant.UNKNOWN_LONG, Constant.UNKNOWN_LONG));
statistics.setOld(new MemoryStatisticsItem((long) data[1][0].average(), data[1][1].getMax(), (long) data[1][2].average(), (long) data[1][3].average()));
statistics.setHumongous(new MemoryStatisticsItem((long) data[2][0].average(), data[2][1].getMax(), (long) data[2][2].average(), (long) data[2][3].average()));
statistics.setHeap(new MemoryStatisticsItem((long) data[3][0].average(), data[3][1].getMax(), (long) data[3][2].average(), (long) data[3][3].average()));
statistics.setMetaspace(new MemoryStatisticsItem(Constant.UNKNOWN_LONG, data[4][1].getMax(), (long) data[4][2].average(), (long) data[4][3].average()));
// Metaspace capacity printed in gclog may be reserve space rather than commit size, so we
// try to read it from vm option
if (isMetaspaceCapacityReliable()) {
statistics.getMetaspace().setCapacityAvg((long) data[4][0].average());
} else if (vmOptions != null) {
statistics.getMetaspace().setCapacityAvg(vmOptions.getMetaspaceSize());
}
return statistics;
}
protected void calculateUsedAvgAfterOldGC(TimeRange range, LongData[][] data) {
// for overriding
}
public ObjectStatistics getObjectStatistics(TimeRange range) {
range = makeValidTimeRange(range);
LongData allocation = new LongData();
LongData promotion = new LongData();
iterateEventsWithinTimeRange(gcCollectionEvents, range, event -> {
allocation.add(event.getAllocation());
promotion.add(event.getPromotion());
});
return new ObjectStatistics(
allocation.getSum() != Constant.UNKNOWN_DOUBLE ? allocation.getSum() / range.length() : Constant.UNKNOWN_DOUBLE,
promotion.getSum() != Constant.UNKNOWN_DOUBLE ? promotion.getSum() / range.length() : Constant.UNKNOWN_DOUBLE,
(long) promotion.average(), promotion.getMax()
);
}
// decide start and end time using events
public void autoDecideStartEndTime() {
gcEvents.sort(Comparator.comparingDouble(GCEvent::getStartTime));
if (gcEvents.size() == 0) {
return;
}
GCEvent event = gcEvents.get(gcEvents.size() - 1);
double endTime = event.getEndTime();
if (event.hasPhases()) {
endTime = Math.max(endTime, event.getPhases().get(event.getPhases().size() - 1).getEndTime());
}
setEndTime(Math.max(this.endTime, endTime));
}
public Map<String, List<Object[]>> getTimeGraphData(String[] dataTypes) {
Map<String, List<Object[]>> result = new LinkedHashMap<>();
for (String dataType : dataTypes) {
if (dataType.endsWith("Used") || dataType.endsWith("Capacity")) {
result.put(dataType, getTimeGraphMemoryData(dataType));
} else if (dataType.equals("promotion")) {
result.put(dataType, getTimeGraphPromotionData());
} else if (dataType.equals("reclamation")) {
result.put(dataType, getTimeGraphReclamationData());
} else {
result.put(dataType, getTimeGraphDurationData(dataType));
}
}
return result;
}
private List<Object[]> getTimeGraphMemoryData(String dataType) {
boolean used = dataType.endsWith("Used");
String areString = dataType.substring(0, dataType.length() - (used ? "Used" : "Capacity").length());
MemoryArea area = MemoryArea.getMemoryArea(areString);
List<Object[]> result = new ArrayList<>();
for (GCEvent event : this.gcCollectionEvents) {
GCMemoryItem memory = event.getMemoryItem(area);
if (memory == null) {
continue;
}
if (used) {
if (memory.getPreUsed() != Constant.UNKNOWN_LONG) {
result.add(new Object[]{(long) event.getStartTime(), memory.getPreUsed()});
}
if (memory.getPostUsed() != Constant.UNKNOWN_LONG) {
result.add(new Object[]{(long) event.getEndTime(), memory.getPostUsed()});
}
} else {
if (memory.getPostCapacity() != Constant.UNKNOWN_LONG) {
result.add(new Object[]{(long) event.getEndTime(), memory.getPostCapacity()});
}
}
}
result.sort(Comparator.comparingLong(d -> (long) d[0]));
return result;
}
private List<Object[]> getTimeGraphPromotionData() {
return allEvents.stream()
.filter(event -> event.getPromotion() >= 0)
.map(event -> new Object[]{(long) event.getStartTime(), event.getPromotion()})
.collect(Collectors.toList());
}
private List<Object[]> getTimeGraphReclamationData() {
return gcCollectionEvents.stream()
.filter(event -> event.getReclamation() != Constant.UNKNOWN_LONG)
.map(event -> new Object[]{(long) event.getStartTime(), event.getReclamation()})
.collect(Collectors.toList());
}
private List<Object[]> getTimeGraphDurationData(String phaseName) {
return allEvents.stream()
.filter(event -> event.getEventType().getName().equals(phaseName)
&& event.getDuration() != Constant.UNKNOWN_DOUBLE)
.map(event -> new Object[]{(long) event.getStartTime(), event.getDuration()})
.collect(Collectors.toList());
}
public GlobalDiagnoser.GlobalAbnormalInfo getGlobalAbnormalInfo(AnalysisConfig config) {
config.setTimeRange(makeValidTimeRange(config.getTimeRange()));
return new GlobalDiagnoser(this, config).diagnose();
}
public long getRecommendMaxHeapSize() {
// not supported
return Constant.UNKNOWN_INT;
}
public void putEvent(GCEvent event) {
gcEvents.add(event);
allEvents.add(event);
}
public void addPhase(GCEvent parent, GCEvent phase) {
allEvents.add(phase);
parent.addPhase(phase);
}
public void calculateDerivedInfo(ProgressListener progressListener) {
allEvents = null;
// must be done before other steps
filterInvalidEvents();
autoDecideStartEndTime();
decideAndFixEventInfo();
// let subclass do something
doBeforeCalculatingDerivedInfo();
rebuildEventLists();
// the structure of gcEvents and allEvents should not change after this line
// calculate derived data for events themselves
calculateEventsInterval();
calculateEventsMemoryInfo();
// let subclass do something
doAfterCalculatingDerivedInfo();
// data in events should not change after this line
// calculate specific data prepared for route api, order of these calls doesn't matter
calculateGcModelMetadata();
}
// for implementation
protected void doBeforeCalculatingDerivedInfo() {
}
// for implementation
protected void doAfterCalculatingDerivedInfo() {
}
private void rebuildEventLists() {
allEvents = new ArrayList<>();
for (GCEvent event : gcEvents) {
allEvents.add(event);
if (event.hasPhases()) {
allEvents.addAll(event.getPhases());
}
}
allEvents.sort(Comparator.comparingDouble(GCEvent::getStartTime));
for (int i = 0; i < allEvents.size(); i++) {
allEvents.get(i).setId(i);
}
}
private void decideAndFixEventInfo() {
for (GCEvent event : gcEvents) {
List<GCEvent> phases = event.getPhases();
if (phases == null) {
continue;
}
for (int i = phases.size() - 1; i >= 0; i--) {
GCEvent phase = phases.get(i);
if (phase.getDuration() == Constant.UNKNOWN_DOUBLE) {
//this is unlikely to happen, just give a reasonable value
phase.setDuration(phases.get(phases.size() - 1).getStartTime() - phase.getStartTime());
}
}
if (event.getDuration() == Constant.UNKNOWN_DOUBLE && getStartTime() != Constant.UNKNOWN_DOUBLE) {
event.setDuration(phases.get(phases.size() - 1).getEndTime() - event.getStartTime());
}
}
}
/**
* calculate heap size(young, humongous, old, metaspace,total),
* object allocation, reclamation and promotion
*/
private void calculateEventsMemoryInfo() {
for (GCEvent event : gcEvents) {
calculateEventMemoryItems(event);
}
gcCollectionEvents.sort(Comparator.comparingDouble(GCEvent::getStartTime));
long lastTotalMemory = 0;
for (GCEvent event : gcCollectionEvents) {
GCMemoryItem young = event.getMemoryItem(YOUNG);
GCMemoryItem total = event.getMemoryItem(HEAP);
GCMemoryItem humongous = event.getMemoryItem(HUMONGOUS);
// reclamation
// sometimes it may have been calculated during parsing log
if (event.getReclamation() == Constant.UNKNOWN_INT && total != null &&
total.getPreUsed() != Constant.UNKNOWN_INT && total.getPostUsed() != Constant.UNKNOWN_INT) {
event.setReclamation(zeroIfNegative(total.getPreUsed() - total.getPostUsed()));
}
// promotion
if (event.getPromotion() == Constant.UNKNOWN_INT
&& event.hasPromotion() && event.getEventType() != G1_MIXED_GC
&& young != null && total != null) {
// notice: g1 young mixed gc should have promotion, but we have no way to know it exactly
long youngReduction = young.getMemoryReduction();
long totalReduction = total.getMemoryReduction();
if (youngReduction != Constant.UNKNOWN_INT && totalReduction != Constant.UNKNOWN_INT) {
long promotion = youngReduction - totalReduction;
if (humongous != null && humongous.getMemoryReduction() != Constant.UNKNOWN_INT) {
promotion -= humongous.getMemoryReduction();
}
event.setPromotion(zeroIfNegative(promotion));
}
}
// allocation
if (event.getAllocation() == Constant.UNKNOWN_INT &&
total != null && total.getPreUsed() != Constant.UNKNOWN_INT) {
// As to concurrent event, allocation is composed of two parts: allocation between two adjacent events
// and during event. If original allocation is not unknown, that value is allocation during event.
event.setAllocation(zeroIfNegative(
zeroIfUnknownInt(event.getAllocation()) + total.getPreUsed() - lastTotalMemory));
lastTotalMemory = total.getPostUsed();
}
}
}
private long zeroIfUnknownInt(long x) {
return x == Constant.UNKNOWN_INT ? 0 : x;
}
private long zeroIfNegative(long x) {
return x < 0 ? 0 : x;
}
private void calculateEventMemoryItems(GCEvent event) {
event.phasesDoDFS(this::calculateEventMemoryItems);
if (event.getMemoryItems() == null) {
return;
}
gcCollectionEvents.add(event);
// hack: Survivor capacity of g1 is not printed in jdk8. Make it equal to pre used so that
// we can calculate young and old capacity
if (event.getMemoryItem(SURVIVOR) != null &&
event.getMemoryItem(SURVIVOR).getPostCapacity() == Constant.UNKNOWN_INT) {
event.getMemoryItem(SURVIVOR).setPostCapacity(event.getMemoryItem(SURVIVOR).getPreUsed());
}
//case 1: know eden and survivor, calculate young
GCMemoryItem young = event.getMemoryItemOrEmptyObject(EDEN)
.merge(event.getMemoryItem(SURVIVOR));
young.setArea(YOUNG);
event.setMemoryItem(event.getMemoryItemOrEmptyObject(YOUNG)
.updateIfAbsent(young), true);
//case 2: know young and old, calculate heap
GCMemoryItem heap = event.getMemoryItemOrEmptyObject(YOUNG)
.merge(event.getMemoryItem(OLD))
.mergeIfPresent(event.getMemoryItem(HUMONGOUS))
.mergeIfPresent(event.getMemoryItem(ARCHIVE));
heap.setArea(HEAP);
event.setMemoryItem(event.getMemoryItemOrEmptyObject(HEAP)
.updateIfAbsent(heap), true);
//case 3: know old and heap, calculate young
young = event.getMemoryItemOrEmptyObject(HEAP)
.subtract(event.getMemoryItem(OLD))
.subtractIfPresent(event.getMemoryItem(HUMONGOUS))
.subtractIfPresent(event.getMemoryItem(ARCHIVE));
young.setArea(YOUNG);
event.setMemoryItem(event.getMemoryItemOrEmptyObject(YOUNG)
.updateIfAbsent(young), true);
//case 4: know young and heap, calculate old
GCMemoryItem old = event.getMemoryItemOrEmptyObject(HEAP)
.subtract(event.getMemoryItem(YOUNG))
.subtractIfPresent(event.getMemoryItem(HUMONGOUS))
.subtractIfPresent(event.getMemoryItem(ARCHIVE));
old.setArea(OLD);
event.setMemoryItem(event.getMemoryItemOrEmptyObject(OLD)
.updateIfAbsent(old), true);
// Although we can calculate metaspace = class + non class, there is no need to do
// so because when class and non class are known, metaspace must have been known
}
private void filterInvalidEvents() {
// Sometimes the given log is just a part of the complete log. This may lead to some incomplete events at
// beginning or end of this log. Such event at beginning is likely to have been dealt by parser, so here we try
// to deal with the last event
if (gcEvents.get(gcEvents.size() - 1).getEndTime() == Constant.UNKNOWN_DOUBLE) {
gcEvents.remove(gcEvents.size() - 1);
}
}
protected static List<GCEventType> calcAllEventTypes(GCCollectorType collector) {
return GCEventType.getAllEventTypes().stream()
.filter(e -> e.getGcs().contains(collector))
.collect(Collectors.toList());
}
protected static List<GCEventType> calcPauseEventTypes(GCCollectorType collector) {
return GCEventType.getAllEventTypes().stream()
.filter(e -> e.getGcs().contains(collector) && e.getPause() == GCPause.PAUSE)
.collect(Collectors.toList());
}
protected static List<GCEventType> calcMainPauseEventTypes(GCCollectorType collector) {
return GCEventType.getAllEventTypes().stream()
.filter(e -> e.getGcs().contains(collector) && e.isMainPauseEventType())
.collect(Collectors.toList());
}
protected static List<GCEventType> calcParentEventTypes(GCCollectorType collector) {
return Stream.of(YOUNG_GC, G1_MIXED_GC, CMS_CONCURRENT_MARK_SWEPT, G1_CONCURRENT_CYCLE, FULL_GC, ZGC_GARBAGE_COLLECTION)
.filter(e -> e.getGcs().contains(collector))
.collect(Collectors.toList());
}
protected abstract List<GCEventType> getAllEventTypes();
protected abstract List<GCEventType> getPauseEventTypes();
protected abstract List<GCEventType> getMainPauseEventTypes();
protected abstract List<GCEventType> getParentEventTypes();
protected abstract List<GCEventType> getImportantEventTypes();
public GCEvent getLastEventWithCondition(Predicate<GCEvent> condition) {
for (int i = allEvents.size() - 1; i >= 0; i--) {
GCEvent event = allEvents.get(i);
if (condition.test(event)) {
return event;
}
}
return null;
}
// mainly used in jdk8, where gcid may be missing
public GCEvent getLastEventOfType(GCEventType... types) {
List<GCEventType> typeList = Arrays.asList(types);
return getLastEventWithCondition(event -> typeList.contains(event.getEventType()));
}
// mainly used in parser of jdk11, where gcid is always logged if tag includes gc
public GCEvent getLastEventOfGCID(int gcid) {
return getLastEventWithCondition(event -> event.getEventLevel() == GCEventLevel.EVENT && event.getGcid() == gcid);
}
public double getReferenceTimestamp() {
return referenceTimestamp;
}
public void setReferenceTimestamp(double referenceTimestamp) {
this.referenceTimestamp = referenceTimestamp;
}
public void setVmOptions(VmOptions vmOptions) {
this.vmOptions = vmOptions;
}
public VmOptions getVmOptions() {
return vmOptions;
}
private void calculateEventsInterval() {
Map<GCEventType, Double> lastEndTime = new HashMap<>();
Map<GCEventType, Map<GCCause, Double>> lastCauseEndTime = new HashMap<>();
for (GCEvent event : allEvents) {
GCEventType eventType = event.getEventType();
// regard mixed gc as young gc
if (event.isYoungGC()) {
eventType = YOUNG_GC;
}
if (lastEndTime.containsKey(eventType)) {
event.setInterval(Math.max(0, event.getStartTime() - lastEndTime.get(eventType)));
}
lastEndTime.put(eventType, event.getEndTime());
GCCause cause = event.getCause();
if (cause != null) {
Map<GCCause, Double> map = lastCauseEndTime.getOrDefault(eventType, null);
if (map == null) {
map = new HashMap<>();
lastCauseEndTime.put(eventType, map);
}
if (map.containsKey(cause)) {
event.setCauseInterval(Math.max(0, event.getStartTime() - map.get(cause)));
}
map.put(cause, event.getEndTime());
}
}
}
public String toDebugString() {
StringBuilder sb = new StringBuilder();
for (GCEvent event : gcEvents) {
sb.append(event.toDebugString(this)).append("\n");
event.phasesDoDFS(phase -> sb.append(" ").append(phase.toDebugString(this)).append("\n"));
}
return sb.toString();
}
public boolean shouldAvoidFullGC() {
return collectorType != SERIAL && collectorType != PARALLEL && collectorType != UNKNOWN;
}
public List<GCEventVO> getEventsVO(List<GCEvent> events, AnalysisConfig config) {
GlobalDiagnoseInfo diagnose = getGlobalDiagnoseInfo(config);
return events.stream().map(event -> event.toEventVO(this, diagnose)).collect(Collectors.toList());
}
public GCEventVO getEventVO(GCEvent event, AnalysisConfig config) {
GlobalDiagnoseInfo diagnose = getGlobalDiagnoseInfo(config);
return event.toEventVO(this, diagnose);
}
public PageView<GCEventVO> getGCDetails(PagingRequest pagingRequest, GCDetailFilter filter, AnalysisConfig config) {
int firstIndex = (pagingRequest.getPage() - 1) * pagingRequest.getPageSize();
int total = 0;
List<GCEvent> resultEvents = new ArrayList<>();
for (GCEvent event : gcEvents) {
if (!filter.isFiltered(event)) {
if (total >= firstIndex && resultEvents.size() < pagingRequest.getPageSize()) {
resultEvents.add(event);
}
total++;
}
}
List<GCEventVO> result = getEventsVO(resultEvents, config);
return new PageView<>(pagingRequest, total, result);
}
public boolean shouldTryToAvoidMemoryFullGC() {
return collectorType != SERIAL && collectorType != PARALLEL;
}
public GCLogMetadata getGcModelMetadata() {
return metadata;
}
// FIXME: need better implementation
private static final List<GCEventType> EVENT_TYPES_SHOULD_NOT_BE_REPORTED_IF_NOT_PRESENT = List.of(
G1_CONCURRENT_UNDO_CYCLE, G1_MERGE_HEAP_ROOTS, G1_CONCURRENT_REBUILD_REMEMBERED_SETS,
ZGC_CONCURRENT_DETATCHED_PAGES);
private List<String> dealEventTypeForMetadata(List<GCEventType> eventTypesExpected,
Set<GCEventType> eventTypesActuallyShowUp) {
return eventTypesExpected.stream()
.filter(eventType -> !EVENT_TYPES_SHOULD_NOT_BE_REPORTED_IF_NOT_PRESENT.contains(eventType)
|| eventTypesActuallyShowUp.contains(eventType))
.map(GCEventType::getName)
.collect(Collectors.toList());
}
private void calculateGcModelMetadata() {
metadata = new GCLogMetadata();
metadata.setCauses(gcEvents.stream()
.map(GCEvent::getCause)
.filter(Objects::nonNull)
.map(GCCause::getName)
.distinct()
.collect(Collectors.toList()));
metadata.setCollector(getCollectorType().toString());
metadata.setLogStyle(getLogStyle().toString());
metadata.setPauseless(isPauseless());
metadata.setGenerational(isGenerational());
metadata.setMetaspaceCapacityReliable(isMetaspaceCapacityReliable());
metadata.setTimestamp(getReferenceTimestamp());
metadata.setStartTime(getStartTime());
metadata.setEndTime(getEndTime());
Set<GCEventType> eventTypesActuallyShowUp = this.allEvents.stream()
.map(GCEvent::getEventType)
.collect(Collectors.toSet());
metadata.setParentEventTypes(dealEventTypeForMetadata(getParentEventTypes(), eventTypesActuallyShowUp));
metadata.setImportantEventTypes(dealEventTypeForMetadata(getImportantEventTypes(), eventTypesActuallyShowUp));
metadata.setPauseEventTypes(dealEventTypeForMetadata(getPauseEventTypes(), eventTypesActuallyShowUp));
metadata.setAllEventTypes(dealEventTypeForMetadata(getAllEventTypes(), eventTypesActuallyShowUp));
metadata.setMainPauseEventTypes(dealEventTypeForMetadata(getMainPauseEventTypes(), eventTypesActuallyShowUp));
metadata.setAnalysisConfig(AnalysisConfig.defaultConfig(this));
metadata.setParallelGCThreads(getParallelThread());
metadata.setConcurrentGCThreads(getConcurrentThread());
}
protected boolean isMetaspaceCapacityReliable() {
return metaspaceCapacityReliable;
}
public void setMetaspaceCapacityReliable(boolean metaspaceCapacityReliable) {
this.metaspaceCapacityReliable = metaspaceCapacityReliable;
}
public void setParallelThread(int parallelThread) {
this.parallelThread = parallelThread;
}
public void setConcurrentThread(int concurrentThread) {
this.concurrentThread = concurrentThread;
}
public int getParallelThread() {
if (parallelThread == Constant.UNKNOWN_INT && vmOptions != null) {
return vmOptions.<Long>getOptionValue("ParallelGCThreads", Constant.UNKNOWN_LONG).intValue();
}
return parallelThread;
}
public int getConcurrentThread() {
if (concurrentThread == Constant.UNKNOWN_INT && vmOptions != null) {
return vmOptions.<Long>getOptionValue("ConcGCThreads", Constant.UNKNOWN_LONG).intValue();
}
return concurrentThread;
}
public GlobalDiagnoseInfo getGlobalDiagnoseInfo(AnalysisConfig config) {
GlobalDiagnoseInfo result = globalDiagnoseInfoCache.get(config);
if (result == null) {
result = calculateGlobalDiagnoseInfo(config);
globalDiagnoseInfoCache.put(config, result);
}
return result;
}
private GlobalDiagnoseInfo calculateGlobalDiagnoseInfo(AnalysisConfig config) {
GlobalDiagnoseInfo info = new GlobalDiagnoseInfo(this, config);
EventAbnormalDetector abDetector = new EventAbnormalDetector(this, config, info);
abDetector.diagnose();
return info;
}
@Data
@NoArgsConstructor
@ToString
public static class GCDetailFilter {
private String eventType;
private GCCause gcCause;
//in ms
private double logTimeLow;
private double logTimeHigh;
private double pauseTimeLow;
public GCDetailFilter(String eventType, String gcCause, Double logTimeLow, Double logTimeHigh, Double pauseTimeLow) {
this.eventType = eventType;
this.gcCause = GCCause.getCause(gcCause);
this.logTimeLow = logTimeLow == null ? -Double.MAX_VALUE : logTimeLow;
this.logTimeHigh = logTimeHigh == null ? Double.MAX_VALUE : logTimeHigh;
this.pauseTimeLow = pauseTimeLow == null ? -Double.MAX_VALUE : pauseTimeLow;
}
public boolean isFiltered(GCEvent event) {
return event.getEventType() == SAFEPOINT ||
!((eventType == null || eventType.equals(event.getEventType().getName()))
&& (gcCause == null || gcCause == event.getCause())
&& (logTimeLow <= event.getEndTime() && event.getEndTime() <= logTimeHigh)
&& (pauseTimeLow <= event.getPause()));
}
}
}
| 6,766 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/ParallelGCModel.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import java.util.List;
import static org.eclipse.jifa.gclog.model.GCEventType.FULL_GC;
import static org.eclipse.jifa.gclog.model.GCEventType.YOUNG_GC;
public class ParallelGCModel extends GenerationalGCModel {
private static GCCollectorType collector = GCCollectorType.PARALLEL;
public ParallelGCModel() {
super(collector);
}
private static List<GCEventType> allEventTypes = GCModel.calcAllEventTypes(collector);
private static List<GCEventType> pauseEventTypes = GCModel.calcPauseEventTypes(collector);
private static List<GCEventType> mainPauseEventTypes = GCModel.calcMainPauseEventTypes(collector);
private static List<GCEventType> parentEventTypes = GCModel.calcParentEventTypes(collector);
private static List<GCEventType> importantEventTypes = List.of(YOUNG_GC, FULL_GC);
@Override
protected List<GCEventType> getAllEventTypes() {
return allEventTypes;
}
@Override
protected List<GCEventType> getPauseEventTypes() {
return pauseEventTypes;
}
@Override
protected List<GCEventType> getMainPauseEventTypes() {
return mainPauseEventTypes;
}
@Override
protected List<GCEventType> getImportantEventTypes() {
return importantEventTypes;
}
@Override
protected List<GCEventType> getParentEventTypes() {
return parentEventTypes;
}
}
| 6,767 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/GCModelFactory.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
public class GCModelFactory {
public static GCModel getModel(GCCollectorType collectorType) {
switch (collectorType) {
case G1:
return new G1GCModel();
case CMS:
return new CMSGCModel();
case SERIAL:
return new SerialGCModel();
case PARALLEL:
return new ParallelGCModel();
case ZGC:
return new ZGCModel();
case UNKNOWN:
return new UnknownGCModel();
default:
ErrorUtil.shouldNotReachHere();
}
return null;
}
}
| 6,768 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/GenerationalGCModel.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.GCCause;
import org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea;
import org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.model.modeInfo.GCLogStyle;
import java.util.ArrayList;
import java.util.List;
import static org.eclipse.jifa.gclog.model.GCEventType.FULL_GC;
import static org.eclipse.jifa.gclog.model.GCEventType.YOUNG_GC;
public abstract class GenerationalGCModel extends GCModel {
public GenerationalGCModel(GCCollectorType type) {
super(type);
}
private void dealYoungGCThatBecomeFullGCUnified() {
List<GCEvent> newEvents = new ArrayList<>();
List<GCEvent> oldEvents = getGcEvents();
boolean remove = false;
for (int i = 0; i < oldEvents.size() - 1; i++) {
GCEvent event = oldEvents.get(i);
GCEvent nextEvent = oldEvents.get(i + 1);
remove = event.getEventType() == YOUNG_GC && nextEvent.getEventType() == FULL_GC &&
event.getStartTime() <= nextEvent.getStartTime() && event.getEndTime() >= nextEvent.getEndTime();
if (remove) {
event.setEventType(FULL_GC);
event.setTrue(GCEventBooleanType.YOUNG_GC_BECOME_FULL_GC);
event.setPhases(nextEvent.getPhases());
i++; // remove the full gc
}
if (event.getEventType() == FULL_GC && event.isTrue(GCEventBooleanType.PROMOTION_FAILED)) {
event.setCause(GCCause.PROMOTION_FAILED);
}
newEvents.add(event);
}
if (!remove) {
newEvents.add(oldEvents.get(oldEvents.size() - 1));
}
setGcEvents(newEvents);
}
private void dealYoungGCThatBecomeFullGCPreUnified() {
for (GCEvent event : getGcEvents()) {
// if metaspace is printed, it must be a full gc
if (event.getEventType() == YOUNG_GC && event.getMemoryItem(MemoryArea.METASPACE) != null) {
event.setEventType(FULL_GC);
event.setTrue(GCEventBooleanType.YOUNG_GC_BECOME_FULL_GC);
}
if (event.getEventType() == FULL_GC && event.isTrue(GCEventBooleanType.PROMOTION_FAILED)) {
event.setCause(GCCause.PROMOTION_FAILED);
}
}
}
private void youngGenUsedShouldBeZeroAfterFullGC() {
if (getLogStyle() != GCLogStyle.PRE_UNIFIED) {
return;
}
for (GCEvent event : getGcEvents()) {
if (event.getEventType() == FULL_GC && event.getMemoryItem(MemoryArea.YOUNG) != null) {
event.getMemoryItem(MemoryArea.YOUNG).setPostUsed(0);
}
}
}
@Override
protected void doBeforeCalculatingDerivedInfo() {
if (getLogStyle() == GCLogStyle.UNIFIED) {
dealYoungGCThatBecomeFullGCUnified();
} else if (getLogStyle() == GCLogStyle.PRE_UNIFIED) {
dealYoungGCThatBecomeFullGCPreUnified();
}
youngGenUsedShouldBeZeroAfterFullGC();
}
}
| 6,769 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/SerialGCModel.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import java.util.List;
import static org.eclipse.jifa.gclog.model.GCEventType.FULL_GC;
import static org.eclipse.jifa.gclog.model.GCEventType.YOUNG_GC;
public class SerialGCModel extends GenerationalGCModel {
private static GCCollectorType collector = GCCollectorType.SERIAL;
public SerialGCModel() {
super(collector);
}
private static List<GCEventType> allEventTypes = GCModel.calcAllEventTypes(collector);
private static List<GCEventType> pauseEventTypes = GCModel.calcPauseEventTypes(collector);
private static List<GCEventType> mainPauseEventTypes = GCModel.calcMainPauseEventTypes(collector);
private static List<GCEventType> parentEventTypes = GCModel.calcParentEventTypes(collector);
private static List<GCEventType> importantEventTypes = List.of(YOUNG_GC, FULL_GC);
@Override
protected List<GCEventType> getAllEventTypes() {
return allEventTypes;
}
@Override
protected List<GCEventType> getPauseEventTypes() {
return pauseEventTypes;
}
@Override
protected List<GCEventType> getMainPauseEventTypes() {
return mainPauseEventTypes;
}
@Override
protected List<GCEventType> getImportantEventTypes() {
return importantEventTypes;
}
@Override
protected List<GCEventType> getParentEventTypes() {
return parentEventTypes;
}
}
| 6,770 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/ZGCModel.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.TimedEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.util.Constant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
public class ZGCModel extends GCModel {
// key of maps here should include unit like
// "Memory: Allocation Rate MB/s" to deduplicate
private List<ZStatistics> statistics = new ArrayList<>();
private List<GCEvent> allocationStalls = new ArrayList<>();
private long recommendMaxHeapSize = UNKNOWN_INT;
private static GCCollectorType collector = GCCollectorType.ZGC;
public ZGCModel() {
super(collector);
this.setMetaspaceCapacityReliable(true);
}
private static List<GCEventType> allEventTypes = GCModel.calcAllEventTypes(collector);
private static List<GCEventType> pauseEventTypes = GCModel.calcPauseEventTypes(collector);
private static List<GCEventType> mainPauseEventTypes = GCModel.calcMainPauseEventTypes(collector);
private static List<GCEventType> parentEventTypes = GCModel.calcParentEventTypes(collector);
private static List<GCEventType> importantEventTypes = List.of(ZGC_GARBAGE_COLLECTION, ZGC_PAUSE_MARK_START,
ZGC_PAUSE_MARK_END, ZGC_PAUSE_RELOCATE_START, ZGC_CONCURRENT_MARK, ZGC_CONCURRENT_NONREF,
ZGC_CONCURRENT_SELECT_RELOC_SET, ZGC_CONCURRENT_PREPARE_RELOC_SET, ZGC_CONCURRENT_RELOCATE);
@Override
protected List<GCEventType> getAllEventTypes() {
return allEventTypes;
}
@Override
protected List<GCEventType> getPauseEventTypes() {
return pauseEventTypes;
}
@Override
protected List<GCEventType> getMainPauseEventTypes() {
return mainPauseEventTypes;
}
@Override
protected List<GCEventType> getImportantEventTypes() {
return importantEventTypes;
}
@Override
protected List<GCEventType> getParentEventTypes() {
return parentEventTypes;
}
public List<GCEvent> getAllocationStalls() {
return allocationStalls;
}
public void addAllocationStalls(GCEvent allocationStall) {
this.allocationStalls.add(allocationStall);
}
public List<ZStatistics> getStatistics() {
return statistics;
}
@Override
public long getRecommendMaxHeapSize() {
if (recommendMaxHeapSize == UNKNOWN_INT && !statistics.isEmpty()) {
// used at marking start + garbage collection cycle * allocation rate
int statisticIndex = 0;
for (GCEvent collection : getGcCollectionEvents()) {
if (collection.getEventType() != ZGC_GARBAGE_COLLECTION) {
continue;
}
if (collection.getMemoryItem(MemoryArea.HEAP).getPreUsed() == UNKNOWN_INT) {
continue;
}
while (statisticIndex < statistics.size() &&
statistics.get(statisticIndex).getStartTime() < collection.getEndTime()) {
statisticIndex++;
}
if (statisticIndex >= statistics.size()) {
break;
}
double collectionCycleMs = statistics.get(statisticIndex).get("Collector: Garbage Collection Cycle ms").getMax10s();
double allocationRateMBps = statistics.get(statisticIndex).get("Memory: Allocation Rate MB/s").getMax10s();
double size = collection.getMemoryItem(MemoryArea.HEAP).getPreUsed() +
(collectionCycleMs / Constant.MS2S) * (allocationRateMBps * Constant.KB2MB);
recommendMaxHeapSize = Math.max(recommendMaxHeapSize, (long) size);
}
}
return recommendMaxHeapSize;
}
@NoArgsConstructor
@AllArgsConstructor
public static class ZStatistics extends TimedEvent {
private Map<String, ZStatisticsItem> items = new HashMap<>();
public ZStatisticsItem get(String key) {
return items.getOrDefault(key, null);
}
public void put(String key, ZStatisticsItem item) {
items.put(key, item);
}
public Map<String, ZStatisticsItem> getStatisticItems() {
return items;
}
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class ZStatisticsItem {
private double avg10s;
private double max10s;
private double avg10m;
private double max10m;
private double avg10h;
private double max10h;
private double avgTotal;
private double maxTotal;
}
}
| 6,771 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/CMSGCModel.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model;
import com.google.common.util.concurrent.AtomicDouble;
import org.eclipse.jifa.gclog.event.GCEvent;
import org.eclipse.jifa.gclog.event.evnetInfo.GCEventBooleanType;
import org.eclipse.jifa.gclog.model.modeInfo.GCCollectorType;
import org.eclipse.jifa.gclog.util.LongData;
import org.eclipse.jifa.gclog.vo.TimeRange;
import java.util.List;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_LONG;
import static org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea.METASPACE;
import static org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea.OLD;
import static org.eclipse.jifa.gclog.model.GCEventType.*;
public class CMSGCModel extends GenerationalGCModel {
private static GCCollectorType collector = GCCollectorType.CMS;
public CMSGCModel() {
super(collector);
}
private static List<GCEventType> allEventTypes = GCModel.calcAllEventTypes(collector);
private static List<GCEventType> pauseEventTypes = GCModel.calcPauseEventTypes(collector);
private static List<GCEventType> mainPauseEventTypes = GCModel.calcMainPauseEventTypes(collector);
private static List<GCEventType> parentEventTypes = GCModel.calcParentEventTypes(collector);
private static List<GCEventType> importantEventTypes = List.of(YOUNG_GC, FULL_GC, CMS_CONCURRENT_MARK_SWEPT,
CMS_INITIAL_MARK, CMS_CONCURRENT_ABORTABLE_PRECLEAN, CMS_FINAL_REMARK, CMS_CONCURRENT_SWEEP);
@Override
protected List<GCEventType> getAllEventTypes() {
return allEventTypes;
}
@Override
protected List<GCEventType> getPauseEventTypes() {
return pauseEventTypes;
}
@Override
protected List<GCEventType> getMainPauseEventTypes() {
return mainPauseEventTypes;
}
@Override
protected List<GCEventType> getImportantEventTypes() {
return importantEventTypes;
}
@Override
protected List<GCEventType> getParentEventTypes() {
return parentEventTypes;
}
@Override
protected void doAfterCalculatingDerivedInfo() {
decideGCsAfterOldGC();
}
private void decideGCsAfterOldGC() {
double lastCMSEndTime = Double.MAX_VALUE;
double lastRemarkEndTime = Double.MAX_VALUE;
for (GCEvent event : getGcEvents()) {
if (event.getEventType() == CMS_CONCURRENT_MARK_SWEPT) {
if (!event.containPhase(CMS_CONCURRENT_FAILURE) &&
!event.containPhase(CMS_CONCURRENT_INTERRUPTED)) {
lastCMSEndTime = event.getEndTime();
}
GCEvent remark = event.getLastPhaseOfType(CMS_FINAL_REMARK);
if (remark != null) {
lastRemarkEndTime = remark.getEndTime();
}
} else if ((event.getEventType() == YOUNG_GC || event.getEventType() == FULL_GC)) {
if (event.getStartTime() > lastRemarkEndTime) {
event.setTrue(GCEventBooleanType.GC_AFTER_REMARK);
lastRemarkEndTime = Double.MAX_VALUE;
}
if (event.getStartTime() > lastCMSEndTime) {
// Although jdk11 prints old gen usage after old gc, still use
// the next gc result for convenience
event.setTrue(GCEventBooleanType.GC_AT_END_OF_OLD_CYCLE);
lastCMSEndTime = Double.MAX_VALUE;
}
}
}
}
@Override
protected void calculateUsedAvgAfterOldGC(TimeRange range, LongData[][] data) {
iterateEventsWithinTimeRange(getGcEvents(), range, event -> {
if (event.isTrue(GCEventBooleanType.GC_AT_END_OF_OLD_CYCLE) && event.getMemoryItem(OLD) != null) {
data[1][3].add(event.getMemoryItem(OLD).getPreUsed());
}
if (event.isTrue(GCEventBooleanType.GC_AFTER_REMARK) && event.getMemoryItem(METASPACE) != null) {
data[4][3].add(event.getMemoryItem(METASPACE).getPreUsed());
}
});
}
}
| 6,772 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/modeInfo/GCCollectorType.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model.modeInfo;
public enum GCCollectorType {
SERIAL("Serial GC"),
PARALLEL("Parallel GC"),
ZGC("ZGC"),
SHENANDOAH("Shenandoah GC"),
G1("G1 GC"),
CMS("CMS GC"),
UNKNOWN("Unknown GC");
private String name;
GCCollectorType(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
| 6,773 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/modeInfo/GCLogMetadata.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model.modeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.jifa.gclog.diagnoser.AnalysisConfig;
import java.util.List;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
/**
* This class provides some necessary information to the frontend.
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class GCLogMetadata {
private String collector;
private String logStyle;
private double startTime = UNKNOWN_DOUBLE;
private double endTime = UNKNOWN_DOUBLE;
private double timestamp = UNKNOWN_DOUBLE;
private boolean generational = true;
private boolean pauseless = false;
private boolean metaspaceCapacityReliable = false;
private int parallelGCThreads = UNKNOWN_INT;
private int concurrentGCThreads = UNKNOWN_INT;
private List<String> parentEventTypes;
private List<String> importantEventTypes;
private List<String> pauseEventTypes;
private List<String> mainPauseEventTypes;
private List<String> allEventTypes;
private List<String> causes;
private AnalysisConfig analysisConfig;
}
| 6,774 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/modeInfo/GCLogStyle.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model.modeInfo;
public enum GCLogStyle {
PRE_UNIFIED("preunified"),
UNIFIED("unified"),
UNKNOWN("unknown");
private String name;
GCLogStyle(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
| 6,775 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/model/modeInfo/VmOptions.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.model.modeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.eclipse.jifa.gclog.util.GCLogUtil;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
import static org.eclipse.jifa.gclog.util.Constant.KB2MB;
public class VmOptions {
private Map<String, VmOption> options = new LinkedHashMap<>(); // use LinkedHashMap to preserve option order
private String originalOptionString;
private static Map<String, Integer> optionPriority = new ConcurrentHashMap<>();
static {
saveOptionsPriority();
}
private static void saveOptionsPriority() {
List.of("Xms",
"Xmx",
"Xmn",
"InitialHeapSize",
"MaxHeapSize",
"NewSize",
"NewRatio",
"MaxNewSize",
"MetaspaceSize",
"MaxMetaspaceSize",
"MaxDirectMemorySize").forEach(s -> optionPriority.put(s, 9));
List.of("UseCMSInitiatingOccupancyOnly",
"UseCMSCompactAtFullCollection",
"MaxGCPauseMillis",
"InitiatingHeapOccupancyPercent").forEach(s -> optionPriority.put(s, 7));
List.of("MinHeapFreeRatio",
"MaxHeapFreeRatio",
"MaxMetaspaceFreeRatio",
"MinMetaspaceFreeRatio",
"UseCompressedOops",
"UseCompressedClassPointers",
"SurvivorRatio",
"ExplicitGCInvokesConcurrent",
"DisableExplicitGC",
"ParallelRefProcEnabled",
"MaxTenuringThreshold",
"PrintPromotionFailure",
"TargetSurvivorRatio",
"ParGCCardsPerStrideChunk",
"UseGCOverheadLimit",
"ScavengeBeforeFullGC",
"PretenureSizeThreshold",
"InitialTenuringThreshold",
"GCTimeRatio",
"ExplicitGCInvokesConcurrentAndUnloadsClasses",
"SoftRefLRUPolicyMSPerMB",
"GCLockerRetryAllocationCount",
"UseCountedLoopSafepoints",
"ReduceInitialCardMarks",
"UseAdaptiveSizePolicy",
"ClassUnloading",
"ClassUnloadingWithConcurrentMark").forEach(s -> optionPriority.put(s, 6));
List.of("verbose",
"PrintHeapAtGC",
"PrintTenuringDistribution",
"PrintAdaptiveSizePolicy",
"UseAsyncGCLog",
"AsyncGCLogBufferSize",
"AsyncGCLogBufferFlushThreshold",
"UseGCLogFileRotation",
"NumberOfGCLogFiles",
"GCLogFileSize",
"PrintStringDeduplicationStatistics",
"PrintStringTableStatistics",
"PrintSafepointStatistics",
"PrintSafepointStatisticsCount",
"PrintFLSStatistics",
"PrintJNIGCStalls").forEach(s -> optionPriority.put(s, 5));
}
/* priority rule:
* 10: UseXXGC
* 9: Heap. generation and metaspace size
* 8: GC Threads related
* 7: GC specific tuning options
* 6: GC tuning options shared by gc collectors
* 5: GC log related
* 0: other
*/
private int getOptionPriority(String optionName) {
if (optionPriority.containsKey(optionName)) {
return optionPriority.get(optionName);
}
int priority;
if (optionName.startsWith("Use") && optionName.endsWith("GC")) {
priority = 10;
} else if (optionName.endsWith("GCThreads")) {
priority = 8;
} else if (optionName.startsWith("Z") || optionName.startsWith("G1") || optionName.startsWith("CMS")) {
priority = 7;
} else if (optionName.contains("PLAB") || optionName.contains("TLAB")) {
priority = 6;
} else if (optionName.startsWith("PrintGC") || optionName.startsWith("Xlog")) {
priority = 5;
} else {
priority = 0;
}
optionPriority.put(optionName, priority);
return priority;
}
// notice that integers are long type and options indicating size are in Byte
@SuppressWarnings("unchecked")
public <T> T getOptionValue(String key) {
if (options.containsKey(key)) {
return (T) options.get(key).getValue();
} else {
return null;
}
}
@SuppressWarnings("unchecked")
public <T> T getOptionValue(String key, T defaultValue) {
if (options.containsKey(key)) {
return (T) options.get(key).getValue();
} else {
return defaultValue;
}
}
public boolean containOption(String key) {
return options.containsKey(key);
}
public VmOptions(String vmOptionsString) {
originalOptionString = vmOptionsString;
if (vmOptionsString == null) {
return;
}
for (String option : vmOptionsString.split(" +")) {
addVmOption(option);
}
}
private void addVmOption(String optionString) {
if (optionString.startsWith("-XX:")) {
parseSingleOption(optionString, optionString.substring(4));
} else if (optionString.startsWith("-D")) {
parseSingleOption(optionString, optionString.substring(2));
} else if (optionString.startsWith("-X")) {
parseSingleOptionWithX(optionString, optionString.substring(2));
} else if (optionString.startsWith("-")) {
parseSingleOption(optionString, optionString.substring(1));
}
}
private void parseSingleOptionWithX(String optionString, String content) {
if (content == null) {
return;
}
if (content.startsWith("mn") || content.startsWith("ms") || content.startsWith("mx") || content.startsWith("ss")) {
// add 'X' for convention
String optionName = "X" + content.substring(0, 2);
options.put(optionName, new VmOption(optionString, optionName,
GCLogUtil.toByte(content.substring(2)) * (long) KB2MB, getOptionPriority(optionName)));
}
int mid = content.indexOf('=');
if (mid < 0) {
mid = content.indexOf(':');
}
if (mid >= 0) {
String optionName = 'X' + content.substring(0, mid);
options.put(optionName, new VmOption(optionString, optionName,
decideTypeAndParse(content.substring(mid + 1)), getOptionPriority(optionName)));
return;
}
options.put(content, new VmOption(optionString, content, true, getOptionPriority(content)));
}
private void parseSingleOption(String optionString, String content) {
if (content == null || content.isEmpty()) {
return;
}
if (content.charAt(0) == '+') {
String optionName = content.substring(1);
options.put(optionName, new VmOption(optionString, optionName, true, getOptionPriority(optionName)));
return;
}
if (content.charAt(0) == '-') {
String optionName = content.substring(1);
options.put(optionName, new VmOption(optionString, optionName, false, getOptionPriority(optionName)));
return;
}
int mid = content.indexOf('=');
if (mid < 0) {
mid = content.indexOf(':');
}
if (mid >= 0) {
String optionName = content.substring(0, mid);
options.put(optionName, new VmOption(optionString, optionName,
decideTypeAndParse(content.substring(mid + 1)), getOptionPriority(optionName)));
return;
}
options.put(content, new VmOption(optionString, content, true, getOptionPriority(content)));
}
private static final Pattern NUMBER_PATTERN = Pattern.compile("\\d+");
private static final Pattern SIZE_PATTERN = Pattern.compile("\\d+[kmgt]]?[b]?");
private Object decideTypeAndParse(String s) {
s = s.toLowerCase();
if (NUMBER_PATTERN.matcher(s).matches()) {
return Long.parseLong(s);
} else if (SIZE_PATTERN.matcher(s).matches()) {
return GCLogUtil.toByte(s);
} else {
return s;
}
}
public String getOriginalOptionString() {
return originalOptionString;
}
public long getMetaspaceSize() {
Long metaspaceSize = getOptionValue("MetaspaceSize");
Long maxMetaspaceSize = getOptionValue("MaxMetaspaceSize");
if (metaspaceSize != null && metaspaceSize.equals(maxMetaspaceSize)) {
return metaspaceSize;
} else {
return UNKNOWN_INT;
}
}
public VmOptionResult getVmOptionResult() {
VmOptionResult optionResult = new VmOptionResult();
options.values().stream()
.sorted((o1, o2) -> o2.priority - o1.priority)
.forEach(o -> (o.isGCRelated() ? optionResult.gcRelated : optionResult.other).add(new VmOptionVo(o.originalText)));
return optionResult;
}
@Override
public String toString() {
return options.toString();
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class VmOption {
private String originalText;
private String optionName;
private Object value;
private int priority;
public boolean isGCRelated() {
return priority != 0;
}
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class VmOptionVo {
private String text;
}
@Data
@NoArgsConstructor
public static class VmOptionResult {
private List<VmOptionVo> gcRelated = new ArrayList<>();
private List<VmOptionVo> other = new ArrayList<>();
}
}
| 6,776 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/ThreadEvent.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event;
import org.eclipse.jifa.gclog.diagnoser.GlobalDiagnoseInfo;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.vo.GCEventVO;
public class ThreadEvent extends GCEvent {
private String threadName;
public ThreadEvent() {
}
public String getThreadName() {
return threadName;
}
public void setThreadName(String threadName) {
this.threadName = threadName;
}
@Override
protected void appendClassSpecificInfo(StringBuilder sb) {
sb.append(threadName);
}
@Override
protected void fillInfoToVO(GCModel model, GCEventVO vo, GlobalDiagnoseInfo diagnose) {
super.fillInfoToVO(model, vo, diagnose);
vo.saveInfo("threadName", threadName);
}
}
| 6,777 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/TimedEvent.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event;
import org.eclipse.jifa.gclog.diagnoser.GlobalDiagnoseInfo;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.vo.GCEventVO;
import org.eclipse.jifa.gclog.vo.TimeRange;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
public class TimedEvent {
// We assume that start time always exists. We will refuse to analyze logs that does not print any time,
// and will add a suitable start time to events that does not have a start time in log.
// Unit of all time variables is ms.
protected double startTime = UNKNOWN_DOUBLE;
protected int id = UNKNOWN_INT; // id is used to identify events, should not be showed to user
// Real time duration of event. The duration may not exist, and we should always check its existence when using.
private double duration = UNKNOWN_DOUBLE;
public double getStartTime() {
return startTime;
}
public double getDuration() {
return duration;
}
public double getEndTime() {
if (getStartTime() != UNKNOWN_DOUBLE && getDuration() != UNKNOWN_DOUBLE) {
return getStartTime() + getDuration();
} else {
return UNKNOWN_DOUBLE;
}
}
public void setStartTime(double startTime) {
this.startTime = startTime;
}
public void setDuration(double duration) {
this.duration = duration;
}
public TimedEvent(double startTime, double duration) {
this.startTime = startTime;
this.duration = duration;
}
public TimedEvent(double startTime) {
this.startTime = startTime;
}
public TimedEvent() {
}
public static TimedEvent fromTimeRange(TimeRange range) {
return new TimedEvent(range.getStart(), range.length());
}
public TimeRange toTimeRange() {
if (duration != UNKNOWN_DOUBLE) {
return new TimeRange(getStartTime(), getEndTime());
} else {
return new TimeRange(getStartTime(), getStartTime());
}
}
public static TimedEvent newByStartEnd(double start, double end) {
return new TimedEvent(start, end - start);
}
protected void fillInfoToVO(GCModel model, GCEventVO vo, GlobalDiagnoseInfo diagnose) {
vo.saveInfo("id", id);
vo.saveInfo("startTime", getStartTime());
vo.saveInfo("duration", getDuration());
}
// notice: should call GCModel.transformEventsToVo to create a vo because diagnose info is filled there
public GCEventVO toEventVO(GCModel model, GlobalDiagnoseInfo diagnose) {
GCEventVO vo = new GCEventVO();
fillInfoToVO(model, vo, diagnose);
return vo;
}
}
| 6,778 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/GCEvent.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event;
import org.eclipse.jifa.common.util.ErrorUtil;
import org.eclipse.jifa.gclog.diagnoser.GlobalDiagnoseInfo;
import org.eclipse.jifa.gclog.event.evnetInfo.*;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.util.Constant;
import org.eclipse.jifa.gclog.vo.GCEventVO;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Consumer;
import static org.eclipse.jifa.gclog.event.evnetInfo.MemoryArea.*;
import static org.eclipse.jifa.gclog.event.evnetInfo.GCEventLevel.EVENT;
import static org.eclipse.jifa.gclog.event.evnetInfo.GCEventLevel.PHASE;
import static org.eclipse.jifa.gclog.util.Constant.KB2MB;
public class GCEvent extends TimedEvent {
/* All info saved here should not be relevant to AnalysisConfig. Anything related to the config
should be saved in EventDiagnoseInfo
**/
private int gcid = Constant.UNKNOWN_INT;
private CpuTime cpuTime;
private ReferenceGC referenceGC;
private GCEventType eventType = GCEventType.UNDEFINED;
private GCCause cause;
private GCMemoryItem[] memory;
// phases may contain more detailed info about an event. For simplicity, we put subphase of an event as
// a direct child in phases field rather than child of child. Use level field of EventType to check
// if an event type should be a subphase.
private List<GCEvent> phases;
private BitSet booleans;
private double pause = Constant.UNKNOWN_DOUBLE;
private double interval = Constant.UNKNOWN_DOUBLE; // interval from last event with same type
private double causeInterval = Constant.UNKNOWN_DOUBLE; // interval from last event with same type and cause
private long promotion = Constant.UNKNOWN_INT;
private long allocation = Constant.UNKNOWN_INT;
private long reclamation = Constant.UNKNOWN_INT;
public GCMemoryItem[] getMemoryItems() {
return memory;
}
public GCMemoryItem getMemoryItem(MemoryArea area) {
if (memory == null) {
return null;
}
return memory[area.ordinal()];
}
public GCMemoryItem getMemoryItemOrEmptyObject(MemoryArea area) {
GCMemoryItem result = getMemoryItem(area);
if (result == null) {
return new GCMemoryItem(area);
} else {
return result;
}
}
public void setMemoryItem(GCMemoryItem item) {
setMemoryItem(item, false);
}
public void setMemoryItem(GCMemoryItem item, boolean force) {
if (item == null || item.isEmpty()) {
return;
}
if (memory == null) {
memory = new GCMemoryItem[values().length];
}
if (force || getMemoryItem(item.getArea()) == null) {
memory[item.getArea().ordinal()] = item;
}
}
public void setMemoryItems(GCMemoryItem[] memory) {
this.memory = memory;
}
public List<GCEvent> getPhases() {
return phases;
}
public GCEvent() {
}
public void setGcid(int gcid) {
this.gcid = gcid;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public GCEvent getLastPhaseOfType(GCEventType type) {
if (phases == null) {
return null;
}
for (int i = phases.size() - 1; i >= 0; i--) {
GCEvent phase = phases.get(i);
if (phase.getEventType().equals(type)) {
return phase;
}
}
return null;
}
public boolean containPhase(GCEventType type) {
return getLastPhaseOfType(type) != null;
}
public void setBoolean(GCEventBooleanType type, boolean value) {
if (booleans == null) {
booleans = new BitSet();
}
booleans.set(type.ordinal(), value);
}
public void setTrue(GCEventBooleanType type) {
setBoolean(type, true);
}
public boolean isTrue(GCEventBooleanType type) {
return booleans != null && booleans.get(type.ordinal());
}
public ReferenceGC getReferenceGC() {
return referenceGC;
}
public void setReferenceGC(ReferenceGC referenceGC) {
this.referenceGC = referenceGC;
}
public int getGcid() {
return gcid;
}
public GCEventType getEventType() {
return eventType;
}
public boolean isYoungGC() {
return this.eventType != null && this.eventType.isYoungGC();
}
public boolean isOldGC() {
return this.eventType != null && this.eventType.isOldGC();
}
public boolean isFullGC() {
return this.eventType != null && this.eventType.isFullGC();
}
public GCCause getCause() {
return cause;
}
public CpuTime getCpuTime() {
return cpuTime;
}
public long getAllocation() {
return allocation;
}
public long getReclamation() {
return reclamation;
}
public void setPromotion(long promotion) {
if (promotion < 0) {
promotion = Constant.UNKNOWN_INT;
}
this.promotion = promotion;
}
public void setAllocation(long allocation) {
if (allocation < 0) {
allocation = Constant.UNKNOWN_INT;
}
this.allocation = allocation;
}
public void setReclamation(long reclamation) {
if (reclamation < 0) {
reclamation = Constant.UNKNOWN_INT;
}
this.reclamation = reclamation;
}
public void setEventType(GCEventType eventType) {
this.eventType = eventType;
}
public void setCause(String cause) {
this.cause = GCCause.getCause(cause);
}
public void setCause(GCCause cause) {
this.cause = cause;
}
public void setCpuTime(CpuTime cpuTime) {
this.cpuTime = cpuTime;
}
public boolean hasPhases() {
return phases != null;
}
public void addPhase(GCEvent phase) {
if (phases == null) {
phases = new ArrayList<>(2);
}
phases.add(phase);
}
public void setPhases(List<GCEvent> phases) {
this.phases = phases;
}
public boolean hasPromotion() {
return eventType != null && eventType.hasObjectPromotion();
}
public double getInterval() {
return interval;
}
public void setInterval(double interval) {
this.interval = interval;
}
public double getCauseInterval() {
return causeInterval;
}
public void setCauseInterval(double causeInterval) {
this.causeInterval = causeInterval;
}
public boolean isPause() {
return getEventType().getPause() == GCPause.PAUSE;
}
public boolean isPartialConcurrent() {
return getEventType().getPause() == GCPause.PARTIAL;
}
public boolean isConcurrent() {
return getEventType().getPause() == GCPause.CONCURRENT;
}
public boolean isBadFullGC() {
return isFullGC() && getCause().isBad();
}
private static final double GCTRACETIME_TRACECPUTIME_CLOSE_THRESHOLD = 10.0;
public double getPause() {
if (pause == Constant.UNKNOWN_DOUBLE) {
switch (eventType.getPause()) {
case PAUSE:
// In most cases, duration is more accurate than cputime because of rounding error.
// In very rare cases, cputime may be significantly larger than duration. In these cases
// cputime is more accurate value.
if (cpuTime != null) {
if (getDuration() != Constant.UNKNOWN_DOUBLE &&
Math.abs(cpuTime.getReal() - getDuration()) > GCTRACETIME_TRACECPUTIME_CLOSE_THRESHOLD) {
pause = getCpuTime().getReal();
} else {
pause = getDuration();
}
} else {
pause = getDuration();
}
break;
case CONCURRENT:
pause = 0;
break;
case PARTIAL:
pause = 0;
if (phases != null) {
for (GCEvent phase : phases) {
if (phase.getEventType().getPause() == GCPause.PAUSE && phase.getEventLevel() == PHASE) {
pause += phase.getPause();
}
}
}
break;
default:
ErrorUtil.shouldNotReachHere();
}
}
return pause;
}
public long getPromotion() {
return promotion;
}
private static final SimpleDateFormat TIMESTAMP_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
protected void appendStartTimestamp(StringBuilder sb, double referenceTimestamp) {
if (referenceTimestamp != Constant.UNKNOWN_DOUBLE && startTime != Constant.UNKNOWN_DOUBLE) {
sb.append(TIMESTAMP_FORMAT.format((long) (referenceTimestamp + startTime))).append(" ");
}
}
protected void appendStartTime(StringBuilder sb) {
if (startTime != Constant.UNKNOWN_DOUBLE) {
sb.append(String.format("%.3f: ", getStartTime() / 1000));
}
}
private void appendGCSpecialSituation(StringBuilder sb) {
List<String> parts = new ArrayList<>();
if (isTrue(GCEventBooleanType.INITIAL_MARK)) {
parts.add("Initial Mark");
}
if (isTrue(GCEventBooleanType.PREPARE_MIXED)) {
parts.add("Prepare Mixed");
}
if (isTrue(GCEventBooleanType.TO_SPACE_EXHAUSTED)) {
parts.add("To-space Exhausted");
}
if (parts.isEmpty()) {
return;
}
sb.append("(");
for (int i = 0; i < parts.size(); i++) {
if (i != 0) {
sb.append(", ");
}
sb.append(parts.get(i));
}
sb.append(") ");
}
private void appendEventType(StringBuilder sb) {
sb.append(eventType).append(" ");
}
protected void appendClassSpecificInfo(StringBuilder sb) {
if (gcid != Constant.UNKNOWN_INT) {
sb.append('(').append(gcid).append(") ");
}
if (cause != null) {
sb.append("(").append(cause).append(") ");
}
appendGCSpecialSituation(sb);
if (getDuration() != Constant.UNKNOWN_DOUBLE) {
sb.append(String.format("%.3f", getDuration() / 1000)).append("s ");
}
memoryItemDo(item -> sb.append("[").append(item).append("] "));
boolean moreInfoAvailable = getEventLevel() == EVENT
&& (getPromotion() != Constant.UNKNOWN_INT || getInterval() != Constant.UNKNOWN_DOUBLE);
if (moreInfoAvailable) {
boolean first = true;
sb.append("[");
if (getPromotion() != Constant.UNKNOWN_INT) {
sb.append("promotion ").append(getPromotion() / (long) KB2MB).append(" K");
first = false;
}
if (getInterval() != Constant.UNKNOWN_INT) {
if (!first) {
sb.append(", ");
}
sb.append("interval ").append(String.format("%.3f", getInterval() / 1000)).append(" s");
}
sb.append("] ");
}
if (cpuTime != null) {
sb.append("[").append(cpuTime).append("] ");
}
}
// this function is used for printing while debugging. The result is never showed to user
// reference format: 14.244: Full GC (1) (Ergonomics) 0.001s [Young: 2548K->0K(18944K)] [Old: 33595K->11813K(44032K)] [Total: 36143K->11813K(62976K)] [Metaspace: 19355K->19355K(1067008K)] [promotion 3000 K, interval 30 s]
public String toDebugString(GCModel model) {
StringBuilder sb = new StringBuilder();
appendStartTimestamp(sb, model.getReferenceTimestamp());
appendStartTime(sb);
appendEventType(sb);
appendClassSpecificInfo(sb);
return sb.toString();
}
// This function is used for printing while debugging(mainly used in IDE). The result is nover showed to user.
// toDebugString shows more info than this function
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
appendStartTime(sb);
appendEventType(sb);
appendClassSpecificInfo(sb);
return sb.toString();
}
public GCEventLevel getEventLevel() {
return eventType.getLevel();
}
public void pauseEventOrPhasesDo(Consumer<GCEvent> consumer) {
if (getEventLevel() != EVENT || isTrue(GCEventBooleanType.IGNORE_PAUSE)) {
return;
}
switch (getEventType().getPause()) {
case PAUSE:
consumer.accept(this);
break;
case PARTIAL:
phasesDoDFS(phase -> {
if (phase.getEventType().getPause() == GCPause.PAUSE && phase.getEventType().getLevel() == PHASE) {
consumer.accept(phase);
}
});
}
}
public void memoryItemDo(Consumer<GCMemoryItem> consumer) {
if (memory == null) {
return;
}
for (GCMemoryItem item : memory) {
if (item != null && !item.isEmpty()) {
consumer.accept(item);
}
}
}
public void phasesDoDFS(Consumer<GCEvent> consumer) {
if (phases != null) {
for (GCEvent phase : phases) {
consumer.accept(phase);
}
}
}
private Map<String, GCMemoryItem> memoryToVO() {
Map<String, GCMemoryItem> result = new HashMap<>();
memoryItemDo(item -> result.put(item.getArea().getName(), item));
return result;
}
@Override
protected void fillInfoToVO(GCModel model, GCEventVO vo, GlobalDiagnoseInfo diagnose) {
super.fillInfoToVO(model, vo, diagnose);
vo.saveInfo("eventType", eventType.getName());
vo.saveInfo("gcid", gcid);
vo.saveInfo("cputime", cpuTime);
vo.saveInfo("referenceGC", referenceGC);
vo.saveInfo("memory", memoryToVO());
vo.saveInfo("pause", pause);
vo.saveInfo("interval", interval);
vo.saveInfo("causeInterval", causeInterval);
vo.saveInfo("promotion", promotion);
vo.saveInfo("reclamation", reclamation);
vo.saveInfo("allocation", allocation);
phasesDoDFS(phase -> vo.addPhase(phase.toEventVO(model, diagnose)));
vo.saveInfo("diagnose", diagnose.getEventDiagnoseVO(this));
for (GCEventBooleanType type : GCEventBooleanType.values()) {
if (isTrue(type)) {
vo.saveInfo(type.name(), true);
}
}
if (cause != null) {
vo.saveInfo("cause", cause.getName());
}
}
}
| 6,779 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/Safepoint.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event;
import org.eclipse.jifa.gclog.model.GCEventType;
import org.eclipse.jifa.gclog.model.GCModel;
import org.eclipse.jifa.gclog.util.Constant;
public class Safepoint extends GCEvent {
private double timeToEnter = Constant.UNKNOWN_DOUBLE;
public Safepoint() {
this.setEventType(GCEventType.SAFEPOINT);
}
public double getTimeToEnter() {
return timeToEnter;
}
public void setTimeToEnter(double timeToEnter) {
this.timeToEnter = timeToEnter;
}
@Override
protected void appendClassSpecificInfo(StringBuilder sb) {
sb.append(String.format("Total time for which application threads were stopped: " +
"%.3f seconds, Stopping threads took: %.3f seconds", getDuration(), getTimeToEnter()));
}
@Override
public String toDebugString(GCModel model) {
StringBuilder sb = new StringBuilder();
appendStartTimestamp(sb, model.getStartTime());
appendStartTime(sb);
appendClassSpecificInfo(sb);
return sb.toString();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
appendStartTime(sb);
appendClassSpecificInfo(sb);
return sb.toString();
}
}
| 6,780 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/evnetInfo/GCEventBooleanType.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event.evnetInfo;
/*
* This class records some boolean types related to a GCEvent. They will be saved in a BitSet of GCEvent,
* Each boolean should have the default value false.
*/
public enum GCEventBooleanType {
PROMOTION_FAILED,
// this gc is just after a cms or g1 remark
GC_AFTER_REMARK,
// this event is just after a cms cycle, or last mixed gc of an old cycle in g1, or the Prepare Mixed gc
// because no mixed gc will be scheduled
GC_AT_END_OF_OLD_CYCLE,
// pause of this event should not be included in statistics
IGNORE_PAUSE,
TO_SPACE_EXHAUSTED,
YOUNG_GC_BECOME_FULL_GC,
INITIAL_MARK,
PREPARE_MIXED;
}
| 6,781 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/evnetInfo/ReferenceGC.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event.evnetInfo;
import lombok.Data;
import lombok.NoArgsConstructor;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
@Data
@NoArgsConstructor
public class ReferenceGC {
private double softReferenceStartTime = UNKNOWN_DOUBLE;
private int softReferenceCount = UNKNOWN_INT;
private double softReferencePauseTime = UNKNOWN_DOUBLE;
private double weakReferenceStartTime = UNKNOWN_DOUBLE;
private int weakReferenceCount = UNKNOWN_INT;
private double weakReferencePauseTime = UNKNOWN_DOUBLE;
private double finalReferenceStartTime = UNKNOWN_DOUBLE;
private int finalReferenceCount = UNKNOWN_INT;
private double finalReferencePauseTime = UNKNOWN_DOUBLE;
private double phantomReferenceStartTime = UNKNOWN_DOUBLE;
private int phantomReferenceCount = UNKNOWN_INT;
private int phantomReferenceFreedCount;
private double phantomReferencePauseTime = UNKNOWN_DOUBLE;
private double jniWeakReferenceStartTime = UNKNOWN_DOUBLE;
private double jniWeakReferencePauseTime = UNKNOWN_DOUBLE;
}
| 6,782 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/evnetInfo/MemoryArea.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event.evnetInfo;
public enum MemoryArea {
EDEN("eden"),
SURVIVOR("survivor"),
YOUNG("young"),
OLD("old"),
HUMONGOUS("humongous"),
ARCHIVE("archive"),
HEAP("heap"), //young + old + humongous
METASPACE("metaspace"), // also represents perm
CLASS("class"),
NONCLASS("nonclass");
public static MemoryArea getMemoryArea(String name) {
if (name == null) {
return null;
}
switch (name.trim().toLowerCase()) {
case "young":
case "parnew":
case "defnew":
case "psyounggen":
return YOUNG;
case "eden":
return EDEN;
case "survivor":
case "survivors":
return SURVIVOR;
case "tenured":
case "old":
case "psoldgen":
case "paroldgen":
case "cms":
case "ascms":
return OLD;
case "metaspace":
case "perm":
return METASPACE;
case "class":
return CLASS;
case "nonclass":
return NONCLASS;
case "humongous":
return HUMONGOUS;
case "archive":
return ARCHIVE;
case "total":
case "heap":
return HEAP;
default:
return null;
}
}
private final String name;
MemoryArea(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
| 6,783 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/evnetInfo/GCCause.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event.evnetInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GCCause {
private String name;
private static final Map<String, GCCause> name2cause = new HashMap<>();
public static GCCause SYSTEM_GC = new GCCause("System.gc()");
public static GCCause DIAGNOSTIC_COMMAND = new GCCause("Diagnostic Command");
public static GCCause FULL_GC_ALOT = new GCCause("FullGCALot");
public static GCCause SCAVENGE_ALOT = new GCCause("ScavengeAlot");
public static GCCause ALLOCATION_PROFILER = new GCCause("Allocation Profiler");
public static GCCause JVMTI_FORCE_GC = new GCCause("JvmtiEnv ForceGarbageCollection");
public static GCCause ARCHIVE_SHARE_GC = new GCCause("Full GC for -Xshare:dump");
public static GCCause GC_LOCKER = new GCCause("GCLocker Initiated GC");
public static GCCause HEAP_INSPECTION = new GCCause("Heap Inspection Initiated GC");
public static GCCause HEAP_DUMP = new GCCause("Heap Dump Initiated GC");
public static GCCause NO_GC = new GCCause("No GC");
public static GCCause ALLOCATION_FAILURE = new GCCause("Allocation Failure");
public static GCCause TENURED_GENERATION_FULL = new GCCause("Tenured Generation Full");
public static GCCause METADATA_GENERATION_THRESHOLD = new GCCause("Metadata GC Threshold");
public static GCCause PERMANENT_GENERATION_FULL = new GCCause("Permanent Generation Full");
public static GCCause CMS_GENERATION_FULL = new GCCause("CMS Generation Full");
public static GCCause CMS_INITIAL_MARK = new GCCause("CMS Initial Mark");
public static GCCause CMS_FINAL_REMARK = new GCCause("CMS Final Remark");
public static GCCause CMS_CONCURRENT_MARK = new GCCause("CMS Concurrent Mark");
public static GCCause CMS_FAILURE = new GCCause("CMS Failure");
public static GCCause OLD_GENERATION_EXPANDED_ON_LAST_SCAVENGE = new GCCause("Old Generation Expanded On Last Scavenge");
public static GCCause OLD_GENERATION_TOO_FULL_TO_SCAVENGE = new GCCause("Old Generation Too Full To Scavenge");
public static GCCause ERGONOMICS = new GCCause("Ergonomics");
public static GCCause G1_EVACUATION_PAUSE = new GCCause("G1 Evacuation Pause");
public static GCCause G1_HUMONGOUS_ALLOCATION = new GCCause("G1 Humongous Allocation");
public static GCCause LAST_DITCH_COLLECTION = new GCCause("Last ditch collection");
public static GCCause LAST_GC_CAUSE = new GCCause("ILLEGAL VALUE - last gc cause - ILLEGAL VALUE");
public static GCCause PROMOTION_FAILED = new GCCause("Promotion Failed");
public static GCCause UPDATE_ALLOCATION_CONTEXT_STATS = new GCCause("Update Allocation Context Stats");
public static GCCause WHITEBOX_YOUNG = new GCCause("WhiteBox Initiated Young GC");
public static GCCause WHITEBOX_CONCURRENT_MARK = new GCCause("WhiteBox Initiated Concurrent Mark");
public static GCCause WHITEBOX_FULL = new GCCause("WhiteBox Initiated Full GC");
public static GCCause META_CLEAR_SOFT_REF = new GCCause("Metadata GC Clear Soft References");
public static GCCause TIMER = new GCCause("Timer");
public static GCCause WARMUP = new GCCause("Warmup");
public static GCCause ALLOC_RATE = new GCCause("Allocation Rate");
public static GCCause ALLOC_STALL = new GCCause("Allocation Stall");
public static GCCause PROACTIVE = new GCCause("Proactive");
public static GCCause PREVENTIVE = new GCCause("G1 Preventive Collection");
public static GCCause G1_COMPACTION = new GCCause("G1 Compaction Pause");
public static GCCause UNKNOWN_GCCAUSE = new GCCause("unknown GCCause");
static {
name2cause.put("System.gc", SYSTEM_GC); // HACK: sometimes "()" is missing
}
private GCCause(String name) {
this.name = name;
name2cause.put(name, this);
}
public static GCCause getCause(String name) {
return name2cause.getOrDefault(name, null);
}
public String getName() {
return name;
}
public boolean isMetaspaceFullGCCause() {
return this == METADATA_GENERATION_THRESHOLD || this == META_CLEAR_SOFT_REF || this == LAST_DITCH_COLLECTION;
}
private static final List<GCCause> HeapMemoryTriggeredFullGCCauses = List.of(GC_LOCKER, ALLOCATION_FAILURE,
ERGONOMICS, G1_HUMONGOUS_ALLOCATION, PROMOTION_FAILED, G1_COMPACTION);
public boolean isHeapMemoryTriggeredFullGCCause() {
return HeapMemoryTriggeredFullGCCauses.contains(this);
}
public boolean isSystemGC() {
return this == SYSTEM_GC;
}
public boolean isBad() {
return isSystemGC() || isMetaspaceFullGCCause() || isHeapMemoryTriggeredFullGCCause();
}
@Override
public String toString() {
return name;
}
}
| 6,784 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/evnetInfo/GCMemoryItem.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event.evnetInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Objects;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_INT;
import static org.eclipse.jifa.gclog.util.Constant.KB2MB;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GCMemoryItem {
private MemoryArea area;
// memory size in kb
private long preUsed = UNKNOWN_INT;
private long preCapacity = UNKNOWN_INT;
private long postUsed = UNKNOWN_INT;
private long postCapacity = UNKNOWN_INT;
public GCMemoryItem(MemoryArea area) {
this.area = area;
}
public GCMemoryItem(MemoryArea area, long preUsed, long postUsed, long postCapacity) {
this.area = area;
this.preUsed = preUsed;
this.postUsed = postUsed;
this.postCapacity = postCapacity;
}
public GCMemoryItem(MemoryArea area, long[] memories) {
this(area, memories[0], memories[1], memories[2], memories[3]);
}
public long getMemoryReduction() {
return minus(preUsed, postUsed);
}
/**
* unknown value in this or anotherItem will lead result to be unknown.
*/
public GCMemoryItem merge(GCMemoryItem anotherItem) {
if (anotherItem == null) {
return new GCMemoryItem(area);
}
return new GCMemoryItem(area,
plus(preUsed, anotherItem.preUsed),
plus(preCapacity, anotherItem.preCapacity),
plus(postUsed, anotherItem.postUsed),
plus(postCapacity, anotherItem.postCapacity));
}
/**
* unknown value in this will lead result to be unknown.
* unknown value in anotherItem are seen as 0
*/
public GCMemoryItem mergeIfPresent(GCMemoryItem anotherItem) {
if (anotherItem == null) {
return this;
}
return new GCMemoryItem(area,
plusIfPresent(preUsed, anotherItem.preUsed),
plusIfPresent(preCapacity, anotherItem.preCapacity),
plusIfPresent(postUsed, anotherItem.postUsed),
plusIfPresent(postCapacity, anotherItem.postCapacity));
}
/**
* unknown value in this or anotherItem will lead result to be unknown.
*/
public GCMemoryItem subtract(GCMemoryItem anotherItem) {
if (anotherItem == null) {
return new GCMemoryItem(area);
}
return new GCMemoryItem(area,
minus(preUsed, anotherItem.preUsed),
minus(preCapacity, anotherItem.preCapacity),
minus(postUsed, anotherItem.postUsed),
minus(postCapacity, anotherItem.postCapacity));
}
/**
* unknown value in this will lead result to be unknown.
* unknown value in anotherItem are seen as 0
*/
public GCMemoryItem subtractIfPresent(GCMemoryItem anotherItem) {
if (anotherItem == null) {
return this;
}
return new GCMemoryItem(area,
minusIfPresent(preUsed, anotherItem.preUsed),
minusIfPresent(preCapacity, anotherItem.preCapacity),
minusIfPresent(postUsed, anotherItem.postUsed),
minusIfPresent(postCapacity, anotherItem.postCapacity));
}
public GCMemoryItem updateIfAbsent(GCMemoryItem anotherItem) {
if (anotherItem == null) {
return this;
}
return new GCMemoryItem(area,
preUsed == UNKNOWN_INT ? anotherItem.preUsed : preUsed,
preCapacity == UNKNOWN_INT ? anotherItem.preCapacity : preCapacity,
postUsed == UNKNOWN_INT ? anotherItem.postUsed : postUsed,
postCapacity == UNKNOWN_INT ? anotherItem.postCapacity : postCapacity);
}
private static long plus(long x, long y) {
if (x == UNKNOWN_INT || y == UNKNOWN_INT) {
return UNKNOWN_INT;
}
return x + y;
}
private static long plusIfPresent(long x, long y) {
if (x == UNKNOWN_INT || y == UNKNOWN_INT) {
return x;
}
return x + y;
}
private static long minus(long x, long y) {
if (x == UNKNOWN_INT || y == UNKNOWN_INT) {
return UNKNOWN_INT;
}
return x >= y ? x - y : 0;
}
private static long minusIfPresent(long x, long y) {
if (x == UNKNOWN_INT || y == UNKNOWN_INT) {
return x;
}
return x >= y ? x - y : 0;
}
public void multiply(long x) {
if (preUsed != UNKNOWN_INT) {
preUsed *= x;
}
if (preCapacity != UNKNOWN_INT) {
preCapacity *= x;
}
if (postUsed != UNKNOWN_INT) {
postUsed *= x;
}
if (postCapacity != UNKNOWN_INT) {
postCapacity *= x;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GCMemoryItem item = (GCMemoryItem) o;
return preUsed == item.preUsed && preCapacity == item.preCapacity && postUsed == item.postUsed && postCapacity == item.postCapacity && area == item.area;
}
@Override
public int hashCode() {
return Objects.hash(area, preUsed, preCapacity, postUsed, postCapacity);
}
public boolean isEmpty() {
return preUsed == UNKNOWN_INT && preCapacity == UNKNOWN_INT && postUsed == UNKNOWN_INT && postCapacity == UNKNOWN_INT;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
String area = this.area.toString().toLowerCase();
sb.append((char) (area.charAt(0) - 32)).append(area.substring(1)).append(": ");
if (isEmpty()) {
sb.append("unknown");
} else {
if (preUsed != UNKNOWN_INT) {
sb.append((long) (Math.max(0, preUsed) / KB2MB / KB2MB)).append("M");
}
if (preCapacity != UNKNOWN_INT) {
sb.append('(').append((long) (Math.max(0, preCapacity) / KB2MB / KB2MB)).append("M)");
}
if (preUsed != UNKNOWN_INT || preCapacity != UNKNOWN_INT) {
sb.append("->");
}
if (postUsed != UNKNOWN_INT) {
sb.append((long) (Math.max(0, postUsed) / KB2MB / KB2MB)).append('M');
} else {
sb.append("unknown");
}
if (postCapacity != UNKNOWN_INT) {
sb.append('(').append((long) (Math.max(0, postCapacity) / KB2MB / KB2MB)).append("M)");
}
}
return sb.toString();
}
}
| 6,785 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/evnetInfo/CpuTime.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event.evnetInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import static org.eclipse.jifa.gclog.util.Constant.UNKNOWN_DOUBLE;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CpuTime {
//unit is ms
private double user = UNKNOWN_DOUBLE;
private double sys = UNKNOWN_DOUBLE;
private double real = UNKNOWN_DOUBLE;
public String toString() {
return String.format("User=%.2fs Sys=%.2fs Real=%.2fs", user / 1000, sys / 1000, real / 1000);
}
}
| 6,786 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/evnetInfo/GCEventLevel.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event.evnetInfo;
public enum GCEventLevel {
EVENT,
PHASE,
SUBPHASE,
}
| 6,787 |
0 | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event | Create_ds/eclipse-jifa/backend/gc-log-analyzer/src/main/java/org/eclipse/jifa/gclog/event/evnetInfo/GCPause.java | /********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.gclog.event.evnetInfo;
public enum GCPause {
PAUSE,
CONCURRENT,
PARTIAL // to get its pause time, we need to consider its paused phases
}
| 6,788 |
0 | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master/Master.java | /********************************************************************************
* Copyright (c) 2020, 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.master;
import io.reactivex.Single;
import io.vertx.config.ConfigRetrieverOptions;
import io.vertx.config.ConfigStoreOptions;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Promise;
import io.vertx.core.json.JsonObject;
import io.vertx.reactivex.config.ConfigRetriever;
import io.vertx.reactivex.core.AbstractVerticle;
import io.vertx.reactivex.core.Vertx;
import io.vertx.reactivex.ext.web.client.WebClient;
import org.eclipse.jifa.master.http.HttpServerVerticle;
import org.eclipse.jifa.master.service.ServiceVerticle;
import org.eclipse.jifa.master.support.WorkerClient;
public class Master extends AbstractVerticle implements Constant {
private static final String DEV_CONF = "master-config-dev.json";
public static boolean DEV_MODE = false;
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(Master.class.getName());
}
@Override
public void start(Promise<Void> startFuture) {
String mc = System.getProperty("jifa.master.config", DEV_CONF);
DEV_MODE = DEV_CONF.endsWith(mc);
ConfigRetriever configRetriever =
ConfigRetriever.create(vertx, new ConfigRetrieverOptions().addStore(
new ConfigStoreOptions().setType("file")
.setConfig(new JsonObject().put("path", mc))));
configRetriever.rxGetConfig().subscribe(masterConfig -> {
WorkerClient.init(masterConfig.getJsonObject(WORKER_CONFIG_KEY), WebClient.create(vertx));
// service
Single<String> service = vertx.rxDeployVerticle(ServiceVerticle.class.getName(), new DeploymentOptions()
.setConfig(masterConfig));
DeploymentOptions httpConfig =
new DeploymentOptions().setConfig(masterConfig.getJsonObject(HTTP_VERTICLE_CONFIG_KEY))
.setInstances(Runtime.getRuntime().availableProcessors());
service.flatMap(id -> vertx.rxDeployVerticle(HttpServerVerticle.class.getName(), httpConfig))
.subscribe(id -> startFuture.complete(), startFuture::fail);
}, startFuture::fail);
}
}
| 6,789 |
0 | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master/Constant.java | /********************************************************************************
* Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.master;
public interface Constant extends org.eclipse.jifa.common.Constant {
/**
* TOP CONFIG KEY
*/
String HTTP_VERTICLE_CONFIG_KEY = "http-verticle-config";
String WORKER_CONFIG_KEY = "worker-config";
/**
* Database
*/
String DB_KEYWORD = "database";
String DB_USERNAME = "username";
String DB_PASSWORD = "password";
String DB_URL = "url";
String DB_DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";
/**
* User
*/
String USER_ID_KEY = "id";
String USER_NAME_KEY = "name";
String USER_IS_ADMIN_KEY = "isAdmin";
String USER_INFO_KEY = "userInfo";
/**
* JWT
*/
String JWT_SUBJECT = "Jifa Master";
String JWT_ISSUER = "Jifa Master";
String JWT_ALGORITHM_HS256 = "HS256";
String JWT_ALGORITHM_HS256_PUBLIC_KEY = "Jifa Master Public Key";
int JWT_EXPIRES_IN_MINUTES = 7 * 24 * 60; // seven days
/**
* BASE URL
*/
String BASE = "/jifa-api";
String AUTH = "/auth";
String USER_INFO = "/userInfo";
/**
* FILE URL
*/
String FILES = "/files";
String FILE = "/file";
String PUBLIC_KEY = "/publicKey";
String FILE_SET_SHARED = "/file/setShared";
String FILE_UNSET_SHARED = "/file/unsetShared";
String FILE_DELETE = "/file/delete";
String FILE_BATCH_DELETE = "/file/batchDelete";
String FILE_SYNC = "/file/sync";
String FILE_UPLOAD = "/file/upload";
String TRANSFER_BY_URL = "/file/transferByURL";
String TRANSFER_BY_SCP = "/file/transferBySCP";
String TRANSFER_BY_OSS = "/file/transferByOSS";
String TRANSFER_BY_S3 = "/file/transferByS3";
String TRANSFER_PROGRESS = "/file/transferProgress";
String FILE_UPDATE_DISPLAY_NAME = "/file/updateDisplayName";
String UPLOAD_TO_OSS = "/file/uploadToOSS";
String UPLOAD_TO_OSS_PROGRESS = "/file/uploadToOSSProgress";
String DOWNLOAD = "/file/download";
/**
* JOB URL
*/
String PENDING_JOBS = "/pendingJobs";
/**
* HEAP DUMP URL
*/
String HEAP_DUMP_RELEASE = "/heap-dump/:file/release";
String HEAP_DUMP_COMMON = "/heap-dump/:file/*";
/**
* GC LOG URL
*/
String GCLOG_RELEASE = "/gc-log/:file/release";
String GCLOG_COMMON = "/gc-log/:file/*";
/**
* THREAD DUMP URL
*/
String THREAD_DUMP_RELEASE = "/thread-dump/:file/release";
String THREAD_DUMP_COMMON = "/thread-dump/:file/*";
/**
* WORKER URL
*/
String QUERY_ALL_WORKERS = "/workers";
String WORKER_DISK_CLEANUP = "/worker/diskCleanup";
String HEALTH_CHECK = "/worker/healthCheck";
/**
* ADMIN URL
*/
String ADD_ADMIN = "/admin/add";
String QUERY_ALL_ADMIN = "/admins";
/**
* MISC
*/
String USERNAME = "username";
String PASSWORD = "password";
String PORT = "port";
String SYSTEM_DISK_USAGE = "/system/diskUsage";
String PING = "/system/ping";
/**
* K8S CLOUD CONFIG
*/
String K8S_KEYWORD = "k8s-config";
String K8S_NAMESPACE = "namespace";
String K8S_WORKER_IMAGE = "worker-image";
String K8S_MINIMAL_MEM_REQ = "minimal-mem-req";
String K8S_MASTER_POD_NAME = "master-pod-name";
String K8S_WORKER_PVC_NAME = "worker-pvc-name";
/**
* DEV
*/
String LOCAL_HOST = "localhost";
static String uri(String suffix) {
return BASE + suffix;
}
}
| 6,790 |
0 | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master/vo/ExtendedFileInfo.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.master.vo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.eclipse.jifa.common.vo.FileInfo;
@Data
@EqualsAndHashCode(callSuper = true)
public class ExtendedFileInfo extends FileInfo {
private String displayName;
private String userId;
private boolean shared;
}
| 6,791 |
0 | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master/vo/PendingJobsResult.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.master.vo;
import lombok.Data;
import java.util.List;
@Data
public class PendingJobsResult {
private boolean inProgress;
private List<PendingJob> jobs;
public PendingJobsResult(boolean inProgress) {
this.inProgress = inProgress;
}
public PendingJobsResult(List<PendingJob> jobs) {
this.inProgress = false;
this.jobs = jobs;
}
}
| 6,792 |
0 | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master/vo/TransferDestination.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.master.vo;
import lombok.Data;
@Data
public class TransferDestination {
private String hostIP;
private String directory;
private String filename;
public TransferDestination(String hostIP, String directory, String filename) {
this.hostIP = hostIP;
this.directory = directory;
this.filename = filename;
}
}
| 6,793 |
0 | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master/vo/PendingJob.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.master.vo;
import lombok.Data;
import org.eclipse.jifa.master.entity.Job;
import org.eclipse.jifa.master.entity.enums.JobType;
@Data
public class PendingJob {
private String userId;
private JobType type;
private String target;
private long creationTime;
public PendingJob(Job job) {
this.userId = job.getUserId();
this.type = job.getType();
this.target = job.getTarget();
this.creationTime = job.getCreationTime();
}
}
| 6,794 |
0 | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master/vo/UserToken.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.master.vo;
import lombok.Data;
@Data
public class UserToken {
private String token;
public UserToken(String token) {
this.token = token;
}
}
| 6,795 |
0 | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master/entity/Master.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.master.entity;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
@DataObject(generateConverter = true)
public class Master extends Entity {
public static Master NOT_FOUND = notFoundInstance(Master.class);
public boolean leader;
private String hostIP;
private String hostName;
public Master() {
}
public Master(JsonObject json) {
MasterConverter.fromJson(json, this);
}
public JsonObject toJson() {
JsonObject result = new JsonObject();
MasterConverter.toJson(this, result);
return result;
}
}
| 6,796 |
0 | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master/entity/Admin.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.master.entity;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
@DataObject(generateConverter = true)
public class Admin extends Entity {
public static Admin NOT_FOUND = notFoundInstance(Admin.class);
private String userId;
public Admin() {
}
public Admin(JsonObject json) {
AdminConverter.fromJson(json, this);
}
public JsonObject toJson() {
JsonObject result = new JsonObject();
AdminConverter.toJson(this, result);
return result;
}
}
| 6,797 |
0 | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master/entity/Job.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.master.entity;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.eclipse.jifa.master.entity.enums.JobState;
import org.eclipse.jifa.master.entity.enums.JobType;
@Data
@EqualsAndHashCode(callSuper = false)
@DataObject(generateConverter = true)
public class Job extends Entity {
public static Job NOT_FOUND = notFoundInstance(Job.class);
private String userId;
private JobType type;
private JobState state;
private String hostIP;
private String target;
private String attachment;
private long estimatedLoad;
private boolean immediate = false;
private boolean keepAlive;
private long accessTime;
public Job() {
}
public Job(JsonObject json) {
JobConverter.fromJson(json, this);
}
public JsonObject toJson() {
JsonObject result = new JsonObject();
JobConverter.toJson(this, result);
return result;
}
}
| 6,798 |
0 | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master | Create_ds/eclipse-jifa/backend/master/src/main/java/org/eclipse/jifa/master/entity/Worker.java | /********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.jifa.master.entity;
import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
@DataObject(generateConverter = true)
public class Worker extends Entity {
public static Worker NOT_FOUND = notFoundInstance(Worker.class);
private String hostIP;
private String hostName;
private long currentLoad;
private long maxLoad;
private long cpuCount;
private long memoryUsed;
private long memoryTotal;
private long diskUsed;
private long diskTotal;
public Worker() {
}
public Worker(JsonObject json) {
WorkerConverter.fromJson(json, this);
}
public JsonObject toJson() {
JsonObject result = new JsonObject();
WorkerConverter.toJson(this, result);
return result;
}
}
| 6,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.