Skip to content

Commit

Permalink
*: show memory usage in "show processlist" (#6266)
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason authored Apr 12, 2018
1 parent f21483e commit 27fa552
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions executor/executor_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func (msm *mockSessionManager) Kill(cid uint64, query bool) {

func (s *testExecSuite) TestShowProcessList(c *C) {
// Compose schema.
names := []string{"Id", "User", "Host", "db", "Command", "Time", "State", "Info"}
names := []string{"Id", "User", "Host", "db", "Command", "Time", "State", "Info", "Mem"}
ftypes := []byte{mysql.TypeLonglong, mysql.TypeVarchar, mysql.TypeVarchar,
mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLong, mysql.TypeVarchar, mysql.TypeString}
mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLong, mysql.TypeVarchar, mysql.TypeString, mysql.TypeLonglong}
schema := buildSchema(names, ftypes)

// Compose a mocked session manager.
Expand Down
1 change: 1 addition & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func (e *ShowExec) fetchShowProcessList() error {
t,
fmt.Sprintf("%d", pi.State),
info,
pi.Mem,
})
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions plan/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1377,9 +1377,9 @@ func buildShowSchema(s *ast.ShowStmt) (schema *expression.Schema) {
mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar,
}
case ast.ShowProcessList:
names = []string{"Id", "User", "Host", "db", "Command", "Time", "State", "Info"}
names = []string{"Id", "User", "Host", "db", "Command", "Time", "State", "Info", "Mem"}
ftypes = []byte{mysql.TypeLonglong, mysql.TypeVarchar, mysql.TypeVarchar,
mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLong, mysql.TypeVarchar, mysql.TypeString}
mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLong, mysql.TypeVarchar, mysql.TypeString, mysql.TypeLonglong}
case ast.ShowStatsMeta:
names = []string{"Db_name", "Table_name", "Update_time", "Modify_count", "Row_count"}
ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeDatetime, mysql.TypeLonglong, mysql.TypeLonglong}
Expand Down
1 change: 1 addition & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,7 @@ func (s *session) ShowProcess() util.ProcessInfo {
tmp := s.processInfo.Load()
if tmp != nil {
pi = tmp.(util.ProcessInfo)
pi.Mem = s.GetSessionVars().StmtCtx.MemTracker.BytesConsumed()
}
return pi
}
Expand Down
1 change: 1 addition & 0 deletions util/processinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ProcessInfo struct {
Time time.Time
State uint16
Info string
Mem int64
}

// SessionManager is an interface for session manage. Show processlist and
Expand Down

0 comments on commit 27fa552

Please sign in to comment.