Skip to content

Enhance UNICODE support #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 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,8 @@ 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>();
std::string str = desc[1].GetData<std::string>();
event.ImageFileName = std::wstring(str.begin(), str.end());
event.IsStartEvent = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the underlying data for this event is always char, and GetData() doesn't do any conversion, it just accesses the event data as if it were a T. So, we need to leave it as GetData() and then convert here.

In debug build GetData() should be asserting with this change, though you'll only hit this event when processing from an ETL file (--etl_file).

} 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_t const* etlPath,
wchar_t 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_t*) 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_t*) 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_t 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_t const* etlPath, // If nullptr, live/realtime tracing session
wchar_t const* sessionName); // Required session name

void Stop();

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