track number of write watches with microprofile

This commit is contained in:
Anthony Pesch 2015-09-17 20:57:37 -07:00
parent 76e4a96689
commit 265369f864
2 changed files with 12 additions and 4 deletions

View File

@ -14,6 +14,9 @@
#define PROFILER_RUNTIME(name) \ #define PROFILER_RUNTIME(name) \
MICROPROFILE_SCOPEI("runtime", name, dreavm::emu::Profiler::ScopeColor(name)) MICROPROFILE_SCOPEI("runtime", name, dreavm::emu::Profiler::ScopeColor(name))
#define PROFILER_COUNT(name, count) \
MICROPROFILE_COUNTER_SET(name, count)
namespace dreavm { namespace dreavm {
namespace emu { namespace emu {

View File

@ -1,5 +1,6 @@
#include "core/core.h" #include "core/core.h"
#include "core/interval_tree.h" #include "core/interval_tree.h"
#include "emu/profiler.h"
#include "sys/sigsegv_handler.h" #include "sys/sigsegv_handler.h"
using namespace dreavm::sys; using namespace dreavm::sys;
@ -25,8 +26,6 @@ SIGSEGVHandler *SIGSEGVHandler::Install() {
SIGSEGVHandler::~SIGSEGVHandler() { global_handler_ = nullptr; } SIGSEGVHandler::~SIGSEGVHandler() { global_handler_ = nullptr; }
// TODO track handler counts with microprofile
void SIGSEGVHandler::AddWriteWatch(void *ptr, int size, void SIGSEGVHandler::AddWriteWatch(void *ptr, int size,
WriteWatchHandler handler, void *ctx, WriteWatchHandler handler, void *ctx,
void *data) { void *data) {
@ -37,13 +36,16 @@ void SIGSEGVHandler::AddWriteWatch(void *ptr, int size,
dreavm::align(reinterpret_cast<uintptr_t>(ptr) + size, dreavm::align(reinterpret_cast<uintptr_t>(ptr) + size,
static_cast<uintptr_t>(page_size)); static_cast<uintptr_t>(page_size));
// write-protect the pages // write protect the pages
CHECK(Protect(reinterpret_cast<void *>(physical_start), CHECK(Protect(reinterpret_cast<void *>(physical_start),
static_cast<int>(physical_end - physical_start), ACC_READONLY)); static_cast<int>(physical_end - physical_start), ACC_READONLY));
write_watches_.Insert( write_watches_.Insert(
physical_start, physical_end - 1, physical_start, physical_end - 1,
WriteWatch(handler, ctx, data, physical_start, physical_end)); WriteWatch(handler, ctx, data, physical_start, physical_end));
// track number of watches
PROFILER_COUNT("WriteWatches", write_watches_.Size());
} }
bool SIGSEGVHandler::HandleAccessFault(uintptr_t rip, uintptr_t fault_addr) { bool SIGSEGVHandler::HandleAccessFault(uintptr_t rip, uintptr_t fault_addr) {
@ -56,7 +58,7 @@ bool SIGSEGVHandler::HandleAccessFault(uintptr_t rip, uintptr_t fault_addr) {
watch.handler(watch.ctx, watch.data); watch.handler(watch.ctx, watch.data);
// remove write-protection // remove write protection
CHECK(Protect(reinterpret_cast<void *>(watch.physical_start), CHECK(Protect(reinterpret_cast<void *>(watch.physical_start),
static_cast<int>(watch.physical_end - watch.physical_start), static_cast<int>(watch.physical_end - watch.physical_start),
ACC_READWRITE)); ACC_READWRITE));
@ -66,5 +68,8 @@ bool SIGSEGVHandler::HandleAccessFault(uintptr_t rip, uintptr_t fault_addr) {
node = write_watches_.Find(fault_addr, fault_addr); node = write_watches_.Find(fault_addr, fault_addr);
} }
// track number of watches
PROFILER_COUNT("WriteWatches", write_watches_.Size());
return handled; return handled;
} }