mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 09:14:06 +08:00
opt time.cost
This commit is contained in:
parent
0b0ac4cd14
commit
f7c15360c5
@ -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) == "" {
|
if m.Cmdy("cli.system", env, "go", "build", "-o", q, p); m.Result(0) == "" {
|
||||||
m.Cmdy("cli.quit", 1)
|
m.Cmdy("cli.quit", 1)
|
||||||
m.Append("time", m.Time())
|
m.Append("time", m.Time())
|
||||||
|
m.Append("cost", m.Format("cost"))
|
||||||
m.Append("hash", kit.Hashs(q)[:8])
|
m.Append("hash", kit.Hashs(q)[:8])
|
||||||
m.Append("bin", q)
|
m.Append("bin", q)
|
||||||
m.Table()
|
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) == "" {
|
if m.Cmdy("cli.system", env, "go", "build", o, "-o", q, p); m.Result(0) == "" {
|
||||||
m.Append("time", m.Time())
|
m.Append("time", m.Time())
|
||||||
|
m.Append("cost", m.Format("cost"))
|
||||||
m.Append("hash", m.Cmdx("nfs.hash", q)[:8])
|
m.Append("hash", m.Cmdx("nfs.hash", q)[:8])
|
||||||
m.Append("bin", q)
|
m.Append("bin", q)
|
||||||
m.Table()
|
m.Table()
|
||||||
@ -994,9 +996,10 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
restart = true
|
restart = true
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Add("append", "time", m.Time())
|
m.Push("time", m.Time())
|
||||||
m.Add("append", "file", file)
|
m.Push("cost", m.Format("cost"))
|
||||||
m.Add("append", "hash", kit.Hashs(file)[:8])
|
m.Push("hash", kit.Hashs(file)[:8])
|
||||||
|
m.Push("file", file)
|
||||||
|
|
||||||
if strings.HasSuffix(link, ".tar.gz") {
|
if strings.HasSuffix(link, ".tar.gz") {
|
||||||
m.Cmd("cli.system", "tar", "-xvf", file, "-C", path.Dir(file))
|
m.Cmd("cli.system", "tar", "-xvf", file, "-C", path.Dir(file))
|
||||||
|
@ -4,5 +4,5 @@ var version = struct {
|
|||||||
host string
|
host string
|
||||||
self int
|
self int
|
||||||
}{
|
}{
|
||||||
"2019-08-13 16:05:35", "ZYB-20190522USI", 384,
|
"2019-08-13 20:02:55", "ZYB-20190522USI", 400,
|
||||||
}
|
}
|
||||||
|
@ -541,7 +541,7 @@ func (m *Message) Goshy(input []string, index int, stack *kit.Stack, cb func(*Me
|
|||||||
m.Optioni("stack.pos", i)
|
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 {
|
if cb != nil {
|
||||||
cb(msg)
|
cb(msg)
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
|||||||
"space": " ", "compact": "false", "col_sep": " ", "row_sep": "\n",
|
"space": " ", "compact": "false", "col_sep": " ", "row_sep": "\n",
|
||||||
"offset": 0, "limit": 10,
|
"offset": 0, "limit": 10,
|
||||||
}, Help: "制表"},
|
}, Help: "制表"},
|
||||||
"call_timeout": &Config{Name: "call_timeout", Value: "10s", Help: "回调超时"},
|
"call_timeout": &Config{Name: "call_timeout", Value: "60s", Help: "回调超时"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*Command{
|
Commands: map[string]*Command{
|
||||||
"_init": &Command{Name: "_init", Help: "启动", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
"_init": &Command{Name: "_init", Help: "启动", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"sort"
|
"sort"
|
||||||
"toolkit"
|
"toolkit"
|
||||||
@ -70,6 +71,9 @@ func (m *Message) Format(arg ...interface{}) string {
|
|||||||
meta := []string{}
|
meta := []string{}
|
||||||
for _, v := range arg {
|
for _, v := range arg {
|
||||||
switch kit.Format(v) {
|
switch kit.Format(v) {
|
||||||
|
case "cost":
|
||||||
|
meta = append(meta, kit.FmtTime(time.Now().Sub(m.time).Nanoseconds()))
|
||||||
|
|
||||||
case "summary":
|
case "summary":
|
||||||
msg := arg[1].(*Message)
|
msg := arg[1].(*Message)
|
||||||
ms := make([]*Message, 0, 1024)
|
ms := make([]*Message, 0, 1024)
|
||||||
|
@ -90,15 +90,10 @@ type DEBUG interface {
|
|||||||
func (m *Message) Time(arg ...interface{}) string {
|
func (m *Message) Time(arg ...interface{}) string {
|
||||||
t := m.time
|
t := m.time
|
||||||
if len(arg) > 0 {
|
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 {
|
if d, e := time.ParseDuration(arg[0].(string)); e == nil {
|
||||||
arg, t = arg[1:], t.Add(d)
|
arg, t = arg[1:], t.Add(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
str := m.Conf("time", "format")
|
str := m.Conf("time", "format")
|
||||||
if len(arg) > 1 {
|
if len(arg) > 1 {
|
||||||
|
@ -409,11 +409,11 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool {
|
|||||||
msg.Add(field, value)
|
msg.Add(field, value)
|
||||||
|
|
||||||
case "":
|
case "":
|
||||||
m.Log("recv", "time %v", time.Now().Format(m.Conf("time", "format")))
|
|
||||||
if head == "detail" { // 接收请求
|
if head == "detail" { // 接收请求
|
||||||
msg.Detail(-1, "_route")
|
msg.Detail(-1, "_route")
|
||||||
msg.Option("remote_code", code)
|
msg.Option("remote_code", code)
|
||||||
m.Gos(msg, func(msg *ctx.Message) {
|
m.Gos(msg, func(msg *ctx.Message) {
|
||||||
|
msg.Log("time", "parse %v", msg.Format("cost", "detail"))
|
||||||
msg.Call(func(msg *ctx.Message) *ctx.Message {
|
msg.Call(func(msg *ctx.Message) *ctx.Message {
|
||||||
nfs.echo <- msg
|
nfs.echo <- msg
|
||||||
return nil
|
return nil
|
||||||
|
@ -483,6 +483,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"_route": &ctx.Command{Name: "_route", Help: "路由", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"_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 {
|
if len(arg) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -555,6 +556,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
// 路由转发
|
// 路由转发
|
||||||
for _, p := range ps {
|
for _, p := range ps {
|
||||||
m.Find(p, true).Copy(m, "option").CallBack(sync, func(sub *ctx.Message) *ctx.Message {
|
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")
|
return m.CopyFuck(sub, "append").CopyFuck(sub, "result")
|
||||||
}, "send", rest, arg)
|
}, "send", rest, arg)
|
||||||
}
|
}
|
||||||
@ -563,6 +565,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
|
|
||||||
defer func() { m.Back(m) }()
|
defer func() { m.Back(m) }()
|
||||||
|
|
||||||
|
m.Log("time", "exec: %v", m.Format("cost"))
|
||||||
if !m.Options("remote_code") {
|
if !m.Options("remote_code") {
|
||||||
// 本地调用
|
// 本地调用
|
||||||
m.Cmdy(arg)
|
m.Cmdy(arg)
|
||||||
@ -596,8 +599,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
m.Echo("node error of %s", m.Option("node.route"))
|
m.Echo("node error of %s", m.Option("node.route"))
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
m.Log("time", "exec: %v", m.Format("cost"))
|
||||||
// 执行命令
|
// 执行命令
|
||||||
m.Cmd("_exec", arg)
|
m.Cmd("_exec", arg)
|
||||||
|
m.Log("time", "exec: %v", m.Format("cost"))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
@ -951,6 +956,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
|
|
||||||
// 执行命令
|
// 执行命令
|
||||||
m.Cmdy(arg)
|
m.Cmdy(arg)
|
||||||
|
m.Log("time", "exec: %v", m.Format("cost"))
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MUX interface {
|
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) {
|
web.HandleFunc(key, func(w http.ResponseWriter, r *http.Request) {
|
||||||
m.TryCatch(m.Spawn(m.Conf("serve", "autofree")), true, func(msg *ctx.Message) {
|
m.TryCatch(m.Spawn(m.Conf("serve", "autofree")), true, func(msg *ctx.Message) {
|
||||||
defer func() {
|
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_addr", r.RemoteAddr)
|
||||||
msg.Option("remote_ip", r.Header.Get("remote_ip"))
|
msg.Option("remote_ip", r.Header.Get("remote_ip"))
|
||||||
|
@ -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": "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": "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", "rep{", "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{", "exp", "}"}},
|
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": "fun", "word": []interface{}{"fun", "key", "rep{", "exp", "}"}},
|
||||||
map[string]interface{}{"page": "stm", "hash": "kit", "word": []interface{}{"kit", "rep{", "exp", "}"}},
|
map[string]interface{}{"page": "stm", "hash": "kit", "word": []interface{}{"kit", "rep{", "exp", "}"}},
|
||||||
|
@ -73,3 +73,15 @@ func FmtSize(size uint64) string {
|
|||||||
|
|
||||||
return fmt.Sprintf("%dB", size)
|
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)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user