diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 35def945..ad578102 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -812,6 +812,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", if m.Cmdy("cli.system", env, "go", "build", "-o", q, p); m.Result(0) == "" { m.Cmdy("cli.quit", 1) m.Append("time", m.Time()) + m.Append("cost", m.Format("cost")) m.Append("hash", kit.Hashs(q)[:8]) m.Append("bin", q) m.Table() @@ -851,6 +852,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", if m.Cmdy("cli.system", env, "go", "build", o, "-o", q, p); m.Result(0) == "" { m.Append("time", m.Time()) + m.Append("cost", m.Format("cost")) m.Append("hash", m.Cmdx("nfs.hash", q)[:8]) m.Append("bin", q) m.Table() @@ -994,9 +996,10 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", restart = true } - m.Add("append", "time", m.Time()) - m.Add("append", "file", file) - m.Add("append", "hash", kit.Hashs(file)[:8]) + m.Push("time", m.Time()) + m.Push("cost", m.Format("cost")) + m.Push("hash", kit.Hashs(file)[:8]) + m.Push("file", file) if strings.HasSuffix(link, ".tar.gz") { m.Cmd("cli.system", "tar", "-xvf", file, "-C", path.Dir(file)) diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index b02c6e71..cb6f7d0d 100644 --- a/src/contexts/cli/version.go +++ b/src/contexts/cli/version.go @@ -4,5 +4,5 @@ var version = struct { host string self int }{ - "2019-08-13 16:05:35", "ZYB-20190522USI", 384, + "2019-08-13 20:02:55", "ZYB-20190522USI", 400, } diff --git a/src/contexts/ctx/core.go b/src/contexts/ctx/core.go index ca32a975..55e2dd76 100644 --- a/src/contexts/ctx/core.go +++ b/src/contexts/ctx/core.go @@ -541,7 +541,7 @@ func (m *Message) Goshy(input []string, index int, stack *kit.Stack, cb func(*Me m.Optioni("stack.pos", i) // 执行语句 - msg := m.Sess("yac", true, true).Cmd("parse", line+"\n") + msg := m.Sess("yac").Cmd("parse", line+"\n") if cb != nil { cb(msg) } diff --git a/src/contexts/ctx/ctx.go b/src/contexts/ctx/ctx.go index d20ca820..4e147bf2 100644 --- a/src/contexts/ctx/ctx.go +++ b/src/contexts/ctx/ctx.go @@ -91,7 +91,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, "space": " ", "compact": "false", "col_sep": " ", "row_sep": "\n", "offset": 0, "limit": 10, }, Help: "制表"}, - "call_timeout": &Config{Name: "call_timeout", Value: "10s", Help: "回调超时"}, + "call_timeout": &Config{Name: "call_timeout", Value: "60s", Help: "回调超时"}, }, Commands: map[string]*Command{ "_init": &Command{Name: "_init", Help: "启动", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) { diff --git a/src/contexts/ctx/misc.go b/src/contexts/ctx/misc.go index 57c06abd..a58d8667 100644 --- a/src/contexts/ctx/misc.go +++ b/src/contexts/ctx/misc.go @@ -6,6 +6,7 @@ import ( "regexp" "runtime" "strings" + "time" "sort" "toolkit" @@ -70,6 +71,9 @@ func (m *Message) Format(arg ...interface{}) string { meta := []string{} for _, v := range arg { switch kit.Format(v) { + case "cost": + meta = append(meta, kit.FmtTime(time.Now().Sub(m.time).Nanoseconds())) + case "summary": msg := arg[1].(*Message) ms := make([]*Message, 0, 1024) diff --git a/src/contexts/ctx/type.go b/src/contexts/ctx/type.go index 2ccbe1ca..a74dcd50 100644 --- a/src/contexts/ctx/type.go +++ b/src/contexts/ctx/type.go @@ -90,13 +90,8 @@ type DEBUG interface { func (m *Message) Time(arg ...interface{}) string { t := m.time if len(arg) > 0 { - switch v := arg[0].(type) { - case time.Time: - return fmt.Sprintf("%v", v.Sub(t)) - default: - if d, e := time.ParseDuration(arg[0].(string)); e == nil { - arg, t = arg[1:], t.Add(d) - } + if d, e := time.ParseDuration(arg[0].(string)); e == nil { + arg, t = arg[1:], t.Add(d) } } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index d0dada15..72845649 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -409,11 +409,11 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { msg.Add(field, value) case "": - m.Log("recv", "time %v", time.Now().Format(m.Conf("time", "format"))) if head == "detail" { // 接收请求 msg.Detail(-1, "_route") msg.Option("remote_code", code) m.Gos(msg, func(msg *ctx.Message) { + msg.Log("time", "parse %v", msg.Format("cost", "detail")) msg.Call(func(msg *ctx.Message) *ctx.Message { nfs.echo <- msg return nil diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index c8c818f4..9c35097e 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -483,6 +483,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", return }}, "_route": &ctx.Command{Name: "_route", Help: "路由", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + m.Log("time", "exec: %v", m.Format("cost")) if len(arg) == 0 { return } @@ -555,6 +556,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", // 路由转发 for _, p := range ps { m.Find(p, true).Copy(m, "option").CallBack(sync, func(sub *ctx.Message) *ctx.Message { + m.Log("time", "remote: %v", sub.Format("cost")) return m.CopyFuck(sub, "append").CopyFuck(sub, "result") }, "send", rest, arg) } @@ -563,6 +565,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", defer func() { m.Back(m) }() + m.Log("time", "exec: %v", m.Format("cost")) if !m.Options("remote_code") { // 本地调用 m.Cmdy(arg) @@ -596,8 +599,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", m.Echo("node error of %s", m.Option("node.route")) } else { + m.Log("time", "exec: %v", m.Format("cost")) // 执行命令 m.Cmd("_exec", arg) + m.Log("time", "exec: %v", m.Format("cost")) } return }}, @@ -951,6 +956,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", // 执行命令 m.Cmdy(arg) + m.Log("time", "exec: %v", m.Format("cost")) return }}, }, diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 06d658ed..e8b3ab46 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -21,7 +21,6 @@ import ( "path/filepath" "strconv" "strings" - "time" ) type MUX interface { @@ -160,7 +159,7 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) { web.HandleFunc(key, func(w http.ResponseWriter, r *http.Request) { m.TryCatch(m.Spawn(m.Conf("serve", "autofree")), true, func(msg *ctx.Message) { defer func() { - msg.Log("time", "cost: %v", msg.Time(time.Now())) + msg.Log("time", "serve: %v", msg.Format("cost")) }() msg.Option("remote_addr", r.RemoteAddr) msg.Option("remote_ip", r.Header.Get("remote_ip")) diff --git a/src/contexts/yac/yac.go b/src/contexts/yac/yac.go index ef9e4d69..f3da9a90 100644 --- a/src/contexts/yac/yac.go +++ b/src/contexts/yac/yac.go @@ -340,9 +340,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心", map[string]interface{}{"page": "stm", "hash": "let", "word": []interface{}{"let", "key", "=", "\\[", "rep{", "exp", "}", "\\]"}}, map[string]interface{}{"page": "stm", "hash": "let", "word": []interface{}{"let", "key", "=", "\\{", "rep{", "exp", "}", "\\}"}}, map[string]interface{}{"page": "stm", "hash": "if", "word": []interface{}{"if", "exp"}}, - map[string]interface{}{"page": "stm", "hash": "for", "word": []interface{}{"for", "key", "key", "key", "in", "key"}}, - map[string]interface{}{"page": "stm", "hash": "for", "word": []interface{}{"for", "key", "key", "in", "key"}}, - map[string]interface{}{"page": "stm", "hash": "for", "word": []interface{}{"for", "key", "in", "key"}}, + map[string]interface{}{"page": "stm", "hash": "for", "word": []interface{}{"for", "rep{", "key", "}"}}, map[string]interface{}{"page": "stm", "hash": "for", "word": []interface{}{"for", "rep{", "exp", "}"}}, map[string]interface{}{"page": "stm", "hash": "fun", "word": []interface{}{"fun", "key", "rep{", "exp", "}"}}, map[string]interface{}{"page": "stm", "hash": "kit", "word": []interface{}{"kit", "rep{", "exp", "}"}}, diff --git a/src/toolkit/misc.go b/src/toolkit/misc.go index 8fefdfbf..e2bfc125 100644 --- a/src/toolkit/misc.go +++ b/src/toolkit/misc.go @@ -73,3 +73,15 @@ func FmtSize(size uint64) string { return fmt.Sprintf("%dB", size) } +func FmtTime(time int64) string { + if time > 1000000000 { + return fmt.Sprintf("%d.%ds", time/1000000000, (time/1000000)%1000*100/1000) + } + if time > 1000000 { + return fmt.Sprintf("%d.%dms", time/1000000, (time/1000)%1000*100/1000) + } + if time > 1000 { + return fmt.Sprintf("%d.%dus", time/1000, (time/1000)%1000*100/1000) + } + return fmt.Sprintf("%dns", time) +}