@@ -14,7 +14,6 @@ import (
1414 "github.com/checkpoint-restore/checkpointctl/internal"
1515 metadata "github.com/checkpoint-restore/checkpointctl/lib"
1616 "github.com/checkpoint-restore/go-criu/v7/crit"
17- "github.com/olekukonko/tablewriter"
1817 "github.com/spf13/cobra"
1918)
2019
@@ -116,21 +115,16 @@ func memparse(cmd *cobra.Command, args []string) error {
116115
117116// Display processes memory sizes within the given container checkpoints.
118117func showProcessMemorySizeTables (tasks []internal.Task ) error {
119- // Initialize the table
120- table := tablewriter .NewWriter (os .Stdout )
121118 header := []string {
122119 "PID" ,
123120 "Process name" ,
124121 "Memory size" ,
125122 "Shared memory size" ,
126123 }
127- table .SetHeader (header )
128- table .SetAutoMergeCells (false )
129- table .SetRowLine (true )
130124
131125 // Function to recursively traverse the process tree and populate the table rows
132- var traverseTree func (* crit.PsTree , string ) error
133- traverseTree = func (root * crit.PsTree , checkpointOutputDir string ) error {
126+ var traverseTree func (* crit.PsTree , string , * [][] string ) error
127+ traverseTree = func (root * crit.PsTree , checkpointOutputDir string , rows * [][] string ) error {
134128 memReader , err := crit .NewMemoryReader (
135129 filepath .Join (checkpointOutputDir , metadata .CheckpointDirectory ),
136130 root .PID , pageSize ,
@@ -152,24 +146,25 @@ func showProcessMemorySizeTables(tasks []internal.Task) error {
152146 return err
153147 }
154148
155- table . Append ( []string {
149+ row := []string {
156150 fmt .Sprintf ("%d" , root .PID ),
157151 root .Comm ,
158152 metadata .ByteToString (memSize ),
159153 metadata .ByteToString (shmemSize ),
160- })
154+ }
155+ * rows = append (* rows , row )
161156
162157 for _ , child := range root .Children {
163- if err := traverseTree (child , checkpointOutputDir ); err != nil {
158+ if err := traverseTree (child , checkpointOutputDir , rows ); err != nil {
164159 return err
165160 }
166161 }
167162 return nil
168163 }
169164
170165 for _ , task := range tasks {
171- // Clear the table before processing each checkpoint task
172- table . ClearRows ()
166+ w := internal . GetNewTabWriter ( os . Stdout )
167+ var rows [][] string
173168
174169 c := crit .New (nil , nil , filepath .Join (task .OutputDir , "checkpoint" ), false , false )
175170 psTree , err := c .ExplorePs ()
@@ -178,12 +173,16 @@ func showProcessMemorySizeTables(tasks []internal.Task) error {
178173 }
179174
180175 // Populate the table rows
181- if err := traverseTree (psTree , task .OutputDir ); err != nil {
176+ if err := traverseTree (psTree , task .OutputDir , & rows ); err != nil {
182177 return err
183178 }
184179
185180 fmt .Printf ("\n Displaying processes memory sizes from %s\n \n " , task .CheckpointFilePath )
186- table .Render ()
181+
182+ internal .WriteTableHeader (w , header )
183+ internal .WriteTableRows (w , rows )
184+
185+ w .Flush ()
187186 }
188187
189188 return nil
@@ -348,21 +347,24 @@ func printMemorySearchResultForPID(task internal.Task) error {
348347 return nil
349348 }
350349
351- table := tablewriter .NewWriter (os .Stdout )
352- table .SetHeader ([]string {"Address" , "Match" , "Instance" })
353- table .SetAutoMergeCells (false )
354- table .SetRowLine (true )
350+ w := internal .GetNewTabWriter (os .Stdout )
351+ header := []string {"Address" , "Match" , "Instance" }
355352
353+ internal .WriteTableHeader (w , header )
354+
355+ // Build rows
356+ var rows [][]string
356357 for i , result := range results {
357- table .Append ([]string {
358- fmt .Sprintf (
359- "%016x" , result .Vaddr ),
358+ row := []string {
359+ fmt .Sprintf ("%016x" , result .Vaddr ),
360360 result .Match ,
361361 fmt .Sprintf ("%d" , i + 1 ),
362- })
362+ }
363+ rows = append (rows , row )
363364 }
364365
365- table . Render ( )
366+ internal . WriteTableRows ( w , rows )
366367
368+ w .Flush ()
367369 return nil
368370}
0 commit comments