@@ -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}
0 commit comments