support for monitoring of external ML process;
authorwenzelm
Wed, 15 Jul 2020 12:04:48 +0200
changeset 72035 25d5ef16401a
parent 72034 452073b64f28
child 72036 e48a5b6b7554
support for monitoring of external ML process;
src/Pure/ML/ml_statistics.scala
--- a/src/Pure/ML/ml_statistics.scala	Wed Jul 15 11:56:43 2020 +0200
+++ b/src/Pure/ML/ml_statistics.scala	Wed Jul 15 12:04:48 2020 +0200
@@ -25,6 +25,31 @@
   def now(props: Properties.T): Double = Now.unapply(props).get
 
 
+  /* monitor process */
+
+  def monitor(pid: Long,
+    delay: Time = Time.seconds(0.5),
+    consume: Properties.T => Unit = Console.println)
+  {
+    def progress_stdout(line: String)
+    {
+      val props =
+        Library.space_explode(',', line).flatMap((entry: String) =>
+          Library.space_explode('=', entry) match {
+            case List(a, b) => Some((a, b))
+            case _ => None
+          })
+      if (props.nonEmpty) consume(props)
+    }
+
+    Bash.process("exec \"$POLYML_EXE\" -q --use " +
+      File.bash_path(Path.explode("~~/src/Pure/ML/ml_statistics.ML")) +
+      " --eval " + Bash.string("ML_Statistics.monitor " + ML_Syntax.print_long(pid) + " " +
+          ML_Syntax.print_double(delay.seconds)))
+      .result(progress_stdout = progress_stdout, strict = false).check
+  }
+
+
   /* memory fields (mega bytes) */
 
   def mem_print(x: Long): Option[String] =