Module: Pyroscope

Defined in:
lib/pyroscope.rb,
lib/pyroscope/version.rb,
ext/pyroscope/pyroscope.c

Defined Under Namespace

Classes: Config

Constant Summary collapse

VERSION =
"0.2.0".freeze

Class Method Summary collapse

Class Method Details

._build_summaryObject



70
71
72
73
74
75
76
# File 'ext/pyroscope/pyroscope.c', line 70

static VALUE
pyroscope_build_summary(VALUE self) {
  char *c_summary = BuildSummary();
  VALUE r_summary = rb_str_new_cstr(c_summary);
  free(c_summary);
  return r_summary;
}

._change_name(appName) ⇒ Object



44
45
46
47
48
49
50
51
# File 'ext/pyroscope/pyroscope.c', line 44

static VALUE
pyroscope_change_name(VALUE self, VALUE appName) {
  VALUE r_appName = StringValue(appName);
  char *c_appName = RSTRING_PTR(r_appName);

  int res = ChangeName(c_appName);
  return INT2FIX(res);
}

._set_tag(key, val) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'ext/pyroscope/pyroscope.c', line 53

static VALUE
pyroscope_set_tag(VALUE self, VALUE key, VALUE val) {
  VALUE r_key = StringValue(key);
  char *c_key = RSTRING_PTR(r_key);
  VALUE r_val = StringValue(val);
  char *c_val = RSTRING_PTR(r_val);

  int res = SetTag(c_key, c_val);
  return INT2FIX(res);
}

._start(appName, serverAddress, authToken, sampleRate, withSubprocesses, logLevel) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'ext/pyroscope/pyroscope.c', line 16

static VALUE
pyroscope_start(VALUE self, VALUE appName, VALUE serverAddress, VALUE authToken, VALUE sampleRate, VALUE withSubprocesses, VALUE logLevel) {
  VALUE r_appName = StringValue(appName);
  char *c_appName = RSTRING_PTR(r_appName);

  int c_sampleRate = FIX2INT(sampleRate);
  int c_withSubprocesses = FIX2INT(withSubprocesses);

  VALUE r_serverAddress = StringValue(serverAddress);
  char *c_serverAddress = RSTRING_PTR(r_serverAddress);

  VALUE r_authToken = StringValue(authToken);
  char *c_authToken = RSTRING_PTR(r_authToken);

  VALUE r_logLevel = StringValue(logLevel);
  char *c_logLevel = RSTRING_PTR(r_logLevel);

  int res = Start(c_appName, "rbspy", c_serverAddress, c_authToken, c_sampleRate, c_withSubprocesses, c_logLevel);

  return INT2FIX(res);
}

._stopObject



38
39
40
41
42
# File 'ext/pyroscope/pyroscope.c', line 38

static VALUE
pyroscope_stop(VALUE self) {
  int res = Stop();
  return INT2FIX(res);
}

._test_loggerObject



64
65
66
67
68
# File 'ext/pyroscope/pyroscope.c', line 64

static VALUE
pyroscope_test_logger(VALUE self) {
  int res = TestLogger();
  return INT2FIX(res);
}

.build_summaryObject



56
57
58
# File 'lib/pyroscope.rb', line 56

def build_summary
  _build_summary
end

.change_name(new_name) ⇒ Object



26
27
28
# File 'lib/pyroscope.rb', line 26

def change_name(new_name)
  _change_name(new_name)
end

.configure {|@configuration| ... } ⇒ Object

Yields:

  • (@configuration)


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pyroscope.rb', line 8

def configure
  @configuration = Config.new
  yield @configuration
  _start(
    @configuration.app_name,
    @configuration.server_address,
    @configuration.auth_token || "",
    @configuration.sample_rate || 100,
    @configuration.with_subprocesses || 0,
    @configuration.log_level || "error",
  )
  tag(@configuration.tags) if @configuration.tags
end

.remove_tags(*keys) ⇒ Object



46
47
48
49
50
# File 'lib/pyroscope.rb', line 46

def remove_tags(*keys)
  keys.each do |key|
    _set_tag(key.to_s, "")
  end
end

.stopObject



22
23
24
# File 'lib/pyroscope.rb', line 22

def stop
  _stop
end

.tag(tags) ⇒ Object



40
41
42
43
44
# File 'lib/pyroscope.rb', line 40

def tag(tags)
  tags.each_pair do |key, val|
    _set_tag(key.to_s, val.to_s)
  end
end

.tag_wrapper(tags) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/pyroscope.rb', line 30

def tag_wrapper(tags)
  tag(tags)

  begin
    yield
  ensure
    remove_tags(*tags.keys)
  end
end

.test_loggerObject



52
53
54
# File 'lib/pyroscope.rb', line 52

def test_logger
  _test_logger
end