Skip to content

Commit

Permalink
Enhance UNICODE support
Browse files Browse the repository at this point in the history
Also to fix GameTechDev#191

Signed-off-by: Martin Malik <mm@hwinfo.com>
  • Loading branch information
Martin Malik authored and Martin Malik committed Dec 12, 2023
1 parent b469546 commit b7ed19b
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 256 deletions.
7 changes: 2 additions & 5 deletions PresentData/PresentMonTraceConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2190,10 +2190,7 @@ void PMTraceConsumer::HandleProcessEvent(EVENT_RECORD* pEventRecord)
// e.g.: \Device\HarddiskVolume...\...\Proces.exe. We prune off everything other than
// the filename here to be consistent.
size_t start = ImageName.find_last_of('\\') + 1;
size_t size = ImageName.size() - start;
event.ImageFileName.resize(size + 1);
wcstombs_s(&size, &event.ImageFileName[0], size + 1, ImageName.c_str() + start, size);
event.ImageFileName.resize(size - 1);
event.ImageFileName = ImageName.c_str() + start;
break;
}
case Microsoft_Windows_Kernel_Process::ProcessStop_Stop::Id: {
Expand All @@ -2218,7 +2215,7 @@ void PMTraceConsumer::HandleProcessEvent(EVENT_RECORD* pEventRecord)
};
mMetadata.GetEventData(pEventRecord, desc, _countof(desc));
event.ProcessId = desc[0].GetData<uint32_t>();
event.ImageFileName = desc[1].GetData<std::string>();
event.ImageFileName = desc[1].GetData<std::wstring>();
event.IsStartEvent = true;
} else if (hdr.EventDescriptor.Opcode == EVENT_TRACE_TYPE_END||
hdr.EventDescriptor.Opcode == EVENT_TRACE_TYPE_DC_END) {
Expand Down
2 changes: 1 addition & 1 deletion PresentData/PresentMonTraceConsumer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct InputEvent {

// A ProcessEvent occurs whenever a Process starts or stops.
struct ProcessEvent {
std::string ImageFileName; // The name of the process exe file. This is only available on process start events.
std::wstring ImageFileName; // The name of the process exe file. This is only available on process start events.
uint64_t QpcTime; // The time of the start/stop event.
uint32_t ProcessId; // The id of the process.
bool IsStartEvent; // Whether this is a start event (true) or a stop event (false).
Expand Down
20 changes: 10 additions & 10 deletions PresentData/TraceSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ PEVENT_RECORD_CALLBACK GetEventRecordCallback(bool t1, bool t2, bool t3, bool t4
: GetEventRecordCallback<Ts..., false>(t2, t3, t4);
}

ULONG CALLBACK BufferCallback(EVENT_TRACE_LOGFILEA* pLogFile)
ULONG CALLBACK BufferCallback(EVENT_TRACE_LOGFILE* pLogFile)
{
auto session = (TraceSession*) pLogFile->Context;
return session->mContinueProcessingBuffers; // TRUE = continue processing events, FALSE = return out of ProcessTrace()
Expand All @@ -480,8 +480,8 @@ ULONG CALLBACK BufferCallback(EVENT_TRACE_LOGFILEA* pLogFile)
ULONG TraceSession::Start(
PMTraceConsumer* pmConsumer,
MRTraceConsumer* mrConsumer,
char const* etlPath,
char const* sessionName)
WCHAR const* etlPath,
WCHAR const* sessionName)
{
assert(mSessionHandle == 0);
assert(mTraceHandle == INVALID_PROCESSTRACE_HANDLE);
Expand All @@ -492,8 +492,8 @@ ULONG TraceSession::Start(

// -------------------------------------------------------------------------
// Configure trace properties
EVENT_TRACE_LOGFILEA traceProps = {};
traceProps.LogFileName = (char*) etlPath;
EVENT_TRACE_LOGFILE traceProps = {};
traceProps.LogFileName = (WCHAR*) etlPath;
traceProps.ProcessTraceMode = PROCESS_TRACE_MODE_EVENT_RECORD | PROCESS_TRACE_MODE_RAW_TIMESTAMP;
traceProps.Context = this;
/* Output members (passed also to BufferCallback):
Expand Down Expand Up @@ -523,7 +523,7 @@ ULONG TraceSession::Start(
// -------------------------------------------------------------------------
// For realtime collection, start the session with the required providers
if (traceProps.LogFileName == nullptr) {
traceProps.LoggerName = (char*) sessionName;
traceProps.LoggerName = (WCHAR*) sessionName;
traceProps.ProcessTraceMode |= PROCESS_TRACE_MODE_REAL_TIME;

TraceProperties sessionProps = {};
Expand Down Expand Up @@ -556,7 +556,7 @@ ULONG TraceSession::Start(
sessionProps.LoggerThreadId // tracing session identifier
*/

auto status = StartTraceA(&mSessionHandle, sessionName, &sessionProps);
auto status = StartTrace(&mSessionHandle, sessionName, &sessionProps);
if (status != ERROR_SUCCESS) {
mSessionHandle = 0;
return status;
Expand All @@ -571,7 +571,7 @@ ULONG TraceSession::Start(

// -------------------------------------------------------------------------
// Open the trace
mTraceHandle = OpenTraceA(&traceProps);
mTraceHandle = OpenTrace(&traceProps);
if (mTraceHandle == INVALID_PROCESSTRACE_HANDLE) {
auto lastError = GetLastError();
Stop();
Expand Down Expand Up @@ -646,12 +646,12 @@ void TraceSession::Stop()
}
}

ULONG TraceSession::StopNamedSession(char const* sessionName)
ULONG TraceSession::StopNamedSession(WCHAR const* sessionName)
{
TraceProperties sessionProps = {};
sessionProps.Wnode.BufferSize = (ULONG) sizeof(TraceProperties);
sessionProps.LoggerNameOffset = offsetof(TraceProperties, mSessionName);
return ControlTraceA((TRACEHANDLE) 0, sessionName, &sessionProps, EVENT_TRACE_CONTROL_STOP);
return ControlTraceW((TRACEHANDLE) 0, sessionName, &sessionProps, EVENT_TRACE_CONTROL_STOP);
}


Expand Down
6 changes: 3 additions & 3 deletions PresentData/TraceSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ struct TraceSession {
ULONG Start(
PMTraceConsumer* pmConsumer, // Required PMTraceConsumer instance
MRTraceConsumer* mrConsumer, // If nullptr, no WinMR tracing
char const* etlPath, // If nullptr, live/realtime tracing session
char const* sessionName); // Required session name
WCHAR const* etlPath, // If nullptr, live/realtime tracing session
WCHAR const* sessionName); // Required session name

void Stop();

ULONG CheckLostReports(ULONG* eventsLost, ULONG* buffersLost) const;
static ULONG StopNamedSession(char const* sessionName);
static ULONG StopNamedSession(WCHAR const* sessionName);
};

0 comments on commit b7ed19b

Please sign in to comment.