-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nydusify: add new option output-json
During convert, we can collect the metric: image size and convert time, etc. Nydusify can dump the metric to local file if user needs. Signed-off-by: Yadong Ding <[email protected]>
- Loading branch information
1 parent
3c31e13
commit c7c9fad
Showing
3 changed files
with
42 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2023 Nydus Developers. All rights reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package converter | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/goharbor/acceleration-service/pkg/converter" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func dumpMetric(metric *converter.Metric, workDir string) error { | ||
file, err := os.Create(filepath.Join(workDir, "output.json")) | ||
if err != nil { | ||
return errors.Wrap(err, "Create file for metric") | ||
} | ||
defer file.Close() | ||
|
||
encoder := json.NewEncoder(file) | ||
if err := encoder.Encode(metric); err != nil { | ||
return errors.Wrap(err, "Encode JSON from metric") | ||
} | ||
return nil | ||
} |