-
Notifications
You must be signed in to change notification settings - Fork 712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various CPU usage gains from profiling #742
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1fcd079
Use Readdirnames to reduce number of stats we're doing.
tomwilkie cde5920
Cache the contents of some files in /proc
tomwilkie 9cff569
Don't decode the certificates everytime we create an AppClient.
tomwilkie cc90c6c
Don't read tcp6 file (we don't deal with ipv6 anywhere else).
tomwilkie a2862ba
Don't list fds if there are not connections in the net namespace.
tomwilkie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package process | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/armon/go-metrics" | ||
"github.com/coocood/freecache" | ||
|
||
"github.com/weaveworks/scope/common/fs" | ||
) | ||
|
||
const ( | ||
generalTimeout = 30 // seconds | ||
statsTimeout = 10 //seconds | ||
) | ||
|
||
var ( | ||
hitMetricsKey = []string{"process", "cache", "hit"} | ||
missMetricsKey = []string{"process", "cache", "miss"} | ||
) | ||
|
||
var fileCache = freecache.NewCache(1024 * 16) | ||
|
||
type entry struct { | ||
buf []byte | ||
err error | ||
ts time.Time | ||
} | ||
|
||
func cachedReadFile(path string) ([]byte, error) { | ||
key := []byte(path) | ||
if v, err := fileCache.Get(key); err == nil { | ||
metrics.IncrCounter(hitMetricsKey, 1.0) | ||
return v, nil | ||
} | ||
|
||
buf, err := fs.ReadFile(path) | ||
fileCache.Set(key, buf, generalTimeout) | ||
metrics.IncrCounter(missMetricsKey, 1.0) | ||
return buf, err | ||
} | ||
|
||
// we cache the stats, but for a shorter period | ||
func readStats(path string) (int, int, error) { | ||
var ( | ||
key = []byte(path) | ||
buf []byte | ||
err error | ||
) | ||
if buf, err = fileCache.Get(key); err == nil { | ||
metrics.IncrCounter(hitMetricsKey, 1.0) | ||
} else { | ||
buf, err = fs.ReadFile(path) | ||
if err != nil { | ||
return -1, -1, err | ||
} | ||
fileCache.Set(key, buf, statsTimeout) | ||
metrics.IncrCounter(missMetricsKey, 1.0) | ||
} | ||
splits := strings.Fields(string(buf)) | ||
ppid, err := strconv.Atoi(splits[3]) | ||
if err != nil { | ||
return -1, -1, err | ||
} | ||
threads, err := strconv.Atoi(splits[19]) | ||
if err != nil { | ||
return -1, -1, err | ||
} | ||
return ppid, threads, nil | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
Sorry, something went wrong.