Skip to content

Commit

Permalink
Support google-perf & dump stack map
Browse files Browse the repository at this point in the history
Signed-off-by: Seonghyun Kim <[email protected]>
  • Loading branch information
ksh8281 committed Aug 8, 2023
1 parent 100b5d4 commit f60bb68
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build/walrus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ IF (WALRUS_ASAN)
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} -fsanitize=address)
SET (WALRUS_LDFLAGS ${WALRUS_LDFLAGS} -lasan)
ENDIF()
IF (WALRUS_GOOGLE_PERF)
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} -DWALRUS_GOOGLE_PERF)
SET (WALRUS_LDFLAGS ${WALRUS_LDFLAGS} -lprofiler -lunwind -llzma)
ENDIF()
IF (WALRUS_SMALL_CONFIG)
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} -Os)
ENDIF()
Expand Down
30 changes: 30 additions & 0 deletions src/runtime/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,41 @@ Instance* Module::instantiate(ExecutionState& state, const ExternVector& imports
}

#if !defined(NDEBUG)

static const char* localTypeName(Value::Type v)
{
switch (v) {
case Value::I32:
return "i32";
case Value::I64:
return "i64";
case Value::F32:
return "f32";
case Value::F64:
return "f64";
case Value::V128:
return "v128";
case Value::FuncRef:
return "FuncRef";
case Value::ExternRef:
return "ExternRef";
default:
RELEASE_ASSERT_NOT_REACHED();
}
}

void ModuleFunction::dumpByteCode()
{
printf("\n");
printf("required stack size: %u bytes\n", m_requiredStackSize);
printf("required stack size due to local: %u bytes\n", m_requiredStackSizeDueToLocal);
printf("stack: [");
size_t pos = 0;
for (size_t i = 0; i < m_local.size(); i++) {
printf("%zu(local %zu, %s) ", pos, i, localTypeName(m_local[i]));
pos += valueStackAllocatedSize(m_local[i]);
}
printf("%zu(%" PRIu32 " bytes for general operation)]\n", pos, (m_requiredStackSize - m_requiredStackSizeDueToLocal));
printf("bytecode size: %zu bytes\n", m_byteCode.size());
printf("\n");

Expand Down
12 changes: 12 additions & 0 deletions src/shell/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <iomanip>
#include <inttypes.h>

#if defined(WALRUS_GOOGLE_PERF)
#include <gperftools/profiler.h>
#endif

#include "Walrus.h"
#include "runtime/Engine.h"
#include "runtime/Store.h"
Expand Down Expand Up @@ -970,6 +974,10 @@ int main(int argc, char* argv[])
mallopt(M_MMAP_MAX, 1024 * 1024);
#endif

#if defined(WALRUS_GOOGLE_PERF)
ProfilerStart("gperf_result");
#endif

Engine* engine = new Engine();
Store* store = new Store(engine);

Expand Down Expand Up @@ -1012,5 +1020,9 @@ int main(int argc, char* argv[])
delete store;
delete engine;

#if defined(WALRUS_GOOGLE_PERF)
ProfilerStop();
#endif

return 0;
}

0 comments on commit f60bb68

Please sign in to comment.