Skip to content

Commit 6441de2

Browse files
committed
added width, height and output filename options
1 parent f9bfe85 commit 6441de2

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

cmd/memplot.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ func main() {
2323
PlotVsz: false,
2424
}
2525

26-
pidPtr := flag.Int("pid", -1, "pid of the process to analyze")
27-
2826
// Default sample duration time
2927
defaultSd, err := time.ParseDuration("5ms")
3028
check(err)
@@ -33,15 +31,28 @@ func main() {
3331
defaultDur, err := time.ParseDuration("10s")
3432
check(err)
3533

34+
defaultFilename := "output-plot.png"
35+
pidPtr := flag.Int("pid", -1, "pid of the process to analyze")
36+
filenamePtr := flag.String("o", defaultFilename, "output image file name")
3637
sdPtr := flag.Duration("sd", defaultSd, "sample size in time")
3738
durPtr := flag.Duration("dur", defaultDur, "total profiling time")
3839

40+
// To plot or not VSZ
3941
flag.BoolVar(&opts.PlotVsz, "vsz", false, "plot virtual size")
4042

43+
widthStr := flag.String("w", "16cm", "plot image width (can be cm or in)")
44+
heightStr := flag.String("h", "12cm", "plot image height (can be cm or in)")
45+
4146
flag.Parse()
47+
48+
// Checks for valid flags
4249
if *pidPtr <= 0 {
4350
panic(errors.New("Invalid PID. Please specify a PID using -pid flag"))
4451
}
52+
widthImage, err := vg.ParseLength(*widthStr)
53+
check(err)
54+
heightImage, err := vg.ParseLength(*heightStr)
55+
check(err)
4556

4657
// Create and sample
4758
fmt.Fprintln(os.Stderr, "Analyzing PID", *pidPtr, "...")
@@ -53,6 +64,6 @@ func main() {
5364
check(err)
5465

5566
fmt.Fprintln(os.Stderr, "Saving plot..")
56-
memplot.SavePlot(plot, 8*vg.Inch, 8*vg.Inch, "plot.png")
67+
memplot.SavePlot(plot, widthImage, heightImage, *filenamePtr)
5768

5869
}

memplot.go

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func (m *MemoryCollection) Plot(opt PlotOptions) (*plot.Plot, error) {
122122
p.Legend.Add("RSS", rssLine)
123123
}
124124

125+
// TODO add another Y axis for vsz
125126
if opt.PlotVsz {
126127
// RSS line plotter and style
127128
vszData := m.GatherVSZXYs()

0 commit comments

Comments
 (0)