Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a custom value "os.arch" of System.getProperty("os.arch") #57

Open
yogurtearl opened this issue Jun 1, 2022 · 1 comment
Open

Comments

@yogurtearl
Copy link

Add a custom value "os.arch" of System.getProperty("os.arch")

Something like:

        buildScan.value("os.arch", providers.systemProperty("os.arch").get())

This will help compare build times from Intel machines, compared to ARM based machines.
Also, will help see if certain failures are more common on one or the other.

@trevjonez
Copy link

It's not too bad to do the full cpu part. Can be nice to have when you want to try to advocate for hardware upgrades with specific arguments. Gatta isolate all those variables.

    fun GradleEnterpriseExtension.cpuTag() {
        val os = System.getProperty("os.name")
        buildScan.background {
            val tagValue = when {
                os.contains("Mac", ignoreCase = true) ->
                    execAndGetStdout("sysctl", "-a")?.let {
                        findMacCpuPart(it.split("\n"))
                    }

                os.contains("Linux", ignoreCase = true) ->
                    findLinuxCpuPart(File("/proc/cpuinfo").readLines())

                os.contains("Windows", ignoreCase = true) ->
                    execAndGetStdout("wmic", "cpu", "get", "name")?.let {
                        findWindowsCpuPart(it.split("\n"))
                    }

                else -> null
            }
            value("Cpu", tagValue?.takeIf { it.isNotBlank() } ?: "Unknown CPU")
        }
    }

    fun findMacCpuPart(sysctl: List<String>): String? =
        sysctl.find { it.startsWith("machdep.cpu.brand_string") }
            ?.removePrefix("machdep.cpu.brand_string: ")

    fun findLinuxCpuPart(cpuinfo: List<String>): String? =
        cpuinfo.find { it.contains("model name") }?.split(":")?.last()?.trim()

    fun findWindowsCpuPart(wmic: List<String>): String =
        wmic.last { it.isNotBlank() }

Not the most elegant looking thing, but it's worked pretty well for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants