// resourcesForProfile takes standard Heroku sizes described here:
// https://devcenter.heroku.com/articles/dyno-types#available-dyno-types and turns them into
// Kubernetes resource requests.
342650
func resourcesForProfile(profile string) corev1.ResourceRequirements {
	profile = strings.ToLower(profile)
	switch profile {
	case "standard-2x":
		return corev1.ResourceRequirements{
			Limits: corev1.ResourceList{
				corev1.ResourceCPU:    resource.MustParse("200m"),
				corev1.ResourceMemory: resource.MustParse("1Gi"),
			},
		}
	case "performance-m":
		return corev1.ResourceRequirements{
			Requests: corev1.ResourceList{
				corev1.ResourceCPU: resource.MustParse("500m"),
			},
			Limits: corev1.ResourceList{
				corev1.ResourceCPU:    resource.MustParse("500m"),
				corev1.ResourceMemory: resource.MustParse("2.5Gi"),
			},
		}
	case "performance-l":
		return corev1.ResourceRequirements{
			Requests: corev1.ResourceList{
				corev1.ResourceCPU:    resource.MustParse("1"),
				corev1.ResourceMemory: resource.MustParse("2G"),
			},
			Limits: corev1.ResourceList{
				corev1.ResourceCPU:    resource.MustParse("2"),
				corev1.ResourceMemory: resource.MustParse("14Gi"),
			},
		}
	case "free", "hobby", "standard":
		fallthrough
	default:
		return corev1.ResourceRequirements{
			Limits: corev1.ResourceList{
				corev1.ResourceCPU:    resource.MustParse("100m"),
				corev1.ResourceMemory: resource.MustParse("512Mi"),
			},
		}
	}
}
388480
func parseJavaProfile(b []byte) (*Profile, error) {
	h := bytes.SplitAfterN(b, []byte("\n"), 2)
	if len(h) < 2 {
		return nil, errUnrecognized
	}

	p := &Profile{
		PeriodType: &ValueType{},
	}
	header := string(bytes.TrimSpace(h[0]))

	var err error
	var pType string
	switch header {
	case "--- heapz 1 ---":
		pType = "heap"
	case "--- contentionz 1 ---":
		pType = "contention"
	default:
		return nil, errUnrecognized
	}

	if b, err = parseJavaHeader(pType, h[1], p); err != nil {
		return nil, err
	}
	var locs map[uint64]*Location
	if b, locs, err = parseJavaSamples(pType, b, p); err != nil {
		return nil, err
	}
	if err = parseJavaLocations(b, locs, p); err != nil {
		return nil, err
	}

	// Strip out addresses for better merge.
	if err = p.Aggregate(true, true, true, true, false); err != nil {
		return nil, err
	}

	return p, nil
}
202030
func (o *Me) InfrastructureGatewayProfiles(info *bambou.FetchingInfo) (InfrastructureGatewayProfilesList, *bambou.Error) {

	var list InfrastructureGatewayProfilesList
	err := bambou.CurrentSession().FetchChildren(o, InfrastructureGatewayProfileIdentity, &list, info)
	return list, err
}
1133042
func (c *ContivClient) NetprofileList() (*[]*Netprofile, error) {
	// build key and URL
	url := c.baseURL + "/api/v1/netprofiles/"

	// http get the object
	var objList []*Netprofile
	err := c.httpGet(url, &objList)
	if err != nil {
		log.Debugf("Error getting netprofiles. Err: %v", err)
		return nil, err
	}

	return &objList, nil
}
67800
func FetchProfile(source string, timeout time.Duration) (*profile.Profile, error) {
	return Fetcher(source, timeout, plugin.StandardUI())
}
434311
func (ps *ProviderSchema) SchemaForResourceType(mode addrs.ResourceMode, typeName string) (schema *configschema.Block, version uint64) {
	switch mode {
	case addrs.ManagedResourceMode:
		return ps.ResourceTypes[typeName], ps.ResourceTypeSchemaVersions[typeName]
	case addrs.DataResourceMode:
		// Data resources don't have schema versions right now, since state is discarded for each refresh
		return ps.DataSources[typeName], 0
	default:
		// Shouldn't happen, because the above cases are comprehensive.
		return nil, 0
	}
}
1318175
func (p *Client) DiscoverProfile(force bool) (*ble.Profile, error) {
	if p.profile != nil && !force {
		return p.profile, nil
	}
	ss, err := p.DiscoverServices(nil)
	if err != nil {
		return nil, fmt.Errorf("can't discover services: %s\n", err)
	}
	for _, s := range ss {
		cs, err := p.DiscoverCharacteristics(nil, s)
		if err != nil {
			return nil, fmt.Errorf("can't discover characteristics: %s\n", err)
		}
		for _, c := range cs {
			_, err := p.DiscoverDescriptors(nil, c)
			if err != nil {
				return nil, fmt.Errorf("can't discover descriptors: %s\n", err)
			}
		}
	}
	p.profile = &ble.Profile{Services: ss}
	return p.profile, nil
}
174372
func (t *Template) GetAllAWSIAMInstanceProfileResources() map[string]*resources.AWSIAMInstanceProfile {
	results := map[string]*resources.AWSIAMInstanceProfile{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSIAMInstanceProfile:
			results[name] = resource
		}
	}
	return results
}
273734
func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
	switch resource {
	// Group=apiregistration.k8s.io, Version=v1
	case v1.SchemeGroupVersion.WithResource("apiservices"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Apiregistration().V1().APIServices().Informer()}, nil

		// Group=apiregistration.k8s.io, Version=v1beta1
	case v1beta1.SchemeGroupVersion.WithResource("apiservices"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Apiregistration().V1beta1().APIServices().Informer()}, nil

	}

	return nil, fmt.Errorf("no informer found for %v", resource)
}
318458
func (env *azureEnviron) StorageProviderTypes() ([]storage.ProviderType, error) {
	return []storage.ProviderType{azureStorageProviderType}, nil
}
698222
func ForResource(product manifold.Label, id manifold.ID) manifold.Label {
	idBytes := id[2:]

	offset := 0
	adj, offset := fetchWord(idBytes, data.Adjectives, offset, aShare)
	color, offset := fetchWord(idBytes, data.Colors, offset, cShare)
	shape, _ := fetchWord(idBytes, data.Shapes, offset, sShare)

	label := fmt.Sprintf("%s-%s-%s-%s", product, adj, color, shape)
	label = strings.ToLower(strings.Replace(label, " ", "-", -1))

	return manifold.Label(label)
}
1307069
func ParseProfiles(fileName string) ([]*Profile, error) {
	pf, err := os.Open(fileName)
	if err != nil {
		return nil, err
	}
	defer pf.Close()

	files := make(map[string]*Profile)
	buf := bufio.NewReader(pf)
	// First line is "mode: foo", where foo is "set", "count", or "atomic".
	// Rest of file is in the format
	//	encoding/base64/base64.go:34.44,37.40 3 1
	// where the fields are: name.go:line.column,line.column numberOfStatements count
	s := bufio.NewScanner(buf)
	mode := ""
	for s.Scan() {
		line := s.Text()
		if mode == "" {
			const p = "mode: "
			if !strings.HasPrefix(line, p) || line == p {
				return nil, fmt.Errorf("bad mode line: %v", line)
			}
			mode = line[len(p):]
			continue
		}
		m := lineRe.FindStringSubmatch(line)
		if m == nil {
			return nil, fmt.Errorf("line %q doesn't match expected format: %v", m, lineRe)
		}
		fn := m[1]
		p := files[fn]
		if p == nil {
			p = &Profile{
				FileName: fn,
				Mode:     mode,
			}
			files[fn] = p
		}
		p.Blocks = append(p.Blocks, ProfileBlock{
			StartLine: toInt(m[2]),
			StartCol:  toInt(m[3]),
			EndLine:   toInt(m[4]),
			EndCol:    toInt(m[5]),
			NumStmt:   toInt(m[6]),
			Count:     toInt(m[7]),
		})
	}
	if err := s.Err(); err != nil {
		return nil, err
	}
	for _, p := range files {
		sort.Sort(blocksByStart(p.Blocks))
		// Merge samples from the same location.
		j := 1
		for i := 1; i < len(p.Blocks); i++ {
			b := p.Blocks[i]
			last := p.Blocks[j-1]
			if b.StartLine == last.StartLine &&
				b.StartCol == last.StartCol &&
				b.EndLine == last.EndLine &&
				b.EndCol == last.EndCol {
				if b.NumStmt != last.NumStmt {
					return nil, fmt.Errorf("inconsistent NumStmt: changed from %d to %d", last.NumStmt, b.NumStmt)
				}
				if mode == "set" {
					p.Blocks[j-1].Count |= b.Count
				} else {
					p.Blocks[j-1].Count += b.Count
				}
				continue
			}
			p.Blocks[j] = b
			j++
		}
		p.Blocks = p.Blocks[:j]
	}
	// Generate a sorted slice.
	profiles := make([]*Profile, 0, len(files))
	for _, profile := range files {
		profiles = append(profiles, profile)
	}
	sort.Sort(byFileName(profiles))
	return profiles, nil
}
1142538
func (e Endpoints) PutProfile(ctx context.Context, id string, p Profile) error {
	request := putProfileRequest{ID: id, Profile: p}
	response, err := e.PutProfileEndpoint(ctx, request)
	if err != nil {
		return err
	}
	resp := response.(putProfileResponse)
	return resp.Err
}
67541
func (d *DeferredDiscoveryRESTMapper) ResourcesFor(input schema.GroupVersionResource) (gvrs []schema.GroupVersionResource, err error) {
	del, err := d.getDelegate()
	if err != nil {
		return nil, err
	}
	gvrs, err = del.ResourcesFor(input)
	if len(gvrs) == 0 && !d.cl.Fresh() {
		d.Reset()
		gvrs, err = d.ResourcesFor(input)
	}
	return
}
1233227
func startProfiling() (func(), error) {
	// start CPU profiling as early as possible
	ofi, err := os.Create(cpuProfile)
	if err != nil {
		return nil, err
	}
	err = pprof.StartCPUProfile(ofi)
	if err != nil {
		ofi.Close()
		return nil, err
	}
	go func() {
		for range time.NewTicker(time.Second * 30).C {
			err := writeHeapProfileToFile()
			if err != nil {
				log.Error(err)
			}
		}
	}()

	stopProfiling := func() {
		pprof.StopCPUProfile()
		ofi.Close() // captured by the closure
	}
	return stopProfiling, nil
}
894545
func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
	switch resource {
	// Group=example.apiserver.code-generator.k8s.io, Version=v1
	case v1.SchemeGroupVersion.WithResource("testtypes"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V1().TestTypes().Informer()}, nil

		// Group=example.test.apiserver.code-generator.k8s.io, Version=v1
	case example2v1.SchemeGroupVersion.WithResource("testtypes"):
		return &genericInformer{resource: resource.GroupResource(), informer: f.SecondExample().V1().TestTypes().Informer()}, nil

	}

	return nil, fmt.Errorf("no informer found for %v", resource)
}
887622
func ParseProcfile(b []byte) (Procfile, error) {
	p, err := parseStandardProcfile(b)
	if err != nil {
		p, err = parseExtendedProcfile(b)
	}
	return p, err
}