001package com.streamconverter.benchmark; 002 003import java.time.Instant; 004 005/** 006 * リソース使用量の測定結果を表すクラス 007 * 008 * <p>メモリ使用量、処理時間、スループットなどのパフォーマンス指標を保持します。 5GBデータ/50MBメモリ目標の評価に使用されます。 009 */ 010public class ResourceUsage { 011 private final long durationMillis; 012 private final long memoryUsedBytes; 013 private final long peakMemoryBytes; 014 private final long startMemoryBytes; 015 private final long endMemoryBytes; 016 private final long dataSizeBytes; 017 private final double throughputMBps; 018 private final Instant measurementTime; 019 020 /** 021 * リソース使用量結果を構築します 022 * 023 * @param durationMillis 処理時間(ミリ秒) 024 * @param memoryUsedBytes 使用メモリ量(バイト) 025 * @param peakMemoryBytes ピークメモリ使用量(バイト) 026 * @param startMemoryBytes 開始時メモリ使用量(バイト) 027 * @param endMemoryBytes 終了時メモリ使用量(バイト) 028 * @param dataSizeBytes 処理したデータサイズ(バイト) 029 * @param throughputMBps スループット(MB/秒) 030 * @param measurementTime 測定時刻 031 */ 032 public ResourceUsage( 033 long durationMillis, 034 long memoryUsedBytes, 035 long peakMemoryBytes, 036 long startMemoryBytes, 037 long endMemoryBytes, 038 long dataSizeBytes, 039 double throughputMBps, 040 Instant measurementTime) { 041 this.durationMillis = durationMillis; 042 this.memoryUsedBytes = memoryUsedBytes; 043 this.peakMemoryBytes = peakMemoryBytes; 044 this.startMemoryBytes = startMemoryBytes; 045 this.endMemoryBytes = endMemoryBytes; 046 this.dataSizeBytes = dataSizeBytes; 047 this.throughputMBps = throughputMBps; 048 this.measurementTime = measurementTime; 049 } 050 051 /** 052 * 処理時間を取得(ミリ秒) 053 * 054 * @return 処理時間 055 */ 056 public long getDurationMillis() { 057 return durationMillis; 058 } 059 060 /** 061 * 使用メモリ量を取得(バイト) 062 * 063 * @return 使用メモリ量 064 */ 065 public long getMemoryUsedBytes() { 066 return memoryUsedBytes; 067 } 068 069 /** 070 * 使用メモリ量を取得(MB) 071 * 072 * @return 使用メモリ量(MB) 073 */ 074 public double getMemoryUsedMB() { 075 return memoryUsedBytes / 1024.0 / 1024.0; 076 } 077 078 /** 079 * ピークメモリ使用量を取得(バイト) 080 * 081 * @return ピークメモリ使用量 082 */ 083 public long getPeakMemoryBytes() { 084 return peakMemoryBytes; 085 } 086 087 /** 088 * ピークメモリ使用量を取得(MB) 089 * 090 * @return ピークメモリ使用量(MB) 091 */ 092 public double getPeakMemoryMB() { 093 return peakMemoryBytes / 1024.0 / 1024.0; 094 } 095 096 /** 097 * 開始時メモリ使用量を取得(バイト) 098 * 099 * @return 開始時メモリ使用量 100 */ 101 public long getStartMemoryBytes() { 102 return startMemoryBytes; 103 } 104 105 /** 106 * 終了時メモリ使用量を取得(バイト) 107 * 108 * @return 終了時メモリ使用量 109 */ 110 public long getEndMemoryBytes() { 111 return endMemoryBytes; 112 } 113 114 /** 115 * 処理したデータサイズを取得(バイト) 116 * 117 * @return データサイズ 118 */ 119 public long getDataSizeBytes() { 120 return dataSizeBytes; 121 } 122 123 /** 124 * 処理したデータサイズを取得(MB) 125 * 126 * @return データサイズ(MB) 127 */ 128 public double getDataSizeMB() { 129 return dataSizeBytes / 1024.0 / 1024.0; 130 } 131 132 /** 133 * スループットを取得(MB/秒) 134 * 135 * @return スループット 136 */ 137 public double getThroughputMBps() { 138 return throughputMBps; 139 } 140 141 /** 142 * 測定時刻を取得 143 * 144 * @return 測定時刻 145 */ 146 public Instant getMeasurementTime() { 147 return measurementTime; 148 } 149 150 /** 151 * 5GBデータ/50MBメモリ目標を満たしているかを確認 152 * 153 * @return 目標を満たしている場合true 154 */ 155 public boolean meets5GB50MBTarget() { 156 return getMemoryUsedMB() <= 50.0 && getThroughputMBps() >= 100.0; 157 } 158 159 /** 160 * メモリ効率性(データサイズに対するメモリ使用率)を計算 161 * 162 * @return メモリ効率性(0.0-1.0、低いほど効率的) 163 */ 164 public double getMemoryEfficiency() { 165 if (dataSizeBytes == 0) return 0.0; 166 return (double) memoryUsedBytes / dataSizeBytes; 167 } 168 169 @Override 170 public String toString() { 171 return String.format( 172 "ResourceUsage{duration=%dms, memoryUsed=%.2fMB, peakMemory=%.2fMB, " 173 + "dataSize=%.2fMB, throughput=%.2fMB/s, efficiency=%.4f, meets5GB50MB=%s}", 174 durationMillis, 175 getMemoryUsedMB(), 176 getPeakMemoryMB(), 177 getDataSizeMB(), 178 throughputMBps, 179 getMemoryEfficiency(), 180 meets5GB50MBTarget()); 181 } 182}