@@ -34,12 +34,17 @@ bool StartTraceSession()
3434 gMRConsumer = new MRTraceConsumer (args.mTrackDisplay );
3535 }
3636
37+ if (args.mOutputDateTime ) {
38+ gSession .mTimestampType = TraceSession::TIMESTAMP_TYPE_SYSTEM_TIME;
39+ } else {
40+ gSession .mTimestampType = TraceSession::TIMESTAMP_TYPE_QPC;
41+ }
42+
3743 // Start the session;
3844 // If a session with this same name is already running, we either exit or
3945 // stop it and start a new session. This is useful if a previous process
4046 // failed to properly shut down the session for some reason.
41- auto timestampType = args.mOutputDateTime ? TraceSession::TIMESTAMP_TYPE_SYSTEM_TIME : TraceSession::TIMESTAMP_TYPE_QPC;
42- auto status = gSession .Start (gPMConsumer , gMRConsumer , args.mEtlFileName , args.mSessionName , timestampType);
47+ auto status = gSession .Start (gPMConsumer , gMRConsumer , args.mEtlFileName , args.mSessionName );
4348 if (status == ERROR_ALREADY_EXISTS) {
4449 if (args.mStopExistingSession ) {
4550 PrintWarning (
@@ -61,7 +66,7 @@ bool StartTraceSession()
6166
6267 status = TraceSession::StopNamedSession (args.mSessionName );
6368 if (status == ERROR_SUCCESS) {
64- status = gSession .Start (gPMConsumer , gMRConsumer , args.mEtlFileName , args.mSessionName , timestampType );
69+ status = gSession .Start (gPMConsumer , gMRConsumer , args.mEtlFileName , args.mSessionName );
6570 }
6671 }
6772
@@ -164,12 +169,13 @@ double TimestampToSeconds(uint64_t timestamp)
164169
165170void TimestampToLocalSystemTime (uint64_t timestamp, SYSTEMTIME* st, uint64_t * ns)
166171{
167- /* if not TIMESTAMP_TYPE_SYSTEM_TIME
168- auto tns = (timestamp - gSession.mStartTimestamp.QuadPart) * 1000000000ull / gSession.mTimestampFrequency.QuadPart;
169- auto ft = gSession.mStartFileTime + (tns / 100);
170- FileTimeToSystemTime((FILETIME const*) &ft, st);
171- *ns = tns % 1000000000;
172- */
173- FileTimeToSystemTime ((FILETIME const *) ×tamp, st);
172+ if (gSession .mTimestampType != TraceSession::TIMESTAMP_TYPE_SYSTEM_TIME) {
173+ auto delta100ns = (timestamp - gSession .mStartTimestamp .QuadPart ) * 10000000ull / gSession .mTimestampFrequency .QuadPart ;
174+ timestamp = gSession .mStartFileTime + delta100ns;
175+ }
176+
177+ FILETIME lft{};
178+ FileTimeToLocalFileTime ((FILETIME*) ×tamp, &lft);
179+ FileTimeToSystemTime (&lft, st);
174180 *ns = (timestamp % 10000000 ) * 100 ;
175181}
0 commit comments