Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
codemodify committed Feb 18, 2020
1 parent 8ce9cc1 commit 7084459
Show file tree
Hide file tree
Showing 26 changed files with 286 additions and 469 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

# ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~
**/*.log

# ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~
cli/helper-files/.vagrant
cli/helper-files/temp-*
**/temp*
**/.vagrant
cmd/cmd
File renamed without changes.
26 changes: 11 additions & 15 deletions cli/helper-files/build.sh → .helper-files/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ SUPPORTED_TARGETS=(
"linux,amd64"
"linux,arm"
"linux,arm64"

# "freebsd,amd64,true"
# "openbsd,amd64,true"
# "netbsd,amd64,true"
# "dragonfly,amd64"
# "plan9,amd64"
# "solaris,amd64"

# "darwin,amd64"
# "windows,amd64"
"freebsd,amd64,true"
"openbsd,amd64,true"
"netbsd,amd64,true"
"dragonfly,amd64"
"plan9,amd64"
"solaris,amd64"
"darwin,amd64"
"windows,amd64"
)

OUTPUTFOLDER=./temp-build
Expand All @@ -23,8 +21,6 @@ clear
echo ""
echo "Build PARAMS"
echo " -> OUTPUTFOLDER : ${OUTPUTFOLDER}"
echo " -> ENV : ${ENV}"
echo " -> VERSION : ${VERSION}"
echo ""


Expand All @@ -44,13 +40,13 @@ for target in "${SUPPORTED_TARGETS[@]}"; do
printf "Building %s" ${os}.${arch}
echo ""

fullOutputFilePath="$OUTPUTFOLDER/systemkit-platform-cli.${os}.${arch}${ext}"
GOOS=${os} GOARCH=${arch} go build -ldflags "${LDFLAGS}" -o ${fullOutputFilePath} ../
fullOutputFilePath="$OUTPUTFOLDER/systemkit-platform-cpu.${os}.${arch}${ext}"
GOOS=${os} GOARCH=${arch} go build -ldflags "${LDFLAGS}" -o ${fullOutputFilePath} ../cmd

done

echo ""

chmod +x $OUTPUTFOLDER/*



Expand Down
Binary file added .helper-files/dox/sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion 0-LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~
# @Authors : Nicolae Carabut
# @URLs : https://github.com/codemodify/systemkit-platform
# @URLs : https://github.com/codemodify/systemkit-platform-cpu
# @Contributors :
# ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~ ~~~~
#
Expand Down
42 changes: 17 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
# Detailed Platform Detection at Runtime
[![GoDoc](https://godoc.org/github.com/codemodify/SystemKit?status.svg)](https://godoc.org/github.com/codemodify/systemkit-platform)
[![0-License](https://img.shields.io/badge/license-0--license-brightgreen)](https://github.com/codemodify/TheFreeLicense)
[![Go Report Card](https://goreportcard.com/badge/github.com/codemodify/SystemKit)](https://goreportcard.com/report/github.com/codemodify/SystemKit)
[![Test Status](https://github.com/danawoodman/systemservice/workflows/Test/badge.svg)](https://github.com/danawoodman/systemservice/actions)
![code size](https://img.shields.io/github/languages/code-size/codemodify/SystemKit?style=flat-square)
# Detailed CPU Detection at Runtime

# Usages
- Intented use is as a library in Go code
# Usage
- as a library in Go code
```go
package main

import platform "github.com/codemodify/systemkit-platform"
import platformCPU "github.com/codemodify/systemkit-platform-cpu"

func main() {
cpuInfo := platformCPU.Info()

// Example 1
fmt.Println(platform.GetInfo().CPU.Architecture) // => ex: arm OR amd64
fmt.Println(platform.GetInfo().CPU.Variant.Name) // => ex: armv5 OR armv6 OR armv8, etc
fmt.Println(platform.GetInfo().CPU.Variant.Detailed) // => ex: armv5te
fmt.Println(cpuInfo.Architecture) // => ex: arm OR amd64
fmt.Println(cpuInfo.Variant.Name) // => ex: armv5 OR armv6 OR armv8, etc
fmt.Println(cpuInfo.Variant.Detailed) // => ex: armv5te

// Example 2
if platform.IsArm(platform.GetInfo().CPU.Architecture) {
if if platform.GetInfo().CPU.Variant.Name == platform.CPUV_ARMv8 {
if platformCPU.IsArm(cpuInfo.Architecture) {
if cpuInfo.Variant.Name == platformCPU.CPUV_ARMv8 {
// we got AMRv8
} else if platform.GetInfo().CPU.Variant.Name == platform.CPUV_ARMv5 {
if platform.GetInfo().CPU.Variant.Detailed == platform.CPUVD_ARMv5T {
} else if cpuInfo.Variant.Name == platformCPU.CPUV_ARMv5 {
if cpuInfo.Variant.Detailed == platformCPU.CPUVD_ARMv5T {
// we got ARMv5t
} else if platform.GetInfo().CPU.Variant.Detailed == platform.CPUVD_ARMv5TE {
} else if cpuInfo.Variant.Detailed == platformCPU.CPUVD_ARMv5TE {
// we got ARMv5te
} else if platform.GetInfo().CPU.Variant.Detailed == platform.CPUVD_ARMv5TEJ {
} else if cpuInfo.Variant.Detailed == platformCPU.CPUVD_ARMv5TEJ {
// we got ARMv5tej
}
}
}
}
```

-

# References
- `go tool dist list`
- https://github.com/golang/go/blob/master/src/go/build/syslist.go
- https://github.com/containerd/containerd
- https://github.com/mackerelio/go-osstat/blob/master/cpu/cpu_linux.go
- as a binary on a a bunch of platforms
- `https://github.com/codemodify/systemkit-platform-cpu/releases/latest`
![](https://raw.githubusercontent.com/codemodify/systemkit-platform-cpu/master/.helper-files/dox/sample.png)
8 changes: 5 additions & 3 deletions cli/main.go → cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import (
"fmt"
"os"

platform "github.com/codemodify/systemkit-platform"
platformCPU "github.com/codemodify/systemkit-platform-cpu"
)

func main() {
data, err := json.Marshal(platform.GetInfo())
cpuInfo := platformCPU.Info()

data, err := json.Marshal(cpuInfo)
if err != nil {
fmt.Println(err.Error())
}

if len(os.Args) > 1 && os.Args[1] == "-p" {
data, err = json.MarshalIndent(platform.GetInfo(), "", " ")
data, err = json.MarshalIndent(cpuInfo, "", " ")
if err != nil {
fmt.Println(err.Error())
}
Expand Down
101 changes: 0 additions & 101 deletions constants-cpu.go

This file was deleted.

43 changes: 0 additions & 43 deletions constants-os.go

This file was deleted.

44 changes: 18 additions & 26 deletions platform-linux.go → cpu-linux.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// +build linux
// +build !android
// +build !windows

package platform
package cpu

import (
"bufio"
Expand All @@ -15,8 +14,8 @@ import (
"strings"
)

// GetInfo -
func GetInfo() Platform {
// Info -
func Info() CPU {
count := fetchCPUInfo2("Socket(s):")
countAsInt, _ := strconv.Atoi(count)

Expand All @@ -26,29 +25,22 @@ func GetInfo() Platform {
threadsPerCoreCount := fetchCPUInfo2("Thread(s) per core:")
threadsPerCoreCountAsInt, _ := strconv.Atoi(threadsPerCoreCount)

return Platform{
OS: OS{
Name: getOS(),
Version: getKernelVersion(),
Features: []string{},
return CPU{
Count: countAsInt,
CoresPerCPU: coresPerCPUCountAsInt,
ThreadsPerCore: threadsPerCoreCountAsInt,
TotalThreads: runtime.NumCPU(),
Architecture: getCPUArchitecture(),
Variant: CPUVariant{
Name: getCPUVariant(),
Detailed: getCPUVariantDetailed(),
},
CPU: CPU{
Count: countAsInt,
CoresPerCPU: coresPerCPUCountAsInt,
ThreadsPerCore: threadsPerCoreCountAsInt,
TotalThreads: runtime.NumCPU(),
Architecture: getCPUArchitecture(),
Variant: CPUVariant{
Name: getCPUVariant(),
Detailed: getCPUVariantDetailed(),
},
Manufacturer: fetchCPUInfo2("Vendor ID:"),
ByteOrder: fetchCPUInfo2("Byte Order:"),
Features: []string{
fetchCPUInfo2("Flags:"),
},
Manufacturer: fetchCPUInfo2("Vendor ID:"),
ByteOrder: fetchCPUInfo2("Byte Order:"),
Features: []string{
fetchCPUInfo2("Flags:"),
},
Metadata: Metadata{
AdditionalInfo: AdditionalInfo{
"goos": runtime.GOOS,
"goarch": runtime.GOARCH,
"model name": fetchCPUInfo("model name"),
Expand Down
Loading

0 comments on commit 7084459

Please sign in to comment.