When I was doing a memory-related survey, I was told that I really wanted to use Excel for aggregation, so I tried it for the time being.
The usual jstat log appears as follows.
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
512.0 512.0 0.0 0.0 124928.0 6358.9 83968.0 42417.6 65064.0 58754.0 9256.0 7392.2 15501 94.212 15488 1702.193 1796.405
For the time being, if the date and comma can be separated, it seems that it can be read in Excel as it is, so I tried using sed and awk. Since the running application is a Windows environment, install it in advance so that sed and awk can be executed. When I tried it on Mac, I got angry if there was no awk strftime, so I installed gawk.
awk: calling undefined function strftime
So, I tried various things and it became as follows.
jstat -gc <process id> 10s | gawk '{print strftime("%Y/%m/%d-%H:%M:%S"), $0; fflush();}' | sed -e 's/^ *//g; s/ */,/g' >> jstat.csv
Now the output will be as follows.
2018/04/28-23:28:46,S0C,S1C,S0U,S1U,EC,EU,OC,OU,MC,MU,CCSC,CCSU,YGC,YGCT,FGC,FGCT,GCT,
2018/04/28-23:28:46,512.0,512.0,0.0,0.0,124928.0,4831.7,83968.0,42283.1,65064.0,58754.0,9256.0,7392.2,15507,94.412,15494,1703.366,1797.778
2018/04/28-23:28:47,512.0,512.0,0.0,0.0,124928.0,4831.7,83968.0,42283.1,65064.0,58754.0,9256.0,7392.2,15507,94.412,15494,1703.366,1797.778
The header will also have a date, but that's a compromise.