Skip to content

Commit

Permalink
V8 bindings for user time
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 20, 2024
1 parent e58f6a1 commit 45867f0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions bindings/gumjs/gumv8sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "gumv8sampler.h"
#include "gumsampler.h"
#include "gumwallclocksampler.h"
#include "gumusertimesampler.h"

#include "gumv8macros.h"
#include "gumv8scope.h"
Expand All @@ -18,6 +19,7 @@ using namespace v8;
GUMJS_DECLARE_CONSTRUCTOR (gumjs_sampler_construct)
GUMJS_DECLARE_FUNCTION (gumjs_sampler_sample)
GUMJS_DECLARE_CONSTRUCTOR (gumjs_wallclock_sampler_construct)
GUMJS_DECLARE_CONSTRUCTOR (gumjs_user_time_sampler_construct)

static const GumV8Function gumjs_sampler_functions[] =
{
Expand Down Expand Up @@ -45,6 +47,10 @@ _gum_v8_sampler_init (GumV8Sampler * self,
auto wallclock_sampler = _gum_v8_create_class ("WallClockSampler",
gumjs_wallclock_sampler_construct, scope, module, isolate);
wallclock_sampler->Inherit (sampler);

auto user_time_sampler = _gum_v8_create_class ("UserTimeSampler",
gumjs_user_time_sampler_construct, scope, module, isolate);
user_time_sampler->Inherit (sampler);
}

void
Expand Down Expand Up @@ -97,5 +103,26 @@ GUMJS_DEFINE_CONSTRUCTOR (gumjs_wallclock_sampler_construct)

gum_v8_object_manager_add (&module->objects, wrapper, sampler, module);

wrapper->SetAlignedPointerInInternalField (0, sampler);
}

GUMJS_DEFINE_CONSTRUCTOR (gumjs_user_time_sampler_construct)
{
GumThreadId thread_id = gum_process_get_current_thread_id ();

if (!info.IsConstructCall ())
{
_gum_v8_throw_ascii_literal (isolate,
"use `new UserTimeSampler()` to create a new instance");
return;
}

if (!_gum_v8_args_parse (args, "|Z", &thread_id))
return;

auto sampler = gum_user_time_sampler_new_with_thread_id (thread_id);

gum_v8_object_manager_add (&module->objects, wrapper, sampler, module);

wrapper->SetAlignedPointerInInternalField (0, sampler);
}

0 comments on commit 45867f0

Please sign in to comment.