我们在Linux上使用curl访问某些http API接口的时候,有时需要知道调用这个接口的耗时情况,这时我们可以给curl指定输出参数,把耗时情况打印出来
首先我们可以创建一个curl-format.txt把耗时参数的格式给固定下来,然后使用-w参数传到curl中去,curl-format.txt内容如下:
\n
time_namelookup: %{time_namelookup}s\n
time_connect: %{time_connect}s\n
time_appconnect: %{time_appconnect}s\n
time_pretransfer: %{time_pretransfer}s\n
time_redirect: %{time_redirect}s\n
time_starttransfer: %{time_starttransfer}s\n
----------\n
time_total: %{time_total}s\n
请求效果
# post请求,通过vpc对等连接,post图片返回json
[ec2-user@ip-172-41-5-42 ~]$ curl -w "@curl-format.txt" -X POST -F 'image=@/home/ec2-user/aws-logo.jpg' 172.31.62.78:8085/files/images
{"code":200,"message":"success","data":{"file":"aws-logo.jpg"}}
time_namelookup: 0.000044s
time_connect: 0.071695s
time_appconnect: 0.000000s
time_pretransfer: 0.071761s
time_redirect: 0.000000s
time_starttransfer: 0.071764s
----------
time_total: 0.215615s