valgrind 0.0.0 → 0.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4c8be38a432e5ceff7bebd2c75c2d1507685b99b0e8ac7427048aef0c4b2beb
4
- data.tar.gz: dae5536d6035f67546136f12ffe1fc52d602bdffc8dd5eeba120fec2313c4cd7
3
+ metadata.gz: af95f1fc8df6aa9b4e3280a38d634e4c6556870fc11106e718c2dff5aa69973e
4
+ data.tar.gz: 96251e4b25209fa8f083c2b271a251bf495a1b8e4b137bb47da1f1601d39b0fc
5
5
  SHA512:
6
- metadata.gz: 199c7cc4d4da63d7ee6491e14f8bf95f41489d49c591e1caa7fe436850b470e680038e97f363fb6c29689d5c45699a37cffb4fe970135369f05a8b3953474f9d
7
- data.tar.gz: 8cf8d948c812075b068479e25737a0d43999831f2dea87a018d6d62fe8c1049d96bb27076f88173ed91d4bd4ae1939669d768402ee9e8ce8e5c215c14014d909
6
+ metadata.gz: 25f9757ee618417b4b6104bb2dc1ec878e79fe8d20b4559efae3aa9fe08f249eca122b2aa47088eca93731faf2d718cee3a92c350f461c18964eccdd48b8e368
7
+ data.tar.gz: f9af638c310880355594d336c4f3735606ac5eca860c2dd5afeaec40bd0ca14d02f31a5611b5228b31e250af048a209ac88e78c33428a961ced039a89b4f6a85
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Max Bernstein
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # `valgrind`
2
+
3
+ Control callgrind instrumentation from Ruby. A port of
4
+ [tekknolagi/valgrind](https://github.com/tekknolagi/valgrind) (Python).
5
+
6
+ ## Usage
7
+
8
+ Run `gem install valgrind`.
9
+
10
+ In `benchmark.rb` put:
11
+
12
+ ```ruby
13
+ require "valgrind"
14
+
15
+ some_startup_code
16
+ Valgrind.callgrind_start_instrumentation
17
+ some_expensive_function
18
+ Valgrind.callgrind_stop_instrumentation
19
+ Valgrind.callgrind_dump_stats("myprofile")
20
+ ```
21
+
22
+ Run `valgrind --tool=callgrind --instr-atstart=no ruby benchmark.rb`.
23
+
24
+ See profile in `myprofile` file. Consider opening with KCachegrind or
25
+ QCachegrind.
26
+
27
+ ## API
28
+
29
+ All methods are module functions on `Valgrind` and return `nil`. Outside of
30
+ valgrind the underlying client requests are no-ops.
31
+
32
+ - `Valgrind.callgrind_start_instrumentation`
33
+ - `Valgrind.callgrind_stop_instrumentation`
34
+ - `Valgrind.callgrind_zero_stats`
35
+ - `Valgrind.callgrind_dump_stats(description = nil)`
36
+
37
+ ## Development
38
+
39
+ ```sh
40
+ bundle install
41
+ bundle exec rake # compile + test
42
+ ```
43
+
44
+ ## Authors
45
+
46
+ Matthias Braun (original C), Max Bernstein
@@ -0,0 +1,129 @@
1
+
2
+ /*
3
+ ----------------------------------------------------------------
4
+
5
+ Notice that the following BSD-style license applies to this one
6
+ file (callgrind.h) only. The rest of Valgrind is licensed under the
7
+ terms of the GNU General Public License, version 2, unless
8
+ otherwise indicated. See the COPYING file in the source
9
+ distribution for details.
10
+
11
+ ----------------------------------------------------------------
12
+
13
+ This file is part of callgrind, a valgrind tool for cache simulation
14
+ and call tree tracing.
15
+
16
+ Copyright (C) 2003-2017 Josef Weidendorfer. All rights reserved.
17
+
18
+ Redistribution and use in source and binary forms, with or without
19
+ modification, are permitted provided that the following conditions
20
+ are met:
21
+
22
+ 1. Redistributions of source code must retain the above copyright
23
+ notice, this list of conditions and the following disclaimer.
24
+
25
+ 2. The origin of this software must not be misrepresented; you must
26
+ not claim that you wrote the original software. If you use this
27
+ software in a product, an acknowledgment in the product
28
+ documentation would be appreciated but is not required.
29
+
30
+ 3. Altered source versions must be plainly marked as such, and must
31
+ not be misrepresented as being the original software.
32
+
33
+ 4. The name of the author may not be used to endorse or promote
34
+ products derived from this software without specific prior written
35
+ permission.
36
+
37
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
38
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
39
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
41
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
43
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
45
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
46
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48
+
49
+ ----------------------------------------------------------------
50
+
51
+ Notice that the above BSD-style license applies to this one file
52
+ (callgrind.h) only. The entire rest of Valgrind is licensed under
53
+ the terms of the GNU General Public License, version 2. See the
54
+ COPYING file in the source distribution for details.
55
+
56
+ ----------------------------------------------------------------
57
+ */
58
+
59
+ #ifndef __CALLGRIND_H
60
+ #define __CALLGRIND_H
61
+
62
+ #include "valgrind.h"
63
+
64
+ /* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
65
+ This enum comprises an ABI exported by Valgrind to programs
66
+ which use client requests. DO NOT CHANGE THE ORDER OF THESE
67
+ ENTRIES, NOR DELETE ANY -- add new ones at the end.
68
+
69
+ The identification ('C','T') for Callgrind has historical
70
+ reasons: it was called "Calltree" before. Besides, ('C','G') would
71
+ clash with cachegrind.
72
+ */
73
+
74
+ typedef
75
+ enum {
76
+ VG_USERREQ__DUMP_STATS = VG_USERREQ_TOOL_BASE('C','T'),
77
+ VG_USERREQ__ZERO_STATS,
78
+ VG_USERREQ__TOGGLE_COLLECT,
79
+ VG_USERREQ__DUMP_STATS_AT,
80
+ VG_USERREQ__START_INSTRUMENTATION,
81
+ VG_USERREQ__STOP_INSTRUMENTATION
82
+ } Vg_CallgrindClientRequest;
83
+
84
+ /* Dump current state of cost centers, and zero them afterwards */
85
+ #define CALLGRIND_DUMP_STATS \
86
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DUMP_STATS, \
87
+ 0, 0, 0, 0, 0)
88
+
89
+ /* Dump current state of cost centers, and zero them afterwards.
90
+ The argument is appended to a string stating the reason which triggered
91
+ the dump. This string is written as a description field into the
92
+ profile data dump. */
93
+ #define CALLGRIND_DUMP_STATS_AT(pos_str) \
94
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DUMP_STATS_AT, \
95
+ pos_str, 0, 0, 0, 0)
96
+
97
+ /* Zero cost centers */
98
+ #define CALLGRIND_ZERO_STATS \
99
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__ZERO_STATS, \
100
+ 0, 0, 0, 0, 0)
101
+
102
+ /* Toggles collection state.
103
+ The collection state specifies whether the happening of events
104
+ should be noted or if they are to be ignored. Events are noted
105
+ by increment of counters in a cost center */
106
+ #define CALLGRIND_TOGGLE_COLLECT \
107
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__TOGGLE_COLLECT, \
108
+ 0, 0, 0, 0, 0)
109
+
110
+ /* Start full callgrind instrumentation if not already switched on.
111
+ When cache simulation is done, it will flush the simulated cache;
112
+ this will lead to an artificial cache warmup phase afterwards with
113
+ cache misses which would not have happened in reality. */
114
+ #define CALLGRIND_START_INSTRUMENTATION \
115
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__START_INSTRUMENTATION, \
116
+ 0, 0, 0, 0, 0)
117
+
118
+ /* Stop full callgrind instrumentation if not already switched off.
119
+ This flushes Valgrinds translation cache, and does no additional
120
+ instrumentation afterwards, which effectivly will run at the same
121
+ speed as the "none" tool (ie. at minimal slowdown).
122
+ Use this to bypass Callgrind aggregation for uninteresting code parts.
123
+ To start Callgrind in this mode to ignore the setup phase, use
124
+ the option "--instr-atstart=no". */
125
+ #define CALLGRIND_STOP_INSTRUMENTATION \
126
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STOP_INSTRUMENTATION, \
127
+ 0, 0, 0, 0, 0)
128
+
129
+ #endif /* __CALLGRIND_H */
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+
5
+ $INCFLAGS << " -I#{File.expand_path(__dir__)}"
6
+
7
+ create_makefile("valgrind/valgrind")
@@ -0,0 +1,46 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com)
2
+ // Originally authored by Matthias Braun for Python; ported to Ruby.
3
+ #include <ruby.h>
4
+
5
+ #include "callgrind.h"
6
+
7
+ static VALUE callgrind_dump_stats(int argc, VALUE *argv, VALUE self) {
8
+ VALUE description = Qnil;
9
+ rb_scan_args(argc, argv, "01", &description);
10
+
11
+ if (NIL_P(description)) {
12
+ CALLGRIND_DUMP_STATS;
13
+ } else {
14
+ const char *str = StringValueCStr(description);
15
+ CALLGRIND_DUMP_STATS_AT(str);
16
+ (void)str; // No-op on platforms valgrind.h does not support.
17
+ }
18
+ return Qnil;
19
+ }
20
+
21
+ static VALUE callgrind_start_instrumentation(VALUE self) {
22
+ CALLGRIND_START_INSTRUMENTATION;
23
+ return Qnil;
24
+ }
25
+
26
+ static VALUE callgrind_stop_instrumentation(VALUE self) {
27
+ CALLGRIND_STOP_INSTRUMENTATION;
28
+ return Qnil;
29
+ }
30
+
31
+ static VALUE callgrind_zero_stats(VALUE self) {
32
+ CALLGRIND_ZERO_STATS;
33
+ return Qnil;
34
+ }
35
+
36
+ void Init_valgrind(void) {
37
+ VALUE mValgrind = rb_define_module("Valgrind");
38
+ rb_define_module_function(mValgrind, "callgrind_dump_stats",
39
+ callgrind_dump_stats, -1);
40
+ rb_define_module_function(mValgrind, "callgrind_start_instrumentation",
41
+ callgrind_start_instrumentation, 0);
42
+ rb_define_module_function(mValgrind, "callgrind_stop_instrumentation",
43
+ callgrind_stop_instrumentation, 0);
44
+ rb_define_module_function(mValgrind, "callgrind_zero_stats",
45
+ callgrind_zero_stats, 0);
46
+ }