Info funcs added

--HG--
branch : dev
This commit is contained in:
mikespook 2012-09-25 15:16:17 +08:00
parent 8c67ce0830
commit 05590bfb8c
3 changed files with 45 additions and 0 deletions

View File

@ -32,6 +32,18 @@ def main():
except Exception as e:
print type(e)
try:
completed_job_request = client.submit_job("SysInfo", "")
check_request_status(completed_job_request)
except Exception as e:
print type(e)
try:
completed_job_request = client.submit_job("MemInfo", "")
check_request_status(completed_job_request)
except Exception as e:
print type(e)
if __name__ == '__main__':
main()

View File

@ -52,6 +52,8 @@ func main() {
w.AddFunc("ToUpper", ToUpper, worker.Immediately)
w.AddFunc("ToUpperTimeOut5", ToUpperDelay10, 5)
w.AddFunc("ToUpperTimeOut20", ToUpperDelay10, 20)
w.AddFunc("SysInfo", worker.SysInfo, worker.Immediately)
w.AddFunc("MemInfo", worker.MemInfo, worker.Immediately)
go w.Work()
sh := signal.NewHandler()
sh.Bind(os.Interrupt, func() bool {return true})

31
worker/func.go Normal file
View File

@ -0,0 +1,31 @@
package worker
import (
"runtime"
"encoding/json"
)
type systemInfo struct {
GOOS, GOARCH, GOROOT, Version string
NumCPU, NumGoroutine int
NumCgoCall int64
}
func SysInfo(job *Job) ([]byte, error) {
return json.Marshal(&systemInfo{
GOOS: runtime.GOOS,
GOARCH: runtime.GOARCH,
GOROOT: runtime.GOROOT(),
Version: runtime.Version(),
NumCPU: runtime.NumCPU(),
NumGoroutine: runtime.NumGoroutine(),
NumCgoCall: runtime.NumCgoCall(),
})
}
var memState runtime.MemStats
func MemInfo(job *Job) ([]byte, error) {
runtime.ReadMemStats(&memState)
return json.Marshal(&memState)
}