1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

opt time.cost

This commit is contained in:
shaoying 2019-08-13 21:07:19 +08:00
parent 0b0ac4cd14
commit f7c15360c5
11 changed files with 36 additions and 19 deletions

View File

@ -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))

View File

@ -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,
}

View File

@ -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)
}

View File

@ -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) {

View File

@ -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)

View File

@ -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)
}
}

View File

@ -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

View File

@ -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
}},
},

View File

@ -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"))

View File

@ -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", "}"}},

View File

@ -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)
}