laplace 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d617e0ba7f3472d1170dc4c6cd7a2b7524d89ca
4
+ data.tar.gz: d9b8936383115b373b953418128a61520a16cfeb
5
+ SHA512:
6
+ metadata.gz: 2b72ea578cbf8666ee6f0f162b5abf5e315388a7c27daa0375fb1d4f1d49baf8c31cf849af6660c0a5618cbd789763971a09a8736b08d86b0b1192af6562a0c9
7
+ data.tar.gz: 49fafc38919765e0dbba69c5799016db5df00c5459baaa37c7c54e70f3e4e26ae0ba59d580389fc99d15a69593beaaa5531e9f6b9c054085ff28ab9981fb509a
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+
16
+ # rspec failure tracking
17
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in laplace.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (C) 2017 NARUSE, Yui. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
@@ -0,0 +1,36 @@
1
+ # Laplace
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/laplace`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'laplace'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install laplace
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nurse/laplace.
36
+
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require "rake/extensiontask"
7
+
8
+ task :build => :compile
9
+
10
+ Rake::ExtensionTask.new("laplace") do |ext|
11
+ ext.lib_dir = "lib/laplace"
12
+ end
13
+
14
+ task :default => [:clobber, :compile, :spec]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "laplace"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "laplace"
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+
3
+ create_makefile("laplace/laplace")
@@ -0,0 +1,161 @@
1
+ #include "laplace.h"
2
+ #include <errno.h>
3
+ #include <fcntl.h>
4
+ #include <pthread.h>
5
+ #include <ruby/debug.h>
6
+
7
+ VALUE rb_mLaplace;
8
+
9
+ /* laplace_buf_t */
10
+ typedef struct {
11
+ char *head;
12
+ char *cur;
13
+ char *flushed;
14
+ char *end;
15
+ } laplace_buf_t;
16
+
17
+ static void
18
+ laplace_buf_init(laplace_buf_t *buf) {
19
+ size_t size = 1048576 * 5;
20
+ buf->head = malloc(size);
21
+ buf->cur = buf->head;
22
+ buf->cur = buf->head;
23
+ buf->flushed = buf->head;
24
+ buf->end = buf->head + size;
25
+ }
26
+
27
+ static void
28
+ laplace_buf_flush(laplace_buf_t *buf, int fd) {
29
+ size_t len;
30
+ int ret;
31
+ if (buf->flushed == buf->cur) {
32
+ } else if (buf->flushed < buf->cur) {
33
+ write(fd, buf->flushed, buf->cur - buf->flushed);
34
+ buf->flushed = buf->cur;
35
+ } else if (buf->flushed > buf->cur) {
36
+ #ifdef HAVE_WRITEV
37
+ #else
38
+ if (write(fd, buf->flushed, buf->end - buf->flushed) == 0) {
39
+ buf->flushed = buf->head;
40
+ }
41
+ #endif
42
+ }
43
+ }
44
+
45
+ static void
46
+ laplace_buf_write(laplace_buf_t *buf, const char *p, size_t len) {
47
+ size_t n = buf->end - buf->cur;
48
+ if (n >= len) {
49
+ memcpy(buf->flushed, p, len);
50
+ buf->flushed += len;
51
+ if (n == len) buf->flushed = buf->head;
52
+ } else {
53
+ memcpy(buf->flushed, p, n);
54
+ p += n;
55
+ len -= n;
56
+ memcpy(buf->cur, p, len);
57
+ buf->flushed = buf->head + len;
58
+ }
59
+ }
60
+
61
+ /* laplace_event_t */
62
+ typedef struct {
63
+ } laplace_event_t;
64
+
65
+ /* laplace_t */
66
+ typedef struct {
67
+ int fd;
68
+ pthread_mutex_t mutex;
69
+ laplace_buf_t buf;
70
+ } laplace_t;
71
+
72
+ static laplace_t *
73
+ laplace_new(int fd) {
74
+ laplace_t *m = malloc(sizeof(laplace_t));
75
+ pthread_mutex_init(&m->mutex, NULL);
76
+ m->fd = dup(fd);
77
+ fcntl(F_SETFL, m->fd, O_NONBLOCK);
78
+ laplace_buf_init(&m->buf);
79
+ return m;
80
+ }
81
+
82
+ static void
83
+ laplace_flush(laplace_t *m) {
84
+ if (pthread_mutex_trylock(&m->mutex) == 0) {
85
+ laplace_buf_flush(&m->buf, m->fd);
86
+ } else if (errno == EBUSY) {
87
+ /* should retry later */
88
+ } else {
89
+ fprintf(stderr, "%d: unknown errno: %s\n", errno, strerror(errno));
90
+ }
91
+ }
92
+
93
+ static void
94
+ laplace_add(laplace_t *m, laplace_event_t *e) {
95
+ if (pthread_mutex_trylock(&m->mutex) == 0) {
96
+ //laplace_buf_add(&m->buf, m->fd);
97
+ } else if (errno == EBUSY) {
98
+ /* should retry later */
99
+ } else {
100
+ fprintf(stderr, "%d: unknown errno: %s\n", errno, strerror(errno));
101
+ }
102
+ }
103
+
104
+ typedef struct {
105
+ rb_event_flag_t event;
106
+ ID id;
107
+ ID called_id;
108
+ int lineno;
109
+ //rb_thread_t *th;
110
+ VALUE path;
111
+ struct timespec time;
112
+ } lp_event_t;
113
+
114
+ static void
115
+ callback(VALUE tpval, void *data) {
116
+ VALUE io = (VALUE)data;
117
+ laplace_t *m = (laplace_t *)data;
118
+ rb_trace_arg_t *trace_arg = rb_tracearg_from_tracepoint(tpval);
119
+ //rb_event_flag_t ef = rb_tracearg_event_flag(trace_arg);
120
+ VALUE event = rb_tracearg_event(trace_arg);
121
+ VALUE path = rb_tracearg_path(trace_arg);
122
+ VALUE lineno = rb_tracearg_lineno(trace_arg);
123
+ VALUE klass = rb_tracearg_defined_class(trace_arg);
124
+ VALUE method = rb_tracearg_method_id(trace_arg);
125
+ //VALUE callee = rb_tracearg_callee_id(trace_arg);
126
+ VALUE callee = rb_funcall(tpval, rb_intern("callee_id"), 0);
127
+ rb_io_write(io, rb_sprintf("%s %s#%s %s %s:%d\n",
128
+ RSTRING_PTR(rb_sym2str(event)),
129
+ rb_class2name(klass),
130
+ RSTRING_PTR(rb_sym2str(method)),
131
+ RSTRING_PTR(rb_sym2str(callee)),
132
+ RSTRING_PTR(path), FIX2INT(lineno)
133
+ ));
134
+ }
135
+
136
+ /*
137
+ * call-seq:
138
+ * Laplace.trace(io) -> tracepoint
139
+ *
140
+ * Returns tracepoint which outputs method call and return,
141
+ * and raised exceptions.
142
+ */
143
+
144
+ static VALUE
145
+ lp_trace(VALUE dummy, VALUE io)
146
+ {
147
+ rb_event_flag_t events = RUBY_EVENT_CALL|RUBY_EVENT_C_CALL|RUBY_EVENT_RETURN|RUBY_EVENT_C_RETURN|RUBY_EVENT_RAISE;
148
+ return rb_tracepoint_new(Qnil, events, callback, (void *)io);
149
+ }
150
+
151
+ /*
152
+ * Document-class: Laplace
153
+ *
154
+ * For fast method tracing.
155
+ */
156
+ void
157
+ Init_laplace(void)
158
+ {
159
+ rb_mLaplace = rb_define_module("Laplace");
160
+ rb_define_singleton_method(rb_mLaplace, "trace", lp_trace, 1);
161
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef LAPLACE_H
2
+ #define LAPLACE_H 1
3
+
4
+ #include "ruby.h"
5
+
6
+ #endif /* LAPLACE_H */
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'laplace/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "laplace"
8
+ spec.version = Laplace::VERSION
9
+ spec.authors = ["NARUSE, Yui"]
10
+ spec.email = ["naruse@airemix.jp"]
11
+
12
+ spec.summary = %q{fast method tracing}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/nurse/laplace"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ spec.extensions = ["ext/laplace/extconf.rb"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rake-compiler"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
@@ -0,0 +1,6 @@
1
+ require "laplace/version"
2
+ require "laplace/laplace"
3
+
4
+ module Laplace
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,3 @@
1
+ module Laplace
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: laplace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - NARUSE, Yui
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: ''
70
+ email:
71
+ - naruse@airemix.jp
72
+ executables:
73
+ - laplace
74
+ extensions:
75
+ - ext/laplace/extconf.rb
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - exe/laplace
88
+ - ext/laplace/extconf.rb
89
+ - ext/laplace/laplace.c
90
+ - ext/laplace/laplace.h
91
+ - laplace.gemspec
92
+ - lib/laplace.rb
93
+ - lib/laplace/version.rb
94
+ homepage: https://github.com/nurse/laplace
95
+ licenses: []
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.11
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: fast method tracing
117
+ test_files: []