author | wenzelm |
Sat, 13 Aug 2022 23:04:53 +0200 | |
changeset 75853 | f981111768ec |
parent 75839 | 29441f2bfe81 |
child 76492 | e228be7cd375 |
permissions | -rw-r--r-- |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/monitor_dockable.scala |
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
3 |
|
72147 | 4 |
Monitor for runtime statistics. |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
6 |
|
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle.jedit |
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
8 |
|
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
9 |
|
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
10 |
import isabelle._ |
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
11 |
|
57869 | 12 |
import java.awt.BorderLayout |
13 |
||
61724
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
14 |
import scala.collection.immutable.Queue |
75853 | 15 |
import scala.swing.TextField |
16 |
import scala.swing.event.ValueChanged |
|
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
17 |
|
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50433
diff
changeset
|
18 |
import org.jfree.chart.ChartPanel |
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50433
diff
changeset
|
19 |
import org.jfree.data.xy.XYSeriesCollection |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
20 |
|
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
21 |
import org.gjt.sp.jedit.View |
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
22 |
|
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
23 |
|
75393 | 24 |
class Monitor_Dockable(view: View, position: String) extends Dockable(view, position) { |
61724
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
25 |
/* chart data -- owned by GUI thread */ |
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
26 |
|
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
27 |
private var statistics = Queue.empty[Properties.T] |
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
28 |
private var statistics_length = 0 |
56770
e160ae47db94
mane delayed events outside of Swing thread -- triggers no longer require Swing_Thread.later;
wenzelm
parents:
56715
diff
changeset
|
29 |
|
75393 | 30 |
private def add_statistics(stats: Properties.T): Unit = { |
75447 | 31 |
statistics = statistics.appended(stats) |
61724
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
32 |
statistics_length += 1 |
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
33 |
limit_data.text match { |
63805 | 34 |
case Value.Int(limit) => |
61724
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
35 |
while (statistics_length > limit) { |
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
36 |
statistics = statistics.dequeue._2 |
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
37 |
statistics_length -= 1 |
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
38 |
} |
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
39 |
case _ => |
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
40 |
} |
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
41 |
} |
75393 | 42 |
private def clear_statistics(): Unit = { |
61724
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
43 |
statistics = Queue.empty |
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
44 |
statistics_length = 0 |
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
45 |
} |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
46 |
|
72147 | 47 |
private var data_name = ML_Statistics.all_fields.head._1 |
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50433
diff
changeset
|
48 |
private val chart = ML_Statistics.empty.chart(null, Nil) |
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50433
diff
changeset
|
49 |
private val data = chart.getXYPlot.getDataset.asInstanceOf[XYSeriesCollection] |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
50 |
|
75393 | 51 |
private def update_chart(): Unit = { |
65053 | 52 |
ML_Statistics.all_fields.find(_._1 == data_name) match { |
57869 | 53 |
case None => |
65851 | 54 |
case Some((_, fields)) => ML_Statistics(statistics.toList).update_data(data, fields) |
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50433
diff
changeset
|
55 |
} |
72147 | 56 |
} |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
57 |
|
61751 | 58 |
private val input_delay = |
72147 | 59 |
Delay.first(PIDE.options.seconds("editor_input_delay"), gui = true) { update_chart() } |
61751 | 60 |
|
61 |
private val update_delay = |
|
72147 | 62 |
Delay.first(PIDE.options.seconds("editor_chart_delay"), gui = true) { update_chart() } |
57869 | 63 |
|
64 |
||
65 |
/* controls */ |
|
66 |
||
75839 | 67 |
private val select_data = new GUI.Selector[String](ML_Statistics.all_fields.map(_._1)) { |
57869 | 68 |
tooltip = "Select visualized data collection" |
75839 | 69 |
override def changed(): Unit = { data_name = selection.item; update_chart() } |
57869 | 70 |
} |
71 |
||
72145 | 72 |
private val limit_data = new TextField("200", 5) { |
73 |
tooltip = "Limit for accumulated data" |
|
72147 | 74 |
verifier = { |
75 |
case Value.Int(x) => x > 0 |
|
76 |
case _ => false |
|
77 |
} |
|
72145 | 78 |
reactions += { case ValueChanged(_) => input_delay.invoke() } |
79 |
} |
|
80 |
||
75853 | 81 |
private val reset_data = new GUI.Button("Reset") { |
57869 | 82 |
tooltip = "Reset accumulated data" |
75853 | 83 |
override def clicked(): Unit = { clear_statistics(); update_chart() } |
57869 | 84 |
} |
85 |
||
75853 | 86 |
private val full_gc = new GUI.Button("GC") { |
72146 | 87 |
tooltip = "Full garbage collection of ML heap" |
75853 | 88 |
override def clicked(): Unit = PIDE.session.protocol_command("ML_Heap.full_gc") |
72146 | 89 |
} |
90 |
||
75853 | 91 |
private val share_common_data = new GUI.Button("Sharing") { |
72146 | 92 |
tooltip = "Share common data of ML heap" |
75853 | 93 |
override def clicked(): Unit = PIDE.session.protocol_command("ML_Heap.share_common_data") |
72146 | 94 |
} |
95 |
||
96 |
private val controls = |
|
97 |
Wrap_Panel(List(select_data, limit_data, reset_data, full_gc, share_common_data)) |
|
57869 | 98 |
|
99 |
||
100 |
/* layout */ |
|
101 |
||
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50433
diff
changeset
|
102 |
set_content(new ChartPanel(chart)) |
57869 | 103 |
add(controls.peer, BorderLayout.NORTH) |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
104 |
|
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
105 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
55618
diff
changeset
|
106 |
/* main */ |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
107 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
55618
diff
changeset
|
108 |
private val main = |
72135
f67e83608745
removed pointless GUI controls for ML_statistics --- no longer part of prover protocol (see also 38a64cc17403);
wenzelm
parents:
71704
diff
changeset
|
109 |
Session.Consumer[Session.Runtime_Statistics](getClass.getName) { |
72147 | 110 |
stats => |
61724
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
111 |
add_statistics(stats.props) |
61751 | 112 |
update_delay.invoke() |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
55618
diff
changeset
|
113 |
} |
53177
dcac8d837b9c
more uniform treatment of Swing_Thread context switch: prefer asynchronous Swing_Thread.later from actor;
wenzelm
parents:
50982
diff
changeset
|
114 |
|
75393 | 115 |
override def init(): Unit = { |
71652 | 116 |
PIDE.session.runtime_statistics += main |
60074
38a64cc17403
GUI controls for ML_statistics, for more digestible protocol dump;
wenzelm
parents:
57869
diff
changeset
|
117 |
} |
38a64cc17403
GUI controls for ML_statistics, for more digestible protocol dump;
wenzelm
parents:
57869
diff
changeset
|
118 |
|
75393 | 119 |
override def exit(): Unit = { |
71652 | 120 |
PIDE.session.runtime_statistics -= main |
60074
38a64cc17403
GUI controls for ML_statistics, for more digestible protocol dump;
wenzelm
parents:
57869
diff
changeset
|
121 |
} |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
122 |
} |