1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-23 04:10:55 +00:00

improve the output fomate

This commit is contained in:
astaxie 2013-11-15 18:21:26 +08:00
parent 2758c6da14
commit a9b6a0b81a

View File

@ -1,8 +1,8 @@
package admin package admin
import ( import (
"fmt"
"io" "io"
"strconv"
"sync" "sync"
"time" "time"
) )
@ -64,16 +64,12 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri
func (m *UrlMap) GetMap(rw io.Writer) { func (m *UrlMap) GetMap(rw io.Writer) {
m.lock.RLock() m.lock.RLock()
defer m.lock.RUnlock() defer m.lock.RUnlock()
rw.Write([]byte("requestURL avgTime")) fmt.Fprintf(rw, "| % -30s| % -10s | % -16s | % -16s | % -16s | % -16s | % -16s |\n", "requestUrl", "method", "times", "used (s)", "avg used (μs)", "max used (μs)", "min used (μs)")
for k, v := range m.urlmap { for k, v := range m.urlmap {
rw.Write([]byte(k + ""))
for kk, vv := range v { for kk, vv := range v {
rw.Write([]byte(kk)) fmt.Fprintf(rw, "| % -30s| % -10s | % -16d | % -16f | % -16f | % -16f | % -16f |\n", k,
rw.Write([]byte(strconv.FormatInt(vv.RequestNum, 10))) kk, vv.RequestNum, vv.TotalTime, vv.MaxTime, vv.MinTime, int64(vv.TotalTime)/vv.RequestNum,
rw.Write([]byte(strconv.FormatInt(int64(vv.TotalTime), 10))) )
rw.Write([]byte(strconv.FormatInt(int64(vv.MaxTime), 10)))
rw.Write([]byte(strconv.FormatInt(int64(vv.MinTime), 10)))
rw.Write([]byte(strconv.FormatInt(int64(vv.TotalTime)/vv.RequestNum, 10)))
} }
} }
} }