dlight.collector.procfs/src/org/netbeans/modules/dlight/collector/procfs/impl/ProcFSDataCollector.java @@ -58,9 +58,11 @@ import org.netbeans.modules.dlight.api.datafilter.DataFilter; import org.netbeans.modules.dlight.api.execution.AttachableTarget; import org.netbeans.modules.dlight.api.execution.DLightTarget; +import org.netbeans.modules.dlight.api.execution.DLightTarget.Info; import org.netbeans.modules.dlight.api.execution.DLightTargetChangeEvent; import org.netbeans.modules.dlight.api.execution.ValidationListener; import org.netbeans.modules.dlight.api.execution.ValidationStatus; +import org.netbeans.modules.dlight.api.impl.DLightTargetAccessor; import org.netbeans.modules.dlight.api.storage.DataRow; import org.netbeans.modules.dlight.api.storage.DataTableMetadata; import org.netbeans.modules.dlight.collector.procfs.ProcFSDCConfiguration; @@ -250,8 +252,24 @@ final int pid = ((AttachableTarget) target).getPID(); final ProcReader reader = ProcReaderFactory.getReader(target.getExecEnv(), pid); + DLightTargetAccessor targetAccess = DLightTargetAccessor.getDefault(); + Info targetInfo = targetAccess.getDLightTargetInfo(target); + String attachTimeString = targetInfo.getInfo().get("AttachTimeNano"); // NOI18N + // If the target was started using "attach", + // then current time will be used + // as an offset of collected data events... + // If it is a "regular" run, then a fair ts (from proc) + // will be used. + long attachTime = 0; + if (attachTimeString != null) { + try { + attachTime = Long.parseLong(attachTimeString); + } catch (NumberFormatException nfe) { + } + } + mainLoop = DLightExecutorService.scheduleAtFixedRate( - new FetchAndUpdateTask(reader), + new FetchAndUpdateTask(reader, attachTime), 1, TimeUnit.SECONDS, "ProcFSDataCollector data fetching loop"); // NOI18N } @@ -286,13 +304,15 @@ private final ProcReader reader; private final LWPsTracker lwpsTracker = new LWPsTracker(); private final AtomicLong processStartTime = new AtomicLong(0); + private final long attachTimeNano; - public FetchAndUpdateTask(final ProcReader reader) { + public FetchAndUpdateTask(final ProcReader reader, long attachTimeNano) { this.reader = reader; + this.attachTimeNano = attachTimeNano; } private final long toNanoOffset(long timenano) { - return timenano - processStartTime.get(); + return timenano - ((attachTimeNano > 0) ? attachTimeNano : processStartTime.get()); } public void run() { @@ -421,7 +441,7 @@ if (thread_started) { try { insertStatement.setInt(1, id); - insertStatement.setLong(2, toNanoOffset(lwp_usageInfo.getUsageInfo().pr_create)); // USE MILLISECONDS PASSED FROM START + insertStatement.setLong(2, toNanoOffset(attachTimeNano > 0 ? attachTimeNano : lwp_usageInfo.getUsageInfo().pr_create)); // USE MILLISECONDS PASSED FROM START insertStatement.executeUpdate(); } catch (SQLException ex) { if (log.isLoggable(Level.FINE)) { src/dlight.spi.impl/src/com/sun/dlight/spi/impl/target/PIDTarget.java @@ -76,6 +76,7 @@ io.getErr().println(loc("PIDTarget.InputOutput.Message.Attached", "" + getPID())); // NOI18N io.select(); + putToInfo("AttachTimeNano", Long.toString(System.nanoTime())); // NOI18N notifyListeners(new DLightTargetChangeEvent(this, State.RUNNING, pid)); return io;