There is now a time-consuming statistical log of the server-side business logic for filter statistics, formatted as follows
The first column is the keyword, the second and third columns are the other parameters, the fourth column is time-consuming, and I only care about the fourth column.
The goal is to count the time consuming (and the percentage) of the server to find out if there is room for the server to logically optimize.
The first is to take care of the data:
Because this log is not exactly the format shown above, there are a lot of record format is more confusing, so the first thing to do is to exclude irregular format, choose a simple method:
awk ' {if ($2!= ' && $3!= ' && $4!= ' ') {print $NF}} ' Request_cost.log | grep-e ' ^[0-9]+$ ' |
First exclude 2, 3, 4 paragraphs are not worth recording, in the last record of the remaining field, take out the field to ensure that the number
The result of this is that
0
0
0
0
1
0 0 1 1
Next is the statistics and percent:
awk ' {a[$1]++;s+=1}end{for (j in a) printf '%s%.2f%\n ', j,a[j]*100/s} '
So the final instructions are:
awk ' {if ($2!= "&& $3!=" "&& $4!=" ") {print $NF}} ' Request_cost.log | Grep-e "^[0-9]+$" | awk ' {a[$1]++;s+=1}end{for (j in a) printf '%s%.2f%\n ', j,a[j]*100/s} ' > Request_result.log
Output results:
After the output to the file, sort again:
Sort-k 2-gr request_result.log > Sort_request_result.log
-K 2 refers to the value of the second column as key,-GR is sorted by numeric reverse order
Results:
Time consuming 0ms and 1ms accounted for the vast majority, there is no optimization space.