分析耗时sed & awk

本文介绍了一个使用Shell脚本实现的功能,该脚本能够处理输入数据,通过查找特定条件的时间和方法,对数据进行汇总并计算平均值,最后按指定格式输出结果。此脚本适用于性能分析和日志处理等场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/bash

function summary() {
 awk '
    BEGIN { FS="=" }
    {
      if(method[$2]!=0)
      {
       method[$2]=method[$2]+$1;
      }
      else
      {
       method[$2]=$1;
      }
      count[$2]++;
    }
    END {
      for(m in method)
      {
       printf "%f\t%d\t%s\n", method[m]/count[m]/1000.0, count[m], "&"m;
      }
    }
 '
}

#1.find the time and method where time > 1
#2.summary the ave time and count method
#3.sort the result
#4.title
sed -n '/^[^0-9]/s/.*\[\([1-9\,]*\,[0-9]*\)ms.* - \(.*\)/\1=\2/p' $1 \
 | sed 's/\,//' \
 | sed 's/\(.*\=\).*\(.*HSF Service\).\(\$.* \).*\(\$.* \).*/\1\2 \3-> \4/' \
 | summary \
 | sort -t\| -k1 -nr \

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值