use of org.spf4j.tsdb2.TSDBQuery.TableDefEx in project spf4j by zolyfarkas.
the class TSDBQuery method getAllTablesWithDataRanges.
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED")
public static ListMultimap<String, TableDefEx> getAllTablesWithDataRanges(final File tsdbFile) throws IOException {
ListMultimap<String, TableDefEx> result = ArrayListMultimap.create();
TLongObjectMap<TableDefEx> id2Def = new TLongObjectHashMap<>();
try (TSDBReader reader = new TSDBReader(tsdbFile, 8192)) {
Either<TableDef, DataBlock> read;
while ((read = reader.read()) != null) {
if (read.isLeft()) {
final TableDef left = read.getLeft();
final TableDefEx tableDefEx = new TableDefEx(left, Long.MAX_VALUE, 0L);
id2Def.put(left.id, tableDefEx);
result.put(tableDefEx.getTableDef().getName(), tableDefEx);
} else {
DataBlock right = read.getRight();
long baseTs = right.baseTimestamp;
for (DataRow row : right.getValues()) {
TableDefEx tdex = id2Def.get(row.tableDefId);
if (tdex == null) {
throw new IOException("Potentially corupted file data row with no tableDef " + row);
}
long ts = baseTs + row.relTimeStamp;
if (ts < tdex.getStartTime()) {
tdex.setStartTime(ts);
}
if (ts > tdex.getEndTime()) {
tdex.setEndTime(ts);
}
}
}
}
}
return result;
}
use of org.spf4j.tsdb2.TSDBQuery.TableDefEx in project spf4j by zolyfarkas.
the class FileMonitorAspectTest method testFileIOMonitoring.
/**
* Test of nioReadLong method, of class FileMonitorAspect.
*/
@Test
public void testFileIOMonitoring() throws Exception {
System.setProperty("spf4j.perf.file.sampleTimeMillis", "1000");
File tempFile = File.createTempFile("test", ".tmp");
tempFile.deleteOnExit();
try (Writer fw = new OutputStreamWriter(Files.newOutputStream(tempFile.toPath()), StandardCharsets.UTF_8)) {
for (int i = 0; i < 10; i++) {
fw.write("bla bla test\n");
Thread.sleep(500);
}
}
Thread.sleep(1000);
try (BufferedReader fr = new BufferedReader(new InputStreamReader(Files.newInputStream(tempFile.toPath()), StandardCharsets.UTF_8))) {
String line = fr.readLine();
while (line != null) {
LOG.debug("Read: {}", line);
line = fr.readLine();
Thread.sleep(500);
}
}
TSDBWriter dbWriter = ((TSDBMeasurementStore) RecorderFactory.MEASUREMENT_STORE).getDBWriter();
dbWriter.flush();
final File file = dbWriter.getFile();
ListMultimap<String, TableDefEx> allTables = TSDBQuery.getAllTablesWithDataRanges(file);
LOG.debug("Tables {}", allTables);
Map<String, Collection<TableDefEx>> asMap = allTables.asMap();
Assert.assertThat(asMap, (Matcher) Matchers.hasKey("file-write,org.spf4j.perf.aspects.FileMonitorAspectTest"));
Assert.assertThat(asMap, (Matcher) Matchers.hasKey("file-read,org.spf4j.perf.aspects.FileMonitorAspectTest"));
List<TableDefEx> get = allTables.get("file-write,org.spf4j.perf.aspects.FileMonitorAspectTest");
Assert.assertTrue(get.get(0).getStartTime() != 0);
Assert.assertTrue(OperatingSystem.getOpenFileDescriptorCount() > 0);
}
Aggregations