...

Source file src/cmd/vendor/github.com/google/pprof/internal/driver/commands.go

     1	// Copyright 2014 Google Inc. All Rights Reserved.
     2	//
     3	// Licensed under the Apache License, Version 2.0 (the "License");
     4	// you may not use this file except in compliance with the License.
     5	// You may obtain a copy of the License at
     6	//
     7	//     http://www.apache.org/licenses/LICENSE-2.0
     8	//
     9	// Unless required by applicable law or agreed to in writing, software
    10	// distributed under the License is distributed on an "AS IS" BASIS,
    11	// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12	// See the License for the specific language governing permissions and
    13	// limitations under the License.
    14	
    15	package driver
    16	
    17	import (
    18		"bytes"
    19		"fmt"
    20		"io"
    21		"os"
    22		"os/exec"
    23		"runtime"
    24		"sort"
    25		"strconv"
    26		"strings"
    27		"time"
    28	
    29		"github.com/google/pprof/internal/plugin"
    30		"github.com/google/pprof/internal/report"
    31	)
    32	
    33	// commands describes the commands accepted by pprof.
    34	type commands map[string]*command
    35	
    36	// command describes the actions for a pprof command. Includes a
    37	// function for command-line completion, the report format to use
    38	// during report generation, any postprocessing functions, and whether
    39	// the command expects a regexp parameter (typically a function name).
    40	type command struct {
    41		format      int           // report format to generate
    42		postProcess PostProcessor // postprocessing to run on report
    43		visualizer  PostProcessor // display output using some callback
    44		hasParam    bool          // collect a parameter from the CLI
    45		description string        // single-line description text saying what the command does
    46		usage       string        // multi-line help text saying how the command is used
    47	}
    48	
    49	// help returns a help string for a command.
    50	func (c *command) help(name string) string {
    51		message := c.description + "\n"
    52		if c.usage != "" {
    53			message += "  Usage:\n"
    54			lines := strings.Split(c.usage, "\n")
    55			for _, line := range lines {
    56				message += fmt.Sprintf("    %s\n", line)
    57			}
    58		}
    59		return message + "\n"
    60	}
    61	
    62	// AddCommand adds an additional command to the set of commands
    63	// accepted by pprof. This enables extensions to add new commands for
    64	// specialized visualization formats. If the command specified already
    65	// exists, it is overwritten.
    66	func AddCommand(cmd string, format int, post PostProcessor, desc, usage string) {
    67		pprofCommands[cmd] = &command{format, post, nil, false, desc, usage}
    68	}
    69	
    70	// SetVariableDefault sets the default value for a pprof
    71	// variable. This enables extensions to set their own defaults.
    72	func SetVariableDefault(variable, value string) {
    73		if v := pprofVariables[variable]; v != nil {
    74			v.value = value
    75		}
    76	}
    77	
    78	// PostProcessor is a function that applies post-processing to the report output
    79	type PostProcessor func(input io.Reader, output io.Writer, ui plugin.UI) error
    80	
    81	// interactiveMode is true if pprof is running on interactive mode, reading
    82	// commands from its shell.
    83	var interactiveMode = false
    84	
    85	// pprofCommands are the report generation commands recognized by pprof.
    86	var pprofCommands = commands{
    87		// Commands that require no post-processing.
    88		"comments": {report.Comments, nil, nil, false, "Output all profile comments", ""},
    89		"disasm":   {report.Dis, nil, nil, true, "Output assembly listings annotated with samples", listHelp("disasm", true)},
    90		"dot":      {report.Dot, nil, nil, false, "Outputs a graph in DOT format", reportHelp("dot", false, true)},
    91		"list":     {report.List, nil, nil, true, "Output annotated source for functions matching regexp", listHelp("list", false)},
    92		"peek":     {report.Tree, nil, nil, true, "Output callers/callees of functions matching regexp", "peek func_regex\nDisplay callers and callees of functions matching func_regex."},
    93		"raw":      {report.Raw, nil, nil, false, "Outputs a text representation of the raw profile", ""},
    94		"tags":     {report.Tags, nil, nil, false, "Outputs all tags in the profile", "tags [tag_regex]* [-ignore_regex]* [>file]\nList tags with key:value matching tag_regex and exclude ignore_regex."},
    95		"text":     {report.Text, nil, nil, false, "Outputs top entries in text form", reportHelp("text", true, true)},
    96		"top":      {report.Text, nil, nil, false, "Outputs top entries in text form", reportHelp("top", true, true)},
    97		"traces":   {report.Traces, nil, nil, false, "Outputs all profile samples in text form", ""},
    98		"tree":     {report.Tree, nil, nil, false, "Outputs a text rendering of call graph", reportHelp("tree", true, true)},
    99	
   100		// Save binary formats to a file
   101		"callgrind": {report.Callgrind, nil, awayFromTTY("callgraph.out"), false, "Outputs a graph in callgrind format", reportHelp("callgrind", false, true)},
   102		"proto":     {report.Proto, nil, awayFromTTY("pb.gz"), false, "Outputs the profile in compressed protobuf format", ""},
   103		"topproto":  {report.TopProto, nil, awayFromTTY("pb.gz"), false, "Outputs top entries in compressed protobuf format", ""},
   104	
   105		// Generate report in DOT format and postprocess with dot
   106		"gif": {report.Dot, invokeDot("gif"), awayFromTTY("gif"), false, "Outputs a graph image in GIF format", reportHelp("gif", false, true)},
   107		"pdf": {report.Dot, invokeDot("pdf"), awayFromTTY("pdf"), false, "Outputs a graph in PDF format", reportHelp("pdf", false, true)},
   108		"png": {report.Dot, invokeDot("png"), awayFromTTY("png"), false, "Outputs a graph image in PNG format", reportHelp("png", false, true)},
   109		"ps":  {report.Dot, invokeDot("ps"), awayFromTTY("ps"), false, "Outputs a graph in PS format", reportHelp("ps", false, true)},
   110	
   111		// Save SVG output into a file
   112		"svg": {report.Dot, massageDotSVG(), awayFromTTY("svg"), false, "Outputs a graph in SVG format", reportHelp("svg", false, true)},
   113	
   114		// Visualize postprocessed dot output
   115		"eog":    {report.Dot, invokeDot("svg"), invokeVisualizer("svg", []string{"eog"}), false, "Visualize graph through eog", reportHelp("eog", false, false)},
   116		"evince": {report.Dot, invokeDot("pdf"), invokeVisualizer("pdf", []string{"evince"}), false, "Visualize graph through evince", reportHelp("evince", false, false)},
   117		"gv":     {report.Dot, invokeDot("ps"), invokeVisualizer("ps", []string{"gv --noantialias"}), false, "Visualize graph through gv", reportHelp("gv", false, false)},
   118		"web":    {report.Dot, massageDotSVG(), invokeVisualizer("svg", browsers()), false, "Visualize graph through web browser", reportHelp("web", false, false)},
   119	
   120		// Visualize callgrind output
   121		"kcachegrind": {report.Callgrind, nil, invokeVisualizer("grind", kcachegrind), false, "Visualize report in KCachegrind", reportHelp("kcachegrind", false, false)},
   122	
   123		// Visualize HTML directly generated by report.
   124		"weblist": {report.WebList, nil, invokeVisualizer("html", browsers()), true, "Display annotated source in a web browser", listHelp("weblist", false)},
   125	}
   126	
   127	// pprofVariables are the configuration parameters that affect the
   128	// reported generated by pprof.
   129	var pprofVariables = variables{
   130		// Filename for file-based output formats, stdout by default.
   131		"output": &variable{stringKind, "", "", helpText("Output filename for file-based outputs")},
   132	
   133		// Comparisons.
   134		"drop_negative": &variable{boolKind, "f", "", helpText(
   135			"Ignore negative differences",
   136			"Do not show any locations with values <0.")},
   137	
   138		// Graph handling options.
   139		"call_tree": &variable{boolKind, "f", "", helpText(
   140			"Create a context-sensitive call tree",
   141			"Treat locations reached through different paths as separate.")},
   142	
   143		// Display options.
   144		"relative_percentages": &variable{boolKind, "f", "", helpText(
   145			"Show percentages relative to focused subgraph",
   146			"If unset, percentages are relative to full graph before focusing",
   147			"to facilitate comparison with original graph.")},
   148		"unit": &variable{stringKind, "minimum", "", helpText(
   149			"Measurement units to display",
   150			"Scale the sample values to this unit.",
   151			"For time-based profiles, use seconds, milliseconds, nanoseconds, etc.",
   152			"For memory profiles, use megabytes, kilobytes, bytes, etc.",
   153			"Using auto will scale each value independently to the most natural unit.")},
   154		"compact_labels": &variable{boolKind, "f", "", "Show minimal headers"},
   155		"source_path":    &variable{stringKind, "", "", "Search path for source files"},
   156		"trim_path":      &variable{stringKind, "", "", "Path to trim from source paths before search"},
   157	
   158		// Filtering options
   159		"nodecount": &variable{intKind, "-1", "", helpText(
   160			"Max number of nodes to show",
   161			"Uses heuristics to limit the number of locations to be displayed.",
   162			"On graphs, dotted edges represent paths through nodes that have been removed.")},
   163		"nodefraction": &variable{floatKind, "0.005", "", "Hide nodes below <f>*total"},
   164		"edgefraction": &variable{floatKind, "0.001", "", "Hide edges below <f>*total"},
   165		"trim": &variable{boolKind, "t", "", helpText(
   166			"Honor nodefraction/edgefraction/nodecount defaults",
   167			"Set to false to get the full profile, without any trimming.")},
   168		"focus": &variable{stringKind, "", "", helpText(
   169			"Restricts to samples going through a node matching regexp",
   170			"Discard samples that do not include a node matching this regexp.",
   171			"Matching includes the function name, filename or object name.")},
   172		"ignore": &variable{stringKind, "", "", helpText(
   173			"Skips paths going through any nodes matching regexp",
   174			"If set, discard samples that include a node matching this regexp.",
   175			"Matching includes the function name, filename or object name.")},
   176		"prune_from": &variable{stringKind, "", "", helpText(
   177			"Drops any functions below the matched frame.",
   178			"If set, any frames matching the specified regexp and any frames",
   179			"below it will be dropped from each sample.")},
   180		"hide": &variable{stringKind, "", "", helpText(
   181			"Skips nodes matching regexp",
   182			"Discard nodes that match this location.",
   183			"Other nodes from samples that include this location will be shown.",
   184			"Matching includes the function name, filename or object name.")},
   185		"show": &variable{stringKind, "", "", helpText(
   186			"Only show nodes matching regexp",
   187			"If set, only show nodes that match this location.",
   188			"Matching includes the function name, filename or object name.")},
   189		"show_from": &variable{stringKind, "", "", helpText(
   190			"Drops functions above the highest matched frame.",
   191			"If set, all frames above the highest match are dropped from every sample.",
   192			"Matching includes the function name, filename or object name.")},
   193		"tagfocus": &variable{stringKind, "", "", helpText(
   194			"Restricts to samples with tags in range or matched by regexp",
   195			"Use name=value syntax to limit the matching to a specific tag.",
   196			"Numeric tag filter examples: 1kb, 1kb:10kb, memory=32mb:",
   197			"String tag filter examples: foo, foo.*bar, mytag=foo.*bar")},
   198		"tagignore": &variable{stringKind, "", "", helpText(
   199			"Discard samples with tags in range or matched by regexp",
   200			"Use name=value syntax to limit the matching to a specific tag.",
   201			"Numeric tag filter examples: 1kb, 1kb:10kb, memory=32mb:",
   202			"String tag filter examples: foo, foo.*bar, mytag=foo.*bar")},
   203		"tagshow": &variable{stringKind, "", "", helpText(
   204			"Only consider tags matching this regexp",
   205			"Discard tags that do not match this regexp")},
   206		"taghide": &variable{stringKind, "", "", helpText(
   207			"Skip tags matching this regexp",
   208			"Discard tags that match this regexp")},
   209		// Heap profile options
   210		"divide_by": &variable{floatKind, "1", "", helpText(
   211			"Ratio to divide all samples before visualization",
   212			"Divide all samples values by a constant, eg the number of processors or jobs.")},
   213		"mean": &variable{boolKind, "f", "", helpText(
   214			"Average sample value over first value (count)",
   215			"For memory profiles, report average memory per allocation.",
   216			"For time-based profiles, report average time per event.")},
   217		"sample_index": &variable{stringKind, "", "", helpText(
   218			"Sample value to report (0-based index or name)",
   219			"Profiles contain multiple values per sample.",
   220			"Use sample_index=i to select the ith value (starting at 0).")},
   221		"normalize": &variable{boolKind, "f", "", helpText(
   222			"Scales profile based on the base profile.")},
   223	
   224		// Data sorting criteria
   225		"flat": &variable{boolKind, "t", "cumulative", helpText("Sort entries based on own weight")},
   226		"cum":  &variable{boolKind, "f", "cumulative", helpText("Sort entries based on cumulative weight")},
   227	
   228		// Output granularity
   229		"functions": &variable{boolKind, "t", "granularity", helpText(
   230			"Aggregate at the function level.",
   231			"Ignores the filename where the function was defined.")},
   232		"filefunctions": &variable{boolKind, "t", "granularity", helpText(
   233			"Aggregate at the function level.",
   234			"Takes into account the filename where the function was defined.")},
   235		"files": &variable{boolKind, "f", "granularity", "Aggregate at the file level."},
   236		"lines": &variable{boolKind, "f", "granularity", "Aggregate at the source code line level."},
   237		"addresses": &variable{boolKind, "f", "granularity", helpText(
   238			"Aggregate at the address level.",
   239			"Includes functions' addresses in the output.")},
   240		"noinlines": &variable{boolKind, "f", "", helpText(
   241			"Ignore inlines.",
   242			"Attributes inlined functions to their first out-of-line caller.")},
   243	}
   244	
   245	func helpText(s ...string) string {
   246		return strings.Join(s, "\n") + "\n"
   247	}
   248	
   249	// usage returns a string describing the pprof commands and variables.
   250	// if commandLine is set, the output reflect cli usage.
   251	func usage(commandLine bool) string {
   252		var prefix string
   253		if commandLine {
   254			prefix = "-"
   255		}
   256		fmtHelp := func(c, d string) string {
   257			return fmt.Sprintf("    %-16s %s", c, strings.SplitN(d, "\n", 2)[0])
   258		}
   259	
   260		var commands []string
   261		for name, cmd := range pprofCommands {
   262			commands = append(commands, fmtHelp(prefix+name, cmd.description))
   263		}
   264		sort.Strings(commands)
   265	
   266		var help string
   267		if commandLine {
   268			help = "  Output formats (select at most one):\n"
   269		} else {
   270			help = "  Commands:\n"
   271			commands = append(commands, fmtHelp("o/options", "List options and their current values"))
   272			commands = append(commands, fmtHelp("quit/exit/^D", "Exit pprof"))
   273		}
   274	
   275		help = help + strings.Join(commands, "\n") + "\n\n" +
   276			"  Options:\n"
   277	
   278		// Print help for variables after sorting them.
   279		// Collect radio variables by their group name to print them together.
   280		radioOptions := make(map[string][]string)
   281		var variables []string
   282		for name, vr := range pprofVariables {
   283			if vr.group != "" {
   284				radioOptions[vr.group] = append(radioOptions[vr.group], name)
   285				continue
   286			}
   287			variables = append(variables, fmtHelp(prefix+name, vr.help))
   288		}
   289		sort.Strings(variables)
   290	
   291		help = help + strings.Join(variables, "\n") + "\n\n" +
   292			"  Option groups (only set one per group):\n"
   293	
   294		var radioStrings []string
   295		for radio, ops := range radioOptions {
   296			sort.Strings(ops)
   297			s := []string{fmtHelp(radio, "")}
   298			for _, op := range ops {
   299				s = append(s, "  "+fmtHelp(prefix+op, pprofVariables[op].help))
   300			}
   301	
   302			radioStrings = append(radioStrings, strings.Join(s, "\n"))
   303		}
   304		sort.Strings(radioStrings)
   305		return help + strings.Join(radioStrings, "\n")
   306	}
   307	
   308	func reportHelp(c string, cum, redirect bool) string {
   309		h := []string{
   310			c + " [n] [focus_regex]* [-ignore_regex]*",
   311			"Include up to n samples",
   312			"Include samples matching focus_regex, and exclude ignore_regex.",
   313		}
   314		if cum {
   315			h[0] += " [-cum]"
   316			h = append(h, "-cum sorts the output by cumulative weight")
   317		}
   318		if redirect {
   319			h[0] += " >f"
   320			h = append(h, "Optionally save the report on the file f")
   321		}
   322		return strings.Join(h, "\n")
   323	}
   324	
   325	func listHelp(c string, redirect bool) string {
   326		h := []string{
   327			c + "<func_regex|address> [-focus_regex]* [-ignore_regex]*",
   328			"Include functions matching func_regex, or including the address specified.",
   329			"Include samples matching focus_regex, and exclude ignore_regex.",
   330		}
   331		if redirect {
   332			h[0] += " >f"
   333			h = append(h, "Optionally save the report on the file f")
   334		}
   335		return strings.Join(h, "\n")
   336	}
   337	
   338	// browsers returns a list of commands to attempt for web visualization.
   339	func browsers() []string {
   340		var cmds []string
   341		if userBrowser := os.Getenv("BROWSER"); userBrowser != "" {
   342			cmds = append(cmds, userBrowser)
   343		}
   344		switch runtime.GOOS {
   345		case "darwin":
   346			cmds = append(cmds, "/usr/bin/open")
   347		case "windows":
   348			cmds = append(cmds, "cmd /c start")
   349		default:
   350			// Commands opening browsers are prioritized over xdg-open, so browser()
   351			// command can be used on linux to open the .svg file generated by the -web
   352			// command (the .svg file includes embedded javascript so is best viewed in
   353			// a browser).
   354			cmds = append(cmds, []string{"chrome", "google-chrome", "chromium", "firefox", "sensible-browser"}...)
   355			if os.Getenv("DISPLAY") != "" {
   356				// xdg-open is only for use in a desktop environment.
   357				cmds = append(cmds, "xdg-open")
   358			}
   359		}
   360		return cmds
   361	}
   362	
   363	var kcachegrind = []string{"kcachegrind"}
   364	
   365	// awayFromTTY saves the output in a file if it would otherwise go to
   366	// the terminal screen. This is used to avoid dumping binary data on
   367	// the screen.
   368	func awayFromTTY(format string) PostProcessor {
   369		return func(input io.Reader, output io.Writer, ui plugin.UI) error {
   370			if output == os.Stdout && (ui.IsTerminal() || interactiveMode) {
   371				tempFile, err := newTempFile("", "profile", "."+format)
   372				if err != nil {
   373					return err
   374				}
   375				ui.PrintErr("Generating report in ", tempFile.Name())
   376				output = tempFile
   377			}
   378			_, err := io.Copy(output, input)
   379			return err
   380		}
   381	}
   382	
   383	func invokeDot(format string) PostProcessor {
   384		return func(input io.Reader, output io.Writer, ui plugin.UI) error {
   385			cmd := exec.Command("dot", "-T"+format)
   386			cmd.Stdin, cmd.Stdout, cmd.Stderr = input, output, os.Stderr
   387			if err := cmd.Run(); err != nil {
   388				return fmt.Errorf("failed to execute dot. Is Graphviz installed? Error: %v", err)
   389			}
   390			return nil
   391		}
   392	}
   393	
   394	// massageDotSVG invokes the dot tool to generate an SVG image and alters
   395	// the image to have panning capabilities when viewed in a browser.
   396	func massageDotSVG() PostProcessor {
   397		generateSVG := invokeDot("svg")
   398		return func(input io.Reader, output io.Writer, ui plugin.UI) error {
   399			baseSVG := new(bytes.Buffer)
   400			if err := generateSVG(input, baseSVG, ui); err != nil {
   401				return err
   402			}
   403			_, err := output.Write([]byte(massageSVG(baseSVG.String())))
   404			return err
   405		}
   406	}
   407	
   408	func invokeVisualizer(suffix string, visualizers []string) PostProcessor {
   409		return func(input io.Reader, output io.Writer, ui plugin.UI) error {
   410			tempFile, err := newTempFile(os.TempDir(), "pprof", "."+suffix)
   411			if err != nil {
   412				return err
   413			}
   414			deferDeleteTempFile(tempFile.Name())
   415			if _, err := io.Copy(tempFile, input); err != nil {
   416				return err
   417			}
   418			tempFile.Close()
   419			// Try visualizers until one is successful
   420			for _, v := range visualizers {
   421				// Separate command and arguments for exec.Command.
   422				args := strings.Split(v, " ")
   423				if len(args) == 0 {
   424					continue
   425				}
   426				viewer := exec.Command(args[0], append(args[1:], tempFile.Name())...)
   427				viewer.Stderr = os.Stderr
   428				if err = viewer.Start(); err == nil {
   429					// Wait for a second so that the visualizer has a chance to
   430					// open the input file. This needs to be done even if we're
   431					// waiting for the visualizer as it can be just a wrapper that
   432					// spawns a browser tab and returns right away.
   433					defer func(t <-chan time.Time) {
   434						<-t
   435					}(time.After(time.Second))
   436					// On interactive mode, let the visualizer run in the background
   437					// so other commands can be issued.
   438					if !interactiveMode {
   439						return viewer.Wait()
   440					}
   441					return nil
   442				}
   443			}
   444			return err
   445		}
   446	}
   447	
   448	// variables describe the configuration parameters recognized by pprof.
   449	type variables map[string]*variable
   450	
   451	// variable is a single configuration parameter.
   452	type variable struct {
   453		kind  int    // How to interpret the value, must be one of the enums below.
   454		value string // Effective value. Only values appropriate for the Kind should be set.
   455		group string // boolKind variables with the same Group != "" cannot be set simultaneously.
   456		help  string // Text describing the variable, in multiple lines separated by newline.
   457	}
   458	
   459	const (
   460		// variable.kind must be one of these variables.
   461		boolKind = iota
   462		intKind
   463		floatKind
   464		stringKind
   465	)
   466	
   467	// set updates the value of a variable, checking that the value is
   468	// suitable for the variable Kind.
   469	func (vars variables) set(name, value string) error {
   470		v := vars[name]
   471		if v == nil {
   472			return fmt.Errorf("no variable %s", name)
   473		}
   474		var err error
   475		switch v.kind {
   476		case boolKind:
   477			var b bool
   478			if b, err = stringToBool(value); err == nil {
   479				if v.group != "" && !b {
   480					err = fmt.Errorf("%q can only be set to true", name)
   481				}
   482			}
   483		case intKind:
   484			_, err = strconv.Atoi(value)
   485		case floatKind:
   486			_, err = strconv.ParseFloat(value, 64)
   487		case stringKind:
   488			// Remove quotes, particularly useful for empty values.
   489			if len(value) > 1 && strings.HasPrefix(value, `"`) && strings.HasSuffix(value, `"`) {
   490				value = value[1 : len(value)-1]
   491			}
   492		}
   493		if err != nil {
   494			return err
   495		}
   496		vars[name].value = value
   497		if group := vars[name].group; group != "" {
   498			for vname, vvar := range vars {
   499				if vvar.group == group && vname != name {
   500					vvar.value = "f"
   501				}
   502			}
   503		}
   504		return err
   505	}
   506	
   507	// boolValue returns the value of a boolean variable.
   508	func (v *variable) boolValue() bool {
   509		b, err := stringToBool(v.value)
   510		if err != nil {
   511			panic("unexpected value " + v.value + " for bool ")
   512		}
   513		return b
   514	}
   515	
   516	// intValue returns the value of an intKind variable.
   517	func (v *variable) intValue() int {
   518		i, err := strconv.Atoi(v.value)
   519		if err != nil {
   520			panic("unexpected value " + v.value + " for int ")
   521		}
   522		return i
   523	}
   524	
   525	// floatValue returns the value of a Float variable.
   526	func (v *variable) floatValue() float64 {
   527		f, err := strconv.ParseFloat(v.value, 64)
   528		if err != nil {
   529			panic("unexpected value " + v.value + " for float ")
   530		}
   531		return f
   532	}
   533	
   534	// stringValue returns a canonical representation for a variable.
   535	func (v *variable) stringValue() string {
   536		switch v.kind {
   537		case boolKind:
   538			return fmt.Sprint(v.boolValue())
   539		case intKind:
   540			return fmt.Sprint(v.intValue())
   541		case floatKind:
   542			return fmt.Sprint(v.floatValue())
   543		}
   544		return v.value
   545	}
   546	
   547	func stringToBool(s string) (bool, error) {
   548		switch strings.ToLower(s) {
   549		case "true", "t", "yes", "y", "1", "":
   550			return true, nil
   551		case "false", "f", "no", "n", "0":
   552			return false, nil
   553		default:
   554			return false, fmt.Errorf(`illegal value "%s" for bool variable`, s)
   555		}
   556	}
   557	
   558	// makeCopy returns a duplicate of a set of shell variables.
   559	func (vars variables) makeCopy() variables {
   560		varscopy := make(variables, len(vars))
   561		for n, v := range vars {
   562			vcopy := *v
   563			varscopy[n] = &vcopy
   564		}
   565		return varscopy
   566	}
   567	

View as plain text