Skip to content
This repository was archived by the owner on Nov 15, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
quick tidy up, keep send buffer functionality in one place
  • Loading branch information
sawilde committed Aug 8, 2015
commit 69b39e2e84c29225e0d9663c0d708416f2c6e898
6 changes: 1 addition & 5 deletions main/OpenCover.Profiler/CodeCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ HRESULT STDMETHODCALLTYPE CCodeCoverage::Shutdown( void)
if (m_chainedProfiler != NULL)
m_chainedProfiler->Shutdown();

if (!m_tracingEnabled){
m_host.SendRemainingThreadBuffers();
}

m_host.CloseChannel();
m_host.CloseChannel(m_tracingEnabled);

WCHAR szExeName[MAX_PATH];
GetModuleFileNameW(NULL, szExeName, MAX_PATH);
Expand Down
29 changes: 19 additions & 10 deletions main/OpenCover.Profiler/ProfilerCommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void ProfilerCommunication::ThreadCreated(ThreadID threadID, DWORD osThreadID){
ATL::CComCritSecLock<ATL::CComAutoCriticalSection> lock(m_critThreads);
m_threadmap[threadID] = osThreadID;
auto p = new MSG_SendVisitPoints_Request();
::ZeroMemory(p, sizeof(MSG_SendVisitPoints_Request));
p->count = 0;
//::ZeroMemory(p, sizeof(MSG_SendVisitPoints_Request));
m_visitmap[osThreadID] = p;
}

Expand All @@ -119,7 +120,8 @@ MSG_SendVisitPoints_Request* ProfilerCommunication::GetVisitMapForOSThread(ULONG
}
catch (...){
auto p = new MSG_SendVisitPoints_Request();
::ZeroMemory(p, sizeof(MSG_SendVisitPoints_Request));
p->count = 0;
//::ZeroMemory(p, sizeof(MSG_SendVisitPoints_Request));
m_visitmap[osThreadID] = p;
}
return m_visitmap[osThreadID];
Expand All @@ -128,15 +130,18 @@ MSG_SendVisitPoints_Request* ProfilerCommunication::GetVisitMapForOSThread(ULONG
void ProfilerCommunication::ThreadDestroyed(ThreadID threadID){
ATL::CComCritSecLock<ATL::CComAutoCriticalSection> lock(m_critThreads);
ULONG osThreadId = m_threadmap[threadID];
SendThreadVisitPoints(m_visitmap[osThreadId]);
auto points = m_visitmap[osThreadId];
SendThreadVisitPoints(points);
delete m_visitmap[osThreadId];
m_visitmap[osThreadId] = NULL;
}

void ProfilerCommunication::SendRemainingThreadBuffers(){
for (auto it = m_visitmap.begin(); it != m_visitmap.end(); ++it){
if (it->second != NULL)
if (it->second != NULL){
SendThreadVisitPoints(it->second);
//::ZeroMemory(pVisitPoints, sizeof(MSG_SendVisitPoints_Request));
}
}
}

Expand All @@ -148,17 +153,17 @@ void ProfilerCommunication::AddVisitPointToThreadBuffer(ULONG uniqueId, MSG_IdTy
if (++pVisitPoints->count == VP_BUFFER_SIZE)
{
SendThreadVisitPoints(pVisitPoints);
//::ZeroMemory(pVisitPoints, sizeof(MSG_SendVisitPoints_Request));
pVisitPoints->count = 0;
//::ZeroMemory(pVisitPoints, sizeof(MSG_SendVisitPoints_Request));
}
}

void ProfilerCommunication::SendThreadVisitPoints(MSG_SendVisitPoints_Request* pVisitPoints){
ATL::CComCritSecLock<ATL::CComAutoCriticalSection> lock(m_critResults);
if (!hostCommunicationActive) return;
memcpy(m_pVisitPoints, pVisitPoints, sizeof(MSG_SendVisitPoints_Request));
pVisitPoints->count = 0;
SendVisitPoints();
::ZeroMemory(m_pVisitPoints, sizeof(MAX_MSG_SIZE));
//::ZeroMemory(m_pVisitPoints, sizeof(MSG_SendVisitPoints_Request));
m_pVisitPoints->count = 0;
}

Expand All @@ -170,7 +175,7 @@ void ProfilerCommunication::AddVisitPointToBuffer(ULONG uniqueId, MSG_IdType msg
if (++m_pVisitPoints->count == VP_BUFFER_SIZE)
{
SendVisitPoints();
::ZeroMemory(m_pVisitPoints, sizeof(MAX_MSG_SIZE));
//::ZeroMemory(m_pVisitPoints, sizeof(MSG_SendVisitPoints_Request));
m_pVisitPoints->count = 0;
}
}
Expand Down Expand Up @@ -336,10 +341,14 @@ bool ProfilerCommunication::AllocateBuffer(LONG bufferSize, ULONG &bufferId)
return response;
}

void ProfilerCommunication::CloseChannel(){
void ProfilerCommunication::CloseChannel(bool sendSingleBuffer){
if (m_bufferId == 0) return;

SendVisitPoints();

if (sendSingleBuffer)
SendVisitPoints();
else
SendRemainingThreadBuffers();

if (!hostCommunicationActive) return;

Expand Down
4 changes: 2 additions & 2 deletions main/OpenCover.Profiler/ProfilerCommunication.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ class ProfilerCommunication
inline void AddTestTailcallPoint(ULONG uniqueId) { AddVisitPointToBuffer(uniqueId, IT_MethodTailcall); }
inline void AddVisitPoint(ULONG uniqueId) { AddVisitPointToBuffer(uniqueId, IT_VisitPoint); }
void AddVisitPointToThreadBuffer(ULONG uniqueId, MSG_IdType msgType);
void CloseChannel();
void CloseChannel(bool sendSingleBuffer);

public:
void ThreadCreated(ThreadID threadID, DWORD osThreadID);
void ThreadDestroyed(ThreadID threadID);
void SendRemainingThreadBuffers();

private:
void AddVisitPointToBuffer(ULONG uniqueId, MSG_IdType msgType);
void SendVisitPoints();
void SendThreadVisitPoints(MSG_SendVisitPoints_Request* pVisitPoints);
bool GetSequencePoints(mdToken functionToken, WCHAR* pModulePath, WCHAR* pAssemblyName, std::vector<SequencePoint> &points);
bool GetBranchPoints(mdToken functionToken, WCHAR* pModulePath, WCHAR* pAssemblyName, std::vector<BranchPoint> &points);
void SendRemainingThreadBuffers();

private:
tstring m_key;
Expand Down