Last active
May 16, 2024 03:45
-
-
Save gotnix/65f8fff3c0468d76638d848e9a7e2b97 to your computer and use it in GitHub Desktop.
把 Collectl 收集进程状态的 rpc 文件转换为 csv,方便使用 Excel 分析。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FileName: prc_to_csv.awk | |
# 把 Collectl 收集进程状态的 rpc 文件转换为 csv,方便使用 Excel 分析。 | |
# 例子: | |
# cd /tmp/ | |
# collectl -sZ -o a -p /var/log/collectl/${HOSTNAME}-20240516-102558.raw.gz -P -f /tmp/0516 | |
# gzip -d 0516-${HOSTNAME}-20240516.prc.gz | |
# awk -f prc_to_csv.awk 0516-${HOSTNAME}-20240516.prc >> ${HOSTNAME}_collectl_process_0516.csv | |
# | |
BEGIN { | |
FS=" "; OFS="," | |
} | |
/^#/ {next} | |
/^#Date/ { | |
printf "%s%s", "Date", OFS | |
for (i = 2; i <= NF; i++) { | |
printf "%s%s", $i, OFS | |
} | |
print "Args"; | |
} | |
{ | |
if (NF == 30) { | |
for (i = 1; i <= NF; i++) { | |
printf "%s%s", $i, (i==NF ? "\n" : OFS); | |
} | |
} else { | |
for (i = 1; i <= 30; i++) { | |
printf "%s,", $i; | |
} | |
printf "\""; | |
for (i = 31; i <= (NF-1); i++) { | |
printf "%s ", $i; | |
} | |
print $NF"\""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment