MCPcopy Index your code
hub / github.com/coder/coder / statCPU

Method statCPU

cli/stat.go:133–172  ·  view source on GitHub ↗
(fs afero.Fs)

Source from the content-addressed store, hash-verified

131}
132
133func (*RootCmd) statCPU(fs afero.Fs) *serpent.Command {
134 var (
135 hostArg bool
136 st *clistat.Statter
137 formatter = cliui.NewOutputFormatter(cliui.TextFormat(), cliui.JSONFormat())
138 )
139 cmd := &serpent.Command{
140 Use: "cpu",
141 Short: "Show CPU usage, in cores.",
142 Middleware: initStatterMW(&st, fs),
143 Options: serpent.OptionSet{
144 {
145 Flag: "host",
146 Value: serpent.BoolOf(&hostArg),
147 Description: "Force host CPU measurement.",
148 },
149 },
150 Handler: func(inv *serpent.Invocation) error {
151 var cs *clistat.Result
152 var err error
153 if ok, _ := st.IsContainerized(); ok && !hostArg {
154 cs, err = st.ContainerCPU()
155 } else {
156 cs, err = st.HostCPU()
157 }
158 if err != nil {
159 return err
160 }
161 out, err := formatter.Format(inv.Context(), cs)
162 if err != nil {
163 return err
164 }
165 _, err = fmt.Fprintln(inv.Stdout, out)
166 return err
167 },
168 }
169 formatter.AttachOptions(&cmd.Options)
170
171 return cmd
172}
173
174func (*RootCmd) statMem(fs afero.Fs) *serpent.Command {
175 var (

Callers 1

statMethod · 0.95

Calls 8

NewOutputFormatterFunction · 0.92
TextFormatFunction · 0.92
JSONFormatFunction · 0.92
initStatterMWFunction · 0.85
IsContainerizedMethod · 0.65
FormatMethod · 0.65
ContextMethod · 0.65
AttachOptionsMethod · 0.65

Tested by

no test coverage detected