2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.listener;
20 import gov.nasa.jpf.Config;
21 import gov.nasa.jpf.JPF;
22 import gov.nasa.jpf.ListenerAdapter;
23 import gov.nasa.jpf.search.Search;
25 import java.io.PrintWriter;
28 * simple tool to log state changes
30 public class StateTracker extends ListenerAdapter {
32 private final PrintWriter out;
33 private final int logPeriod;
34 volatile private String operation;
35 volatile private String detail;
36 volatile private int depth;
37 volatile private int id;
39 public StateTracker (Config conf, JPF jpf) {
40 out = new PrintWriter(System.out, true);
41 logPeriod = conf.getInt("jpf.state_tracker.log_period", 0);
42 Runnable task = new Runnable() {@Override
43 public void run() {logger();}};
44 Thread thread = new Thread(task);
45 thread.setDaemon(true);
46 thread.setName("StateTracker Logger");
50 private void logger() {
51 StringBuilder buffer = new StringBuilder();
53 buffer.append("----------------------------------- [");
54 int len = buffer.length();
58 Thread.sleep(logPeriod);
59 } catch (InterruptedException e) {
65 buffer.append(operation);
71 buffer.append(detail);
74 out.println(buffer.toString());
76 buffer.setLength(len);
81 public void stateRestored(Search search) {
82 id = search.getStateId();
83 depth = search.getDepth();
84 operation = "restored";
88 //--- the ones we are interested in
90 public void searchStarted(Search search) {
91 out.println("----------------------------------- search started");
95 public void stateAdvanced(Search search) {
96 id = search.getStateId();
97 depth = search.getDepth();
98 operation = "forward";
99 if (search.isNewState()) {
105 if (search.isEndState()) {
111 public void stateBacktracked(Search search) {
112 id = search.getStateId();
113 depth = search.getDepth();
114 operation = "backtrack";
119 public void searchFinished(Search search) {
120 out.println("----------------------------------- search finished");