You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/01/31 03:14:37 UTC
incubator-mynewt-newt git commit: add memory pool statistics to
newtmgr
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/master a77be9b28 -> ae715c939
add memory pool statistics to newtmgr
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/ae715c93
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/ae715c93
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/ae715c93
Branch: refs/heads/master
Commit: ae715c93951da9844c5088c7336f6640a14b2c9b
Parents: a77be9b
Author: Sterling Hughes <st...@apache.org>
Authored: Sat Jan 30 18:14:27 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Sat Jan 30 18:14:27 2016 -0800
----------------------------------------------------------------------
newtmgr/newtmgr.go | 69 ++++++++++++++++++++++++++++++++++++++++
newtmgr/protocol/mpstats.go | 69 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 138 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ae715c93/newtmgr/newtmgr.go
----------------------------------------------------------------------
diff --git a/newtmgr/newtmgr.go b/newtmgr/newtmgr.go
index f3567cf..7244efa 100644
--- a/newtmgr/newtmgr.go
+++ b/newtmgr/newtmgr.go
@@ -314,6 +314,74 @@ func taskStatsCmd() *cobra.Command {
return taskStatsCmd
}
+func mempoolStatsRunCmd(cmd *cobra.Command, args []string) {
+ cpm, err := cli.NewCpMgr()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ profile, err := cpm.GetConnProfile(ConnProfileName)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ conn, err := transport.NewConn(profile)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ runner, err := protocol.NewCmdRunner(conn)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ srr, err := protocol.NewMempoolStatsReadReq()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ nmr, err := srr.EncodeWriteRequest()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ if err := runner.WriteReq(nmr); err != nil {
+ nmUsage(cmd, err)
+ }
+
+ rsp, err := runner.ReadResp()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ msrsp, err := protocol.DecodeMempoolStatsReadResponse(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ fmt.Printf("Return Code = %d\n", msrsp.ReturnCode)
+ if msrsp.ReturnCode == 0 {
+ for k, info := range msrsp.MPools {
+ fmt.Printf(" %s ", k)
+ fmt.Printf("(blksize=%d nblocks=%d nfree=%d)",
+ int(info["blksiz"].(float64)),
+ int(info["nblks"].(float64)),
+ int(info["nfree"].(float64)))
+ fmt.Printf("\n")
+ }
+ }
+}
+
+func mempoolStatsCmd() *cobra.Command {
+ mempoolStatsCmd := &cobra.Command{
+ Use: "mpstats",
+ Short: "Read statistics from a remote endpoint",
+ Run: mempoolStatsRunCmd,
+ }
+
+ return mempoolStatsCmd
+}
+
func statsRunCmd(cmd *cobra.Command, args []string) {
cpm, err := cli.NewCpMgr()
if err != nil {
@@ -900,6 +968,7 @@ func parseCmds() *cobra.Command {
nmCmd.AddCommand(imageCmd())
nmCmd.AddCommand(statsCmd())
nmCmd.AddCommand(taskStatsCmd())
+ nmCmd.AddCommand(mempoolStatsCmd())
nmCmd.AddCommand(configCmd())
return nmCmd
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ae715c93/newtmgr/protocol/mpstats.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/mpstats.go b/newtmgr/protocol/mpstats.go
new file mode 100644
index 0000000..92d5cae
--- /dev/null
+++ b/newtmgr/protocol/mpstats.go
@@ -0,0 +1,69 @@
+/*
+ Copyright 2015 Runtime Inc.
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package protocol
+
+import (
+ "encoding/json"
+ "fmt"
+
+ "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/util"
+)
+
+const (
+ NMGR_ID_MPSTATS = 3
+)
+
+type MempoolStatsReadReq struct {
+}
+
+type MempoolStatsReadRsp struct {
+ ReturnCode int `json:"rc"`
+ MPools map[string]map[string]interface{} `json:"mpools"`
+}
+
+func NewMempoolStatsReadReq() (*MempoolStatsReadReq, error) {
+ s := &MempoolStatsReadReq{}
+
+ return s, nil
+}
+
+func (tsr *MempoolStatsReadReq) EncodeWriteRequest() (*NmgrReq, error) {
+ nmr, err := NewNmgrReq()
+ if err != nil {
+ return nil, err
+ }
+
+ nmr.Op = NMGR_OP_READ
+ nmr.Flags = 0
+ nmr.Group = NMGR_GROUP_ID_DEFAULT
+ nmr.Id = NMGR_ID_MPSTATS
+
+ nmr.Data = []byte{}
+ nmr.Len = uint16(0)
+
+ return nmr, nil
+}
+
+func DecodeMempoolStatsReadResponse(data []byte) (*MempoolStatsReadRsp, error) {
+ var tsr MempoolStatsReadRsp
+ err := json.Unmarshal(data, &tsr)
+ if err != nil {
+ return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
+ err.Error()))
+ }
+
+ return &tsr, nil
+}