// Serialize cpux.CPUs as JSON using package globals.
491172
func Serialize(cpus *x.CPUs) (p []byte, err error) {
	stdMu.Lock()
	defer stdMu.Unlock()
	if std == nil {
		std = NewProfiler()
	}
	return std.Serialize(cpus)
}
1199549
func (p *Profiler) SerializeCPU(cpu *freq.CPU) fb.UOffsetT {
	structs.CPUStart(p.Builder)
	structs.CPUAddProcessor(p.Builder, cpu.Processor)
	structs.CPUAddCPUMHz(p.Builder, cpu.CPUMHz)
	structs.CPUAddPhysicalID(p.Builder, cpu.PhysicalID)
	structs.CPUAddCoreID(p.Builder, cpu.CoreID)
	structs.CPUAddAPICID(p.Builder, cpu.APICID)
	return structs.CPUEnd(p.Builder)
}
750684
func (prof *Profiler) Serialize(inf *structs.DevInfo) ([]byte, error) {
	return json.Marshal(inf)
}
439013
func GetCPU() (info *CPU, err error) {
	info = &CPU{}

	// get physical cpu stats
	var cpus []cpu.InfoStat
	if cpus, err = cpuInfo(); err != nil {
		return info, err
	}

	info.HostPhysicalCPUs = len(cpus)

	// get logical cpu stats
	if info.HostLogicalCPUs, err = cpuCounts(true); err != nil {
		return info, err
	}

	// total number of cpu cores
	for _, cpu := range cpus {
		info.HostCPUCores += int64(cpu.Cores)
		// TODO: This is not ideal... if there are different processors
		// we will only report one of the models... This is unlikely to happen,
		// but it could
		info.HostCPUModel = cpu.ModelName
	}

	err = fillPlatformSpecificCPUData(info)
	return info, err
}
1005084
func (s CPUSet) ToSlice() []int {
	result := []int{}
	for cpu := range s.elems {
		result = append(result, cpu)
	}
	sort.Ints(result)
	return result
}
1134148
func (f *File) Serialize(w io.Writer) error {
	_, err := iotools.WriteTracker(w, func(w io.Writer) error {
		needsNLs := 0
		maybeAddNL := func() {
			if needsNLs > 0 {
				w.Write(bytes.Repeat([]byte("\n"), needsNLs))
				needsNLs = 0
			}
		}

		if f.ServiceURL != "" {
			maybeAddNL()
			fmt.Fprintf(w, "$ServiceURL %s", f.ServiceURL)
			needsNLs = 1
		}
		if f.ParanoidMode != "" && f.ParanoidMode != deployer.NotParanoid {
			maybeAddNL()
			fmt.Fprintf(w, "$ParanoidMode %s", f.ParanoidMode)
			needsNLs = 1
		}
		if f.ResolvedVersions != "" {
			maybeAddNL()
			fmt.Fprintf(w, "$ResolvedVersions %s", f.ResolvedVersions)
			needsNLs = 1
		}

		if needsNLs != 0 {
			needsNLs += 1 // new line separator if any of $Directives were used
		}

		if len(f.VerifyPlatforms) > 0 {
			for _, plat := range f.VerifyPlatforms {
				maybeAddNL()

				fmt.Fprintf(w, "$VerifiedPlatform %s", plat.String())
				needsNLs = 1
			}

			needsNLs = 2
		}

		keys := make(sort.StringSlice, 0, len(f.PackagesBySubdir))
		for k := range f.PackagesBySubdir {
			keys = append(keys, k)
		}
		keys.Sort()

		for _, k := range keys {
			maybeAddNL()
			if k != "" {
				fmt.Fprintf(w, "@Subdir %s", k)
				needsNLs = 1
			}

			pkgs := f.PackagesBySubdir[k]
			pkgsSort := make(PackageSlice, len(pkgs))
			maxLength := 0
			for i, pkg := range pkgs {
				pkgsSort[i] = pkg
				if l := len(pkg.PackageTemplate); l > maxLength {
					maxLength = l
				}
			}
			sort.Sort(pkgsSort)

			for _, p := range pkgsSort {
				maybeAddNL()
				fmt.Fprintf(w, "%-*s %s", maxLength+1, p.PackageTemplate, p.UnresolvedVersion)
				needsNLs = 1
			}
			needsNLs++
		}

		// We only ever want to end the file with 1 newline.
		if needsNLs > 0 {
			needsNLs = 1
		}
		maybeAddNL()
		return nil
	})
	return err
}
644882
func (b *BaseKvdb) SerializeAll(kvps kvdb.KVPairs) ([]byte, error) {
	out, err := json.Marshal(kvps)
	if err != nil {
		return nil, err
	}
	return out, nil
}
222448
func (c cpuInfo) tsx() bool {
	return c.features&(mpx|rtm) == mpx|rtm
}
429402
func (d CPUDetails) Sockets() cpuset.CPUSet {
	b := cpuset.NewBuilder()
	for _, info := range d {
		b.Add(info.SocketID)
	}
	return b.Result()
}
370974
func (p *Profiler) SerializeCPU(cpu *cpux.CPU) fb.UOffsetT {
	uoffs := make([]fb.UOffsetT, len(cpu.CacheIDs))
	// serialize cache info in order; the flatbuffer table will have the info
	// in order so a separate cache ID list isn't necessary for flatbuffers.
	for i, id := range cpu.CacheIDs {
		// If the ID doesn't exist, the 0 value will be used
		inf := cpu.Cache[id]
		uoffs[i] = p.SerializeCache(id, inf)
	}
	structs.CPUStartCacheVector(p.Builder, len(uoffs))
	for i := len(uoffs) - 1; i >= 0; i-- {
		p.Builder.PrependUOffsetT(uoffs[i])
	}
	cache := p.Builder.EndVector(len(uoffs))

	structs.CPUStart(p.Builder)
	structs.CPUAddPhysicalPackageID(p.Builder, cpu.PhysicalPackageID)
	structs.CPUAddCoreID(p.Builder, cpu.CoreID)
	structs.CPUAddMHzMin(p.Builder, cpu.MHzMin)
	structs.CPUAddMHzMax(p.Builder, cpu.MHzMax)
	structs.CPUAddCache(p.Builder, cache)
	return structs.CPUEnd(p.Builder)
}
1027588
func (b *AnnealingEpsilonGreedy) Serialize() interface{} {
	data := make(map[string]interface{})
	data["strategy"] = "annealing epsilon greedy"
	data["epsilon"] = b.Epsilon()
	data["counts"] = b.counts
	data["values"] = b.values
	return data
}
533615
func Deserialize(p []byte) (*procs.Processors, error) {
	proc := &procs.Processors{}
	err := json.Unmarshal(p, proc)
	if err != nil {
		return nil, err
	}
	return proc, nil
}
1065192
func (s CPUSet) Clone() CPUSet {
	b := NewBuilder()
	for elem := range s.elems {
		b.Add(elem)
	}
	return b.Result()
}
87881
func (s *Stat) CPUStats() *CPUStats {
	s.Lock()
	defer s.Unlock()

	var cpu *CPUStats
	do(func() {

		cpup := C.sg_get_cpu_percents_of(C.sg_new_diff_cpu_percent, nil)

		loadStat := C.sg_get_load_stats(nil)

		cpu = &CPUStats{
			User:      float64(cpup.user),
			Kernel:    float64(cpup.kernel),
			Idle:      float64(cpup.idle),
			IOWait:    float64(cpup.iowait),
			Swap:      float64(cpup.swap),
			Nice:      float64(cpup.nice),
			LoadMin1:  float64(loadStat.min1),
			LoadMin5:  float64(loadStat.min5),
			LoadMin15: float64(loadStat.min15),
			Period:    time.Duration(int(cpup.time_taken)) * time.Second,
			TimeTaken: time.Now(),
		}
	})
	return cpu
}
444929
func (b *NexthopUpdateBody) Serialize(version uint8) ([]byte, error) {
	// Address Family (2 bytes)
	buf := make([]byte, 3)
	binary.BigEndian.PutUint16(buf, uint16(b.Prefix.Family))
	addrByteLen, err := addressByteLength(b.Prefix.Family)
	if err != nil {
		return nil, err
	}

	buf[2] = byte(addrByteLen * 8)
	// Prefix Length (1 byte) + Prefix (variable)
	switch b.Prefix.Family {
	case syscall.AF_INET:
		buf = append(buf, b.Prefix.Prefix.To4()...)
	case syscall.AF_INET6:
		buf = append(buf, b.Prefix.Prefix.To16()...)
	default:
		return nil, fmt.Errorf("invalid address family: %d", b.Prefix.Family)
	}
	if version >= 5 {
		// Type (1 byte) (if version>=5)
		// Instance (2 bytes) (if version>=5)
		buf = append(buf, byte(b.Type))
		bbuf := make([]byte, 2)
		binary.BigEndian.PutUint16(bbuf, b.Instance)
		buf = append(buf, bbuf...)
	}
	if version >= 4 {
		// Distance (1 byte) (if version>=4)
		buf = append(buf, b.Distance)
	}
	// Metric (4 bytes)
	bbuf := make([]byte, 4)
	binary.BigEndian.PutUint32(bbuf, b.Metric)
	buf = append(buf, bbuf...)
	// Number of Nexthops (1 byte)
	buf = append(buf, uint8(0)) // Temporary code
	// ToDo Processing Route Entry

	return buf, nil
}
324769
func Deserialize(p []byte) (*stats.CPUStats, error) {
	st := &stats.CPUStats{}
	err := json.Unmarshal(p, st)
	if err != nil {
		return nil, err
	}
	return st, nil
}
1334596
func (n *DebugCapture) DumpJSON(data []byte, cpuPrefix string) {
	resp, err := n.getJSON(data, cpuPrefix)
	if err != nil {
		fmt.Println(fmt.Sprintf(`{"type":"debug_capture_error","message":%q}`, err.Error()))
		return
	}
	fmt.Println(resp)
}