// /* -----------------------------Device Profile -----------------------------*/
962631
func (c *Client) GetDeviceProfileById(id string) (contract.DeviceProfile, error) {
	conn := c.Pool.Get()
	defer conn.Close()

	var d contract.DeviceProfile
	err := getObjectById(conn, id, unmarshalDeviceProfile, &d)
	return d, err
}
349678
func DeviceProximity(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "deviceproximity", Listener: listener}
}
826413
func (devices *DeviceSet) lookupDevice(hash string) (*devInfo, error) {
	info := devices.Devices[hash]
	if info == nil {
		info = devices.loadMetadata(hash)
		if info == nil {
			return nil, fmt.Errorf("devmapper: Unknown device %s", hash)
		}

		devices.Devices[hash] = info
	}
	return info, nil
}
655789
func (n *nvmlDriver) DeviceInfoAndStatusByIndex(index uint) (*DeviceInfo, *DeviceStatus, error) {
	return nil, nil, UnavailableLib
}
16544
func (r *SearchRequest) Profile(profile bool) *SearchRequest {
	r.searchSource = r.searchSource.Profile(profile)
	return r
}
3739
func (mc MongoClient) getDeviceProfiles(q bson.M) ([]contract.DeviceProfile, error) {
	s := mc.session.Copy()
	defer s.Close()

	var dps []models.DeviceProfile
	err := s.DB(mc.database.Name).C(db.DeviceProfile).Find(q).Sort("queryts").All(&dps)
	if err != nil {
		return []contract.DeviceProfile{}, errorMap(err)
	}

	cdps := make([]contract.DeviceProfile, 0)
	for _, dp := range dps {
		c, err := dp.ToContract(mc)
		if err != nil {
			return []contract.DeviceProfile{}, err
		}
		cdps = append(cdps, c)
	}
	return cdps, nil
}
1196378
func (s *SearchService) Profile(profile bool) *SearchService {
	s.searchSource = s.searchSource.Profile(profile)
	return s
}
157373
func (c *Charm) LXDProfile() lxdprofile.Profile {
	c.mu.Lock()
	defer c.mu.Unlock()
	return c.details.LXDProfile
}
1168359
func (_m *DBClient) UpdateDeviceProfile(dp models.DeviceProfile) error {
	ret := _m.Called(dp)

	var r0 error
	if rf, ok := ret.Get(0).(func(models.DeviceProfile) error); ok {
		r0 = rf(dp)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
1216245
func allActiveDeviceEKMetadata(mctx libkb.MetaContext, merkleRoot libkb.MerkleRoot) (metadata map[keybase1.DeviceID]keybase1.DeviceEkMetadata, err error) {
	defer mctx.TraceTimed("allActiveDeviceEKMetadata", func() error { return err })()

	maybeStale, err := allDeviceEKMetadataMaybeStale(mctx, merkleRoot)
	if err != nil {
		return nil, err
	}

	active := map[keybase1.DeviceID]keybase1.DeviceEkMetadata{}
	for deviceID, metadata := range maybeStale {
		// Check whether the key is stale. This isn't considered an error,
		// since the server doesn't do this check for us. We log these cases
		// and skip them.
		if ctimeIsStale(metadata.Ctime.Time(), merkleRoot) {
			mctx.Debug("skipping stale deviceEK %s for device KID %s", metadata.Kid, deviceID)
			continue
		}
		active[deviceID] = metadata
	}

	return active, nil
}
914254
func Profile(w http.ResponseWriter, r *http.Request) {
	sec, _ := strconv.ParseInt(r.FormValue("seconds"), 10, 64)
	if sec == 0 {
		sec = 30
	}

	// Set Content Type assuming StartCPUProfile will work,
	// because if it does it starts writing.
	w.Header().Set("Content-Type", "application/octet-stream")
	if err := pprof.StartCPUProfile(w); err != nil {
		// StartCPUProfile failed, so no writes yet.
		// Can change header back to text content
		// and send error code.
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprintf(w, "Could not enable CPU profiling: %s\n", err)
		return
	}
	sleep(w, time.Duration(sec)*time.Second)
	pprof.StopCPUProfile()
}
684317
func Profile(w http.ResponseWriter, r *http.Request) {
	sec, _ := strconv.ParseInt(r.FormValue("seconds"), 10, 64)
	if sec == 0 {
		sec = 30
	}

	if durationExceedsWriteTimeout(r, float64(sec)) {
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
		w.Header().Set("X-Go-Pprof", "1")
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprintln(w, "profile duration exceeds server's WriteTimeout")
		return
	}

	// Set Content Type assuming StartCPUProfile will work,
	// because if it does it starts writing.
	w.Header().Set("Content-Type", "application/octet-stream")
	if err := pprof.StartCPUProfile(w); err != nil {
		// StartCPUProfile failed, so no writes yet.
		// Can change header back to text content
		// and send error code.
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
		w.Header().Set("X-Go-Pprof", "1")
		w.WriteHeader(http.StatusInternalServerError)
		fmt.Fprintf(w, "Could not enable CPU profiling: %s\n", err)
		return
	}
	sleep(w, time.Duration(sec)*time.Second)
	pprof.StopCPUProfile()
}
1215395
func (c *UsersProfileSetCall) Profile(profile *objects.UserProfile) *UsersProfileSetCall {
	c.profile = profile
	return c
}
1189775
func (n *NetworkServerAPI) CreateDeviceProfile(ctx context.Context, req *ns.CreateDeviceProfileRequest) (*ns.CreateDeviceProfileResponse, error) {
	if req.DeviceProfile == nil {
		return nil, grpc.Errorf(codes.InvalidArgument, "device_profile must not be nil")
	}

	var dpID uuid.UUID
	copy(dpID[:], req.DeviceProfile.Id)

	var factoryPresetFreqs []int
	for _, f := range req.DeviceProfile.FactoryPresetFreqs {
		factoryPresetFreqs = append(factoryPresetFreqs, int(f))
	}

	dp := storage.DeviceProfile{
		ID:                 dpID,
		SupportsClassB:     req.DeviceProfile.SupportsClassB,
		ClassBTimeout:      int(req.DeviceProfile.ClassBTimeout),
		PingSlotPeriod:     int(req.DeviceProfile.PingSlotPeriod),
		PingSlotDR:         int(req.DeviceProfile.PingSlotDr),
		PingSlotFreq:       int(req.DeviceProfile.PingSlotFreq),
		SupportsClassC:     req.DeviceProfile.SupportsClassC,
		ClassCTimeout:      int(req.DeviceProfile.ClassCTimeout),
		MACVersion:         req.DeviceProfile.MacVersion,
		RegParamsRevision:  req.DeviceProfile.RegParamsRevision,
		RXDelay1:           int(req.DeviceProfile.RxDelay_1),
		RXDROffset1:        int(req.DeviceProfile.RxDrOffset_1),
		RXDataRate2:        int(req.DeviceProfile.RxDatarate_2),
		RXFreq2:            int(req.DeviceProfile.RxFreq_2),
		FactoryPresetFreqs: factoryPresetFreqs,
		MaxEIRP:            int(req.DeviceProfile.MaxEirp),
		MaxDutyCycle:       int(req.DeviceProfile.MaxDutyCycle),
		SupportsJoin:       req.DeviceProfile.SupportsJoin,
		Supports32bitFCnt:  req.DeviceProfile.Supports_32BitFCnt,
		RFRegion:           band.Band().Name(),
	}

	if err := storage.CreateDeviceProfile(storage.DB(), &dp); err != nil {
		return nil, errToRPCError(err)
	}

	return &ns.CreateDeviceProfileResponse{
		Id: dp.ID.Bytes(),
	}, nil
}
46778
func CreateDeviceProfile(db sqlx.Execer, dp *DeviceProfile) error {
	now := time.Now()

	if dp.ID == uuid.Nil {
		var err error
		dp.ID, err = uuid.NewV4()
		if err != nil {
			return errors.Wrap(err, "new uuid v4 error")
		}
	}

	dp.CreatedAt = now
	dp.UpdatedAt = now

	_, err := db.Exec(`
        insert into device_profile (
            created_at,
            updated_at,

            device_profile_id,
            supports_class_b,
            class_b_timeout,
            ping_slot_period,
            ping_slot_dr,
            ping_slot_freq,
            supports_class_c,
            class_c_timeout,
            mac_version,
            reg_params_revision,
            rx_delay_1,
            rx_dr_offset_1,
            rx_data_rate_2,
            rx_freq_2,
            factory_preset_freqs,
            max_eirp,
            max_duty_cycle,
            supports_join,
            rf_region,
            supports_32bit_fcnt
        ) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)`,
		dp.CreatedAt,
		dp.UpdatedAt,
		dp.ID,
		dp.SupportsClassB,
		dp.ClassBTimeout,
		dp.PingSlotPeriod,
		dp.PingSlotDR,
		dp.PingSlotFreq,
		dp.SupportsClassC,
		dp.ClassCTimeout,
		dp.MACVersion,
		dp.RegParamsRevision,
		dp.RXDelay1,
		dp.RXDROffset1,
		dp.RXDataRate2,
		dp.RXFreq2,
		pq.Array(dp.FactoryPresetFreqs),
		dp.MaxEIRP,
		dp.MaxDutyCycle,
		dp.SupportsJoin,
		dp.RFRegion,
		dp.Supports32bitFCnt,
	)
	if err != nil {
		return handlePSQLError(err, "insert error")
	}

	log.WithFields(log.Fields{
		"id": dp.ID,
	}).Info("device-profile created")

	return nil
}
785856
func (_m *DBClient) GetDevicesByProfileId(pid string) ([]models.Device, error) {
	ret := _m.Called(pid)

	var r0 []models.Device
	if rf, ok := ret.Get(0).(func(string) []models.Device); ok {
		r0 = rf(pid)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]models.Device)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string) error); ok {
		r1 = rf(pid)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
159078
func (_m *DBClient) GetDeviceProfileByName(n string) (models.DeviceProfile, error) {
	ret := _m.Called(n)

	var r0 models.DeviceProfile
	if rf, ok := ret.Get(0).(func(string) models.DeviceProfile); ok {
		r0 = rf(n)
	} else {
		r0 = ret.Get(0).(models.DeviceProfile)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(string) error); ok {
		r1 = rf(n)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}