Skip to content

Commit

Permalink
Add performance counter for global variables (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger committed Jul 10, 2023
1 parent b9e7640 commit fd4683e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/be_debuglib.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ static int m_counters(bvm *vm)
map_insert(vm, "call", vm->counter_call);
map_insert(vm, "get", vm->counter_get);
map_insert(vm, "set", vm->counter_set);
map_insert(vm, "getgbl", vm->counter_get_global);
map_insert(vm, "try", vm->counter_try);
map_insert(vm, "raise", vm->counter_exc);
map_insert(vm, "objects", vm->counter_gc_kept);
Expand Down
4 changes: 4 additions & 0 deletions src/be_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ BERRY_API bvm* be_vm_new(void)
vm->counter_call = 0;
vm->counter_get = 0;
vm->counter_set = 0;
vm->counter_get_global = 0;
vm->counter_try = 0;
vm->counter_exc = 0;
vm->counter_gc_kept = 0;
Expand Down Expand Up @@ -579,6 +580,9 @@ static void vm_exec(bvm *vm)
dispatch();
}
opcase(GETNGBL): { /* get Global by name */
#if BE_USE_PERF_COUNTERS
vm->counter_get_global++;
#endif
bvalue *v = RA();
bvalue *b = RKB();
if (var_isstr(b)) {
Expand Down
1 change: 1 addition & 0 deletions src/be_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct bvm {
uint32_t counter_call; /* counter for calls, VM or native */
uint32_t counter_get; /* counter for GETMBR or GETMET */
uint32_t counter_set; /* counter for SETMBR */
uint32_t counter_get_global; /* counter for GETNBGL */
uint32_t counter_try; /* counter for `try` statement */
uint32_t counter_exc; /* counter for raised exceptions */
uint32_t counter_gc_kept; /* counter for objects scanned by last gc */
Expand Down

0 comments on commit fd4683e

Please sign in to comment.