/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ package software.amazon.awssdk.benchmark.stats; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.io.IOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.infra.BenchmarkParams; import software.amazon.awssdk.core.util.VersionInfo; /** * Contains metadata for the benchmark */ public class SdkBenchmarkParams { private String sdkVersion; private String jdkVersion; private String jvmName; private String jvmVersion; private Mode mode; @JsonSerialize(using = LocalDateSerializer.class) @JsonDeserialize(using = LocalDateDeserializer.class) private LocalDateTime date; public SdkBenchmarkParams() { } public SdkBenchmarkParams(BenchmarkParams benchmarkParams) { this.sdkVersion = VersionInfo.SDK_VERSION; this.jdkVersion = benchmarkParams.getJdkVersion(); this.jvmName = benchmarkParams.getVmName(); this.jvmVersion = benchmarkParams.getVmVersion(); this.mode = benchmarkParams.getMode(); this.date = LocalDateTime.now(); } public String getSdkVersion() { return sdkVersion; } public void setSdkVersion(String sdkVersion) { this.sdkVersion = sdkVersion; } public String getJdkVersion() { return jdkVersion; } public void setJdkVersion(String jdkVersion) { this.jdkVersion = jdkVersion; } public String getJvmName() { return jvmName; } public void setJvmName(String jvmName) { this.jvmName = jvmName; } public String getJvmVersion() { return jvmVersion; } public void setJvmVersion(String jvmVersion) { this.jvmVersion = jvmVersion; } public LocalDateTime getDate() { return date; } public void setDate(LocalDateTime date) { this.date = date; } public Mode getMode() { return mode; } public void setMode(Mode mode) { this.mode = mode; } private static class LocalDateSerializer extends JsonSerializer { @Override public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeString(value.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); } } private static class LocalDateDeserializer extends JsonDeserializer { @Override public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { return LocalDateTime.parse(p.readValueAs(String.class)); } } }