-
Notifications
You must be signed in to change notification settings - Fork 110
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
RSDK-8819: Finish FTDC #4579
Open
dgottlieb
wants to merge
8
commits into
viamrobotics:main
Choose a base branch
from
dgottlieb:goutils-ftdc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−33
Open
RSDK-8819: Finish FTDC #4579
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a65d835
RSDK-8819: Add goutils rpc stats to FTDC.
dgottlieb 6a945bf
RSDK-8819: Parameterize FTDC diagnostics.data directory.
dgottlieb 8ca673d
RSDK-8819: Sort charts in ftdc viewing by metric name.
dgottlieb 68a11a6
RSDK-8819: Turn on FTDC by default.
dgottlieb 61ef64a
lint
dgottlieb 906a3b7
lint
dgottlieb fe547ab
lint
dgottlieb 9b1ce55
lint
dgottlieb 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,21 @@ package main | |
|
||
import ( | ||
"bufio" | ||
"cmp" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"math" | ||
"os" | ||
"os/exec" | ||
"slices" | ||
"strings" | ||
"time" | ||
|
||
"go.viam.com/utils" | ||
|
||
"go.viam.com/rdk/ftdc" | ||
"go.viam.com/rdk/logging" | ||
) | ||
|
||
// gnuplotWriter organizes all of the output for `gnuplot` to create a graph from FTDC | ||
|
@@ -36,6 +39,31 @@ type gnuplotWriter struct { | |
options graphOptions | ||
} | ||
|
||
type KVPair[K, V any] struct { | ||
Key K | ||
Val V | ||
} | ||
|
||
func sorted[K cmp.Ordered, V any](mp map[K]V) []KVPair[K, V] { | ||
ret := make([]KVPair[K, V], 0, len(mp)) | ||
for key, val := range mp { | ||
ret = append(ret, KVPair[K, V]{key, val}) | ||
} | ||
|
||
slices.SortFunc(ret, func(left, right KVPair[K, V]) int { | ||
if left.Key < right.Key { | ||
return -1 | ||
} | ||
if right.Key < left.Key { | ||
return 1 | ||
} | ||
|
||
return 0 | ||
}) | ||
|
||
return ret | ||
} | ||
|
||
type graphOptions struct { | ||
// minTimeSeconds and maxTimeSeconds control which datapoints should render based on their | ||
// timestamp. The default is all datapoints (minTimeSeconds: 0, maxTimeSeconds: MaxInt64). | ||
|
@@ -155,7 +183,8 @@ func (gpw *gnuplotWriter) CompileAndClose() string { | |
// per-graph setting rather than a global. | ||
writeln(gnuFile, "set yrange [0:*]") | ||
|
||
for metricName, file := range gpw.metricFiles { | ||
for _, nameFilePair := range sorted(gpw.metricFiles) { | ||
metricName, file := nameFilePair.Key, nameFilePair.Val | ||
writelnf(gnuFile, "plot '%v' using 1:2 with lines linestyle 7 lw 4 title '%v'", file.Name(), strings.ReplaceAll(metricName, "_", "\\_")) | ||
utils.UncheckedErrorFunc(file.Close) | ||
} | ||
|
@@ -165,25 +194,20 @@ func (gpw *gnuplotWriter) CompileAndClose() string { | |
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
// We are a CLI, it's appropriate to write to stdout. | ||
// | ||
|
||
nolintPrintln("Expected an FTDC filename. E.g: go run parser.go <path-to>/viam-server.ftdc") | ||
return | ||
} | ||
|
||
ftdcFile, err := os.Open(os.Args[1]) | ||
if err != nil { | ||
// We are a CLI, it's appropriate to write to stdout. | ||
// | ||
|
||
nolintPrintln("Error opening file. File:", os.Args[1], "Err:", err) | ||
|
||
nolintPrintln("Expected an FTDC filename. E.g: go run parser.go <path-to>/viam-server.ftdc") | ||
return | ||
} | ||
|
||
data, err := ftdc.Parse(ftdcFile) | ||
logger := logging.NewDebugLogger("parser") | ||
logger.SetLevel(logging.WARN) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced with a simple |
||
data, err := ftdc.ParseWithLogger(ftdcFile, logger) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect you'll enjoy this @benjirewis