-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1739 from crosbymichael/shim-redux
Move shim process code into subpackage
- Loading branch information
Showing
19 changed files
with
435 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package debug | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// Smaps prints the smaps to a file | ||
func Smaps(note, file string) error { | ||
smaps, err := getMaps(os.Getpid()) | ||
if err != nil { | ||
return err | ||
} | ||
f, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
fmt.Fprintf(f, "%s: rss %d\n", note, smaps["rss"]) | ||
fmt.Fprintf(f, "%s: pss %d\n", note, smaps["pss"]) | ||
return nil | ||
} | ||
|
||
func getMaps(pid int) (map[string]int, error) { | ||
f, err := os.Open(fmt.Sprintf("/proc/%d/smaps", pid)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
var ( | ||
smaps = make(map[string]int) | ||
s = bufio.NewScanner(f) | ||
) | ||
for s.Scan() { | ||
var ( | ||
fields = strings.Fields(s.Text()) | ||
name = fields[0] | ||
) | ||
name = strings.TrimSuffix(strings.ToLower(name), ":") | ||
if len(fields) < 2 { | ||
continue | ||
} | ||
n, err := strconv.Atoi(fields[1]) | ||
if err != nil { | ||
continue | ||
} | ||
smaps[name] += n | ||
} | ||
if err := s.Err(); err != nil { | ||
return nil, err | ||
} | ||
return smaps, nil | ||
} | ||
|
||
func keys(smaps map[string]int) []string { | ||
var o []string | ||
for k := range smaps { | ||
o = append(o, k) | ||
} | ||
sort.Strings(o) | ||
return o | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.