Skip to content

Commit 597b091

Browse files
Fix issue where full process path was reported.
When running presentmon as-admin, and when running presentmon before the target application, the application process would be reported as \Device\HarddiskVolumn...\...\Process.exe instead of Process.exe as in other cases. This change prunes off everything but the Process.exe for that case. It also makes it more clear that ImageName is only valid for process start events (since the property on ProcessStop is not reliable). Addresses issue #157
1 parent d0ffa18 commit 597b091

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

PresentData/PresentMonTraceConsumer.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,21 +2186,23 @@ void PMTraceConsumer::HandleProcessEvent(EVENT_RECORD* pEventRecord)
21862186
auto ImageName = desc[1].GetData<std::wstring>();
21872187
event.IsStartEvent = true;
21882188

2189-
auto size = ImageName.size();
2189+
// When run as-administrator, ImageName will be a fully-qualified path.
2190+
// e.g.: \Device\HarddiskVolume...\...\Proces.exe. We prune off everything other than
2191+
// the filename here to be consistent.
2192+
size_t start = ImageName.find_last_of('\\') + 1;
2193+
size_t size = ImageName.size() - start;
21902194
event.ImageFileName.resize(size + 1);
2191-
wcstombs_s(&size, &event.ImageFileName[0], size + 1, ImageName.c_str(), size);
2195+
wcstombs_s(&size, &event.ImageFileName[0], size + 1, ImageName.c_str() + start, size);
21922196
event.ImageFileName.resize(size - 1);
21932197
break;
21942198
}
21952199
case Microsoft_Windows_Kernel_Process::ProcessStop_Stop::Id: {
21962200
EventDataDesc desc[] = {
21972201
{ L"ProcessID" },
2198-
{ L"ImageName" },
21992202
};
22002203
mMetadata.GetEventData(pEventRecord, desc, _countof(desc));
2201-
event.ProcessId = desc[0].GetData<uint32_t>();
2202-
event.ImageFileName = desc[1].GetData<std::string>();
2203-
event.IsStartEvent = false;
2204+
event.ProcessId = desc[0].GetData<uint32_t>();
2205+
event.IsStartEvent = false;
22042206
break;
22052207
}
22062208
default:
@@ -2210,21 +2212,25 @@ void PMTraceConsumer::HandleProcessEvent(EVENT_RECORD* pEventRecord)
22102212
} else { // hdr.ProviderId == NT_Process::GUID
22112213
if (hdr.EventDescriptor.Opcode == EVENT_TRACE_TYPE_START ||
22122214
hdr.EventDescriptor.Opcode == EVENT_TRACE_TYPE_DC_START) {
2213-
event.IsStartEvent = true;
2215+
EventDataDesc desc[] = {
2216+
{ L"ProcessId" },
2217+
{ L"ImageFileName" },
2218+
};
2219+
mMetadata.GetEventData(pEventRecord, desc, _countof(desc));
2220+
event.ProcessId = desc[0].GetData<uint32_t>();
2221+
event.ImageFileName = desc[1].GetData<std::string>();
2222+
event.IsStartEvent = true;
22142223
} else if (hdr.EventDescriptor.Opcode == EVENT_TRACE_TYPE_END||
22152224
hdr.EventDescriptor.Opcode == EVENT_TRACE_TYPE_DC_END) {
2225+
EventDataDesc desc[] = {
2226+
{ L"ProcessId" },
2227+
};
2228+
mMetadata.GetEventData(pEventRecord, desc, _countof(desc));
2229+
event.ProcessId = desc[0].GetData<uint32_t>();
22162230
event.IsStartEvent = false;
22172231
} else {
22182232
return;
22192233
}
2220-
2221-
EventDataDesc desc[] = {
2222-
{ L"ProcessId" },
2223-
{ L"ImageFileName" },
2224-
};
2225-
mMetadata.GetEventData(pEventRecord, desc, _countof(desc));
2226-
event.ProcessId = desc[0].GetData<uint32_t>();
2227-
event.ImageFileName = desc[1].GetData<std::string>();
22282234
}
22292235

22302236
std::lock_guard<std::mutex> lock(mProcessEventMutex);

PresentData/PresentMonTraceConsumer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ struct InputEvent {
124124

125125
// A ProcessEvent occurs whenever a Process starts or stops.
126126
struct ProcessEvent {
127-
std::string ImageFileName;
128-
uint64_t QpcTime;
129-
uint32_t ProcessId;
130-
bool IsStartEvent;
127+
std::string ImageFileName; // The name of the process exe file. This is only available on process start events.
128+
uint64_t QpcTime; // The time of the start/stop event.
129+
uint32_t ProcessId; // The id of the process.
130+
bool IsStartEvent; // Whether this is a start event (true) or a stop event (false).
131131
};
132132

133133
struct PresentEvent {

0 commit comments

Comments
 (0)