31825
|
1 |
/* Title: Pure/System/platform.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
69112
|
4 |
System platform identification.
|
31825
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
31828
|
9 |
|
31825
|
10 |
object Platform
|
|
11 |
{
|
69112
|
12 |
/* platform family */
|
31828
|
13 |
|
71383
|
14 |
val is_linux: Boolean = System.getProperty("os.name", "") == "Linux"
|
|
15 |
val is_macos: Boolean = System.getProperty("os.name", "") == "Mac OS X"
|
|
16 |
val is_windows: Boolean = System.getProperty("os.name", "").startsWith("Windows")
|
31825
|
17 |
|
69410
|
18 |
def family: Family.Value =
|
|
19 |
if (is_linux) Family.linux
|
|
20 |
else if (is_macos) Family.macos
|
|
21 |
else if (is_windows) Family.windows
|
|
22 |
else error("Failed to determine current platform family")
|
|
23 |
|
|
24 |
object Family extends Enumeration
|
|
25 |
{
|
|
26 |
val linux, macos, windows = Value
|
|
27 |
|
|
28 |
def unapply(name: String): Option[Value] =
|
|
29 |
try { Some(withName(name)) }
|
|
30 |
catch { case _: NoSuchElementException => None }
|
|
31 |
|
|
32 |
def parse(name: String): Value =
|
|
33 |
unapply(name) getOrElse error("Bad platform family: " + quote(name))
|
|
34 |
}
|
|
35 |
|
31828
|
36 |
|
69112
|
37 |
/* platform identifiers */
|
31828
|
38 |
|
69112
|
39 |
private val X86 = """i.86|x86""".r
|
|
40 |
private val X86_64 = """amd64|x86_64""".r
|
31825
|
41 |
|
69726
|
42 |
def cpu_arch: String =
|
|
43 |
System.getProperty("os.arch", "") match {
|
|
44 |
case X86() => "x86"
|
|
45 |
case X86_64() => "x86_64"
|
|
46 |
case _ => error("Failed to determine CPU architecture")
|
|
47 |
}
|
|
48 |
|
|
49 |
def os_name: String =
|
|
50 |
family match {
|
|
51 |
case Family.macos => "darwin"
|
|
52 |
case _ => family.toString
|
|
53 |
}
|
|
54 |
|
|
55 |
lazy val jvm_platform: String = cpu_arch + "-" + os_name
|
31828
|
56 |
|
|
57 |
|
61001
|
58 |
/* JVM version */
|
|
59 |
|
69112
|
60 |
private val Version = """1\.(\d+)\.0_(\d+)""".r
|
71383
|
61 |
lazy val jvm_version: String =
|
61001
|
62 |
System.getProperty("java.version") match {
|
|
63 |
case Version(a, b) => a + "u" + b
|
|
64 |
case a => a
|
|
65 |
}
|
|
66 |
|
|
67 |
|
41381
|
68 |
/* JVM name */
|
|
69 |
|
53582
|
70 |
val jvm_name: String = System.getProperty("java.vm.name", "")
|
72149
|
71 |
|
|
72 |
|
|
73 |
/* JVM statistics */
|
|
74 |
|
|
75 |
def jvm_statistics(): Properties.T =
|
|
76 |
{
|
|
77 |
val heap_size = Runtime.getRuntime.totalMemory()
|
|
78 |
val heap_used = heap_size - Runtime.getRuntime.freeMemory()
|
|
79 |
|
|
80 |
val threads = Thread.activeCount()
|
|
81 |
val workers = Isabelle_Thread.pool.getPoolSize
|
|
82 |
val workers_active = Isabelle_Thread.pool.getActiveCount
|
|
83 |
|
|
84 |
List(
|
|
85 |
"java_heap_size" -> heap_size.toString,
|
|
86 |
"java_heap_used" -> heap_used.toString,
|
|
87 |
"java_threads_total" -> threads.toString,
|
|
88 |
"java_workers_total" -> workers.toString,
|
|
89 |
"java_workers_active" -> workers_active.toString)
|
|
90 |
}
|
31825
|
91 |
}
|