author | wenzelm |
Wed, 09 Nov 2022 19:42:21 +0100 | |
changeset 76492 | e228be7cd375 |
parent 75853 | f981111768ec |
child 76577 | c662a56e77a8 |
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 |
||
76492
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75853
diff
changeset
|
67 |
private val select_data = |
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75853
diff
changeset
|
68 |
new GUI.Selector(ML_Statistics.all_fields.map { case (a, _) => GUI.Selector.item(a) }) { |
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75853
diff
changeset
|
69 |
tooltip = "Select visualized data collection" |
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75853
diff
changeset
|
70 |
override def changed(): Unit = { data_name = selection.item.toString; update_chart() } |
e228be7cd375
clarified GUI.Selector, with support for separator as pseudo-entry;
wenzelm
parents:
75853
diff
changeset
|
71 |
} |
57869 | 72 |
|
72145 | 73 |
private val limit_data = new TextField("200", 5) { |
74 |
tooltip = "Limit for accumulated data" |
|
72147 | 75 |
verifier = { |
76 |
case Value.Int(x) => x > 0 |
|
77 |
case _ => false |
|
78 |
} |
|
72145 | 79 |
reactions += { case ValueChanged(_) => input_delay.invoke() } |
80 |
} |
|
81 |
||
75853 | 82 |
private val reset_data = new GUI.Button("Reset") { |
57869 | 83 |
tooltip = "Reset accumulated data" |
75853 | 84 |
override def clicked(): Unit = { clear_statistics(); update_chart() } |
57869 | 85 |
} |
86 |
||
75853 | 87 |
private val full_gc = new GUI.Button("GC") { |
72146 | 88 |
tooltip = "Full garbage collection of ML heap" |
75853 | 89 |
override def clicked(): Unit = PIDE.session.protocol_command("ML_Heap.full_gc") |
72146 | 90 |
} |
91 |
||
75853 | 92 |
private val share_common_data = new GUI.Button("Sharing") { |
72146 | 93 |
tooltip = "Share common data of ML heap" |
75853 | 94 |
override def clicked(): Unit = PIDE.session.protocol_command("ML_Heap.share_common_data") |
72146 | 95 |
} |
96 |
||
97 |
private val controls = |
|
98 |
Wrap_Panel(List(select_data, limit_data, reset_data, full_gc, share_common_data)) |
|
57869 | 99 |
|
100 |
||
101 |
/* layout */ |
|
102 |
||
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50433
diff
changeset
|
103 |
set_content(new ChartPanel(chart)) |
57869 | 104 |
add(controls.peer, BorderLayout.NORTH) |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
105 |
|
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
106 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
55618
diff
changeset
|
107 |
/* main */ |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
108 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
55618
diff
changeset
|
109 |
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
|
110 |
Session.Consumer[Session.Runtime_Statistics](getClass.getName) { |
72147 | 111 |
stats => |
61724
4bfcc09a33e8
limit statistics, to avoid exhaustion of heap space or GUI time;
wenzelm
parents:
61590
diff
changeset
|
112 |
add_statistics(stats.props) |
61751 | 113 |
update_delay.invoke() |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
55618
diff
changeset
|
114 |
} |
53177
dcac8d837b9c
more uniform treatment of Swing_Thread context switch: prefer asynchronous Swing_Thread.later from actor;
wenzelm
parents:
50982
diff
changeset
|
115 |
|
75393 | 116 |
override def init(): Unit = { |
71652 | 117 |
PIDE.session.runtime_statistics += main |
60074
38a64cc17403
GUI controls for ML_statistics, for more digestible protocol dump;
wenzelm
parents:
57869
diff
changeset
|
118 |
} |
38a64cc17403
GUI controls for ML_statistics, for more digestible protocol dump;
wenzelm
parents:
57869
diff
changeset
|
119 |
|
75393 | 120 |
override def exit(): Unit = { |
71652 | 121 |
PIDE.session.runtime_statistics -= main |
60074
38a64cc17403
GUI controls for ML_statistics, for more digestible protocol dump;
wenzelm
parents:
57869
diff
changeset
|
122 |
} |
50433
9131dadb2bf7
basic monitor panel, using the powerful jfreechart library;
wenzelm
parents:
diff
changeset
|
123 |
} |