Skip to content

Commit 5c44fea

Browse files
committed
restore
Signed-off-by: Harper, Jason M <[email protected]>
1 parent b1b539f commit 5c44fea

File tree

6 files changed

+619
-6
lines changed

6 files changed

+619
-6
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,38 @@ $ ./perfspect config --cores 24 --llc 2.0 --uncore-max 1.8
129129
...
130130
</pre>
131131

132+
##### Recording Configuration
133+
Before making changes, you can record the current configuration to a file using the `--record` flag. This creates a human-readable configuration file that can be used to restore settings later.
134+
135+
Example:
136+
<pre>
137+
$ ./perfspect config --record
138+
Configuration recorded to: perfspect_2025-12-01_14-30-45/gnr_config.txt
139+
</pre>
140+
141+
##### Restoring Configuration
142+
The `config restore` subcommand restores configuration from a previously recorded file. This is useful for reverting changes or applying a known-good configuration across multiple systems.
143+
144+
Example:
145+
<pre>
146+
$ ./perfspect config restore perfspect_2025-12-01_14-30-45/gnr_config.txt
147+
Configuration settings to restore from perfspect_2025-12-01_14-30-45/gnr_config.txt:
148+
--cores 86
149+
--llc 2.4
150+
--uncore-max-compute 2.2
151+
...
152+
Apply these settings? (yes/no): yes
153+
...
154+
</pre>
155+
156+
Use the `--yes` flag to skip the confirmation prompt:
157+
<pre>
158+
$ ./perfspect config restore perfspect_2025-12-01_14-30-45/gnr_config.txt --yes
159+
</pre>
160+
161+
> [!TIP]
162+
> The restore command works with remote targets too. Use `--target` or `--targets` to restore configuration on remote systems.
163+
132164
### Common Command Options
133165

134166
#### Local vs. Remote Targets

cmd/config/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const cmdName = "config"
2626
var examples = []string{
2727
fmt.Sprintf(" Set core count on local host: $ %s %s --cores 32", common.AppName, cmdName),
2828
fmt.Sprintf(" Set multiple config items on local host: $ %s %s --core-max 3.0 --uncore-max 2.1 --tdp 120", common.AppName, cmdName),
29+
fmt.Sprintf(" Record current config to file: $ %s %s --record", common.AppName, cmdName),
30+
fmt.Sprintf(" Restore config from file: $ %s %s restore gnr_config.txt", common.AppName, cmdName),
2931
fmt.Sprintf(" Set core count on remote target: $ %s %s --cores 32 --target 192.168.1.1 --user fred --key fred_key", common.AppName, cmdName),
3032
fmt.Sprintf(" View current config on remote target: $ %s %s --target 192.168.1.1 --user fred --key fred_key", common.AppName, cmdName),
3133
fmt.Sprintf(" Set governor on remote targets: $ %s %s --gov performance --targets targets.yaml", common.AppName, cmdName),
@@ -367,7 +369,7 @@ func printConfig(reports map[string][]byte, toStdout bool, toFile bool, outputDi
367369
fmt.Print(string(reportBytes))
368370
}
369371
if toFile {
370-
outputFilePath := fmt.Sprintf("%s/config_%s.txt", outputDir, targetName)
372+
outputFilePath := fmt.Sprintf("%s/%s_config.txt", outputDir, targetName)
371373
err := os.WriteFile(outputFilePath, reportBytes, 0644) // #nosec G306
372374
if err != nil {
373375
err = fmt.Errorf("failed to write configuration report to file: %v", err)

cmd/config/flag_groups.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ const (
6767
const (
6868
flagNoSummaryName = "no-summary"
6969
flagRecordName = "record"
70-
flagRestoreName = "restore"
7170
)
7271

7372
// governorOptions - list of valid governor options
@@ -242,9 +241,6 @@ func initializeFlags(cmd *cobra.Command) {
242241
group.flags = append(group.flags,
243242
newBoolFlag(cmd, flagRecordName, false, nil, "record the current configuration to a file to be restored later", "", nil),
244243
)
245-
group.flags = append(group.flags,
246-
newStringFlag(cmd, flagRestoreName, "", nil, "restore a previously recorded configuration from the specified file", "", nil),
247-
)
248244
flagGroups = append(flagGroups, group)
249245

250246
common.AddTargetFlags(Cmd)
@@ -269,6 +265,11 @@ func usageFunc(cmd *cobra.Command) error {
269265
cmd.Printf(" --%-20s %s\n", flag.Name, flag.Help)
270266
}
271267

268+
cmd.Printf("\nSubcommands:\n")
269+
for _, subCmd := range cmd.Commands() {
270+
cmd.Printf(" %s: %s\n", subCmd.Name(), subCmd.Short)
271+
}
272+
272273
cmd.Println("\nGlobal Flags:")
273274
cmd.Parent().PersistentFlags().VisitAll(func(pf *pflag.Flag) {
274275
flagDefault := ""

0 commit comments

Comments
 (0)