// Copyright 2016 Google Inc. All Rights Reserved.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.package profileimport ()// SampleIndexByName returns the appropriate index for a value of sample index.// If numeric, it returns the number, otherwise it looks up the text in the// profile sample types.func ( *Profile) ( string) (int, error) {if == "" {if := .DefaultSampleType; != "" {for , := rangesampleTypes() {if == {return , nil } } }// By default select the last sample valuereturnlen(.SampleType) - 1, nil }if , := strconv.Atoi(); == nil {if < 0 || >= len(.SampleType) {return0, fmt.Errorf("sample_index %s is outside the range [0..%d]", , len(.SampleType)-1) }return , nil }// Remove the inuse_ prefix to support legacy pprof options // "inuse_space" and "inuse_objects" for profiles containing types // "space" and "objects". := strings.TrimPrefix(, "inuse_")for , := range .SampleType {if .Type == || .Type == {return , nil } }return0, fmt.Errorf("sample_index %q must be one of: %v", , sampleTypes())}func sampleTypes( *Profile) []string { := make([]string, len(.SampleType))for , := range .SampleType { [] = .Type }return}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.