Skip to content

Commit

Permalink
Profiling with gperftools
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Jan 2, 2024
1 parent 80f6336 commit dda175d
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export(nng_version)
export(opt)
export(parse_url)
export(pipe_notify)
export(profiler_start)
export(profiler_stop)
export(random)
export(reap)
export(recv)
Expand Down
22 changes: 22 additions & 0 deletions R/profiler.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#' @title Start the `gperftools` profiler.
#' @export
#' @description Start the `gperftools` profiler.
#' @return `NULL` (invisibly).
#' @param path Character of length 1 with the file path to the profiling samples.
profiler_start <- function(path) {
stopifnot(all(is.character(path)))
stopifnot(all(length(path) == 1L))
stopifnot(!anyNA(path))
stopifnot(all(nzchar(path)))
.Call(rnng_profiler_start, path = path, PACKAGE = "nanonext")
invisible()
}

#' @title Stop the `gperftools` profiler.
#' @export
#' @description Stop the `gperftools` profiler.
#' @return `NULL` (invisibly).
profiler_stop <- function() {
.Call(rnng_profiler_stop, PACKAGE = "nanonext")
invisible()
}
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TLS_VER="edb8fec"

# Initialise
PKG_CFLAGS=""
PKG_LIBS="-lnng -lmbedtls -lmbedx509 -lmbedcrypto"
PKG_LIBS="-lnng -lmbedtls -lmbedx509 -lmbedcrypto -lprofiler"
NNG_CFLAGS=""
NNG_LIBS=""

Expand Down
17 changes: 17 additions & 0 deletions man/profiler_start.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/profiler_stop.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ static const R_CallMethodDef callMethods[] = {
{"rnng_ncurl_transact", (DL_FUNC) &rnng_ncurl_transact, 1},
{"rnng_next_config", (DL_FUNC) &rnng_next_config, 2},
{"rnng_pipe_notify", (DL_FUNC) &rnng_pipe_notify, 6},
{"rnng_profiler_start", (DL_FUNC) &rnng_profiler_start, 1},
{"rnng_profiler_stop", (DL_FUNC) &rnng_profiler_stop, 0},
{"rnng_protocol_open", (DL_FUNC) &rnng_protocol_open, 2},
{"rnng_random", (DL_FUNC) &rnng_random, 2},
{"rnng_reap", (DL_FUNC) &rnng_reap, 1},
Expand Down
2 changes: 2 additions & 0 deletions src/nanonext.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ SEXP rnng_ncurl_session_close(SEXP);
SEXP rnng_ncurl_transact(SEXP);
SEXP rnng_next_config(SEXP, SEXP);
SEXP rnng_pipe_notify(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
SEXP rnng_profiler_start(SEXP);
SEXP rnng_profiler_stop(SEXP);
SEXP rnng_protocol_open(SEXP, SEXP);
SEXP rnng_random(SEXP, SEXP);
SEXP rnng_reap(SEXP);
Expand Down
13 changes: 13 additions & 0 deletions src/profiler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <R.h>
#include <Rinternals.h>
#include "gperftools/profiler.h"

SEXP rnng_profiler_start(SEXP path) {
ProfilerStart(CHAR(STRING_ELT(path, 0)));
return R_NilValue;
}

SEXP rnng_profiler_stop() {
ProfilerStop();
return R_NilValue;
}

0 comments on commit dda175d

Please sign in to comment.