ede7014b0efd63f4712ee9974e76237bb087dfd2
[deliverable/tracecompass.git] / statesystem / org.eclipse.tracecompass.statesystem.core.tests / stubs / org / eclipse / tracecompass / statesystem / core / tests / stubs / backend / HistoryTreeBackendStub.java
1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.statesystem.core.tests.stubs.backend;
11
12 import java.io.File;
13 import java.io.IOException;
14 import java.io.PrintWriter;
15
16 import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HTConfig;
17 import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HistoryTreeBackend;
18 import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.IHistoryTree;
19
20 /**
21 * Stub class for the {@link HistoryTreeBackend}. It creates a
22 * {@link HistoryTreeClassicStub} to grant access to some protected methods.
23 *
24 * @author Geneviève Bastien
25 */
26 public class HistoryTreeBackendStub extends HistoryTreeBackend {
27
28 private static HistoryTreeType HT_TYPE = HistoryTreeType.CLASSIC;
29
30 /**
31 * Sets the type of tree to build. Since the history tree is initialized in
32 * the parent's constructor, this stub class needs to know the type of tree
33 * to build.
34 *
35 * @param htType
36 * The type of history tree to build for this backend
37 */
38 public static void setTreeType(HistoryTreeType htType) {
39 HT_TYPE = htType;
40 }
41
42 /**
43 * Enumeration of all history tree types implemented. This will be used to
44 * create the right type of history tree
45 */
46 public enum HistoryTreeType {
47 /**
48 * The classic history tree
49 */
50 CLASSIC
51 }
52
53 /**
54 * Constructor for new history files. Use this when creating a new history
55 * from scratch.
56 *
57 * @param ssid
58 * The state system's ID
59 * @param newStateFile
60 * The filename/location where to store the state history (Should
61 * end in .ht)
62 * @param providerVersion
63 * Version of of the state provider. We will only try to reopen
64 * existing files if this version matches the one in the
65 * framework.
66 * @param startTime
67 * The earliest time stamp that will be stored in the history
68 * @param blockSize
69 * The size of the blocks in the history file. This should be a
70 * multiple of 4096.
71 * @param maxChildren
72 * The maximum number of children each core node can have
73 * @throws IOException
74 * Thrown if we can't create the file for some reason
75 */
76 public HistoryTreeBackendStub(String ssid,
77 File newStateFile,
78 int providerVersion,
79 long startTime,
80 int blockSize,
81 int maxChildren) throws IOException {
82 super(ssid, newStateFile, providerVersion, startTime, blockSize, maxChildren);
83 }
84
85 /**
86 * Existing history constructor. Use this to open an existing state-file.
87 *
88 * @param ssid
89 * The state system's id
90 * @param existingStateFile
91 * Filename/location of the history we want to load
92 * @param providerVersion
93 * Expected version of of the state provider plugin.
94 * @throws IOException
95 * If we can't read the file, if it doesn't exist, is not
96 * recognized, or if the version of the file does not match the
97 * expected providerVersion.
98 */
99 public HistoryTreeBackendStub(String ssid, File existingStateFile, int providerVersion)
100 throws IOException {
101 super(ssid, existingStateFile, providerVersion);
102 }
103
104 @Override
105 protected IHistoryTree initializeSHT(HTConfig conf) throws IOException {
106 switch (HT_TYPE) {
107 case CLASSIC:
108 return new HistoryTreeClassicStub(conf);
109 default:
110 return new HistoryTreeClassicStub(conf);
111 }
112 }
113
114 @Override
115 protected IHistoryTree initializeSHT(File existingStateFile, int providerVersion) throws IOException {
116 switch (HT_TYPE) {
117 case CLASSIC:
118 return new HistoryTreeClassicStub(existingStateFile, providerVersion);
119 default:
120 return new HistoryTreeClassicStub(existingStateFile, providerVersion);
121 }
122 }
123
124 /**
125 * Get the History Tree built by this backend.
126 *
127 * @return The history tree
128 */
129 public HistoryTreeClassicStub getHistoryTree() {
130 return (HistoryTreeClassicStub) super.getSHT();
131 }
132
133 /**
134 * Debug method to print the contents of the history backend.
135 *
136 * @param writer
137 * The PrintWriter where to write the output
138 */
139 public void debugPrint(PrintWriter writer) {
140 /* By default don't print out all the intervals */
141 debugPrint(writer, false, -1);
142 }
143
144 /**
145 * The basic debugPrint method will print the tree structure, but not their
146 * contents.
147 *
148 * This method here print the contents (the intervals) as well.
149 *
150 * @param writer
151 * The PrintWriter to which the debug info will be written
152 * @param printIntervals
153 * Should we also print every contained interval individually?
154 * @param ts
155 * The timestamp that nodes have to intersect for intervals to be
156 * printed. A negative value will print intervals for all nodes.
157 * The timestamp only applies if printIntervals is true.
158 */
159 public void debugPrint(PrintWriter writer, boolean printIntervals, long ts) {
160 /* Only used for debugging, shouldn't be externalized */
161 writer.println("------------------------------"); //$NON-NLS-1$
162 writer.println("State History Tree:\n"); //$NON-NLS-1$
163 writer.println(getSHT().toString());
164 writer.println("Average node utilization: " //$NON-NLS-1$
165 + getAverageNodeUsage());
166 writer.println(""); //$NON-NLS-1$
167
168 getHistoryTree().debugPrintFullTree(writer, printIntervals, ts);
169 }
170 }
This page took 0.058649 seconds and 4 git commands to generate.