ruby_memprofiler_pprof 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 +7 -0
- data/ext/ruby_memprofiler_pprof/backtrace.c +429 -0
- data/ext/ruby_memprofiler_pprof/collector.c +1055 -0
- data/ext/ruby_memprofiler_pprof/compat.c +182 -0
- data/ext/ruby_memprofiler_pprof/extconf.rb +72 -0
- data/ext/ruby_memprofiler_pprof/pprof.upb.c +170 -0
- data/ext/ruby_memprofiler_pprof/pprof.upb.h +848 -0
- data/ext/ruby_memprofiler_pprof/pprof_out.c +285 -0
- data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.c +11 -0
- data/ext/ruby_memprofiler_pprof/ruby_memprofiler_pprof.h +301 -0
- data/ext/ruby_memprofiler_pprof/strtab.c +391 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/BUILD +719 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/CONTRIBUTING.md +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/DESIGN.md +201 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/LICENSE +26 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/README.md +78 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/WORKSPACE +58 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/BUILD +53 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/amalgamate.py +129 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/build_defs.bzl +160 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/lua.BUILD +127 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/protobuf.patch +54 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/py_proto_library.bzl +137 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/python_downloads.bzl +84 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/system_python.bzl +101 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/upb_proto_library.bzl +388 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/bazel/workspace_deps.bzl +89 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD +252 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/BUILD.googleapis +54 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/benchmark.cc +333 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/build_defs.bzl +88 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/compare.py +118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor.proto +888 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/descriptor_sv.proto +890 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/empty.proto +6 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_protobuf_binary_cc.py +64 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_synthetic_protos.py +118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/benchmarks/gen_upb_binary_c.py +65 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/BUILD.bazel +102 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/README.md +23 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/build_defs.bzl +73 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/make_cmakelists.py +340 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test.py +57 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/cmake/staleness_test_lib.py +186 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/render.py +43 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/style-guide.md +65 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/vs-cpp-protos.md +255 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/docs/wrapping-upb.md +444 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/BUILD +216 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.c +394 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/convert.h +63 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.c +1694 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor.h +80 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.c +704 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_containers.h +114 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.c +650 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/descriptor_pool.h +48 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/BUILD.bazel +193 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/dist/dist.bzl +190 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.c +247 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/extension_dict.h +39 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.c +522 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/map.h +66 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.c +1909 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/message.h +101 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/minimal_test.py +183 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/BUILD +70 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/README.md +11 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_database_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_pool_test_wrapper.py +45 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/descriptor_test_wrapper.py +46 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/generator_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/json_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/keywords_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_factory_test_wrapper.py +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/message_test_wrapper.py +52 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/proto_builder_test_wrapper.py +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/pyproto_test_wrapper.bzl +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/reflection_test_wrapper.py +45 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/service_reflection_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/symbol_database_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_encoding_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/text_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/unknown_fields_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/well_known_types_test_wrapper.py +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/pb_unit_tests/wire_format_test_wrapper.py +30 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.c +350 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/protobuf.h +230 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/py_extension.bzl +55 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/python_api.h +61 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.c +828 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/repeated.h +69 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.c +404 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/unknown_fields.h +39 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/python/version_script.lds +6 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/LICENSE +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/README.google +9 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/console.lua +156 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/lunit/lunit.lua +725 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/BUILD +19 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/LICENSE +21 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/naive.c +92 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-neon.c +157 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/range2-sse.c +170 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/third_party/utf8_range/utf8_range.h +9 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/BUILD.bazel +129 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/README.md +8 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/def.c +939 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/lua_proto_library.bzl +138 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/main.c +83 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/msg.c +1118 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test.proto +69 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/test_upb.lua +846 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.c +258 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.h +132 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upb.lua +58 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/bindings/lua/upbc.cc +134 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.c +192 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/collections.h +174 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb.c +346 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/conformance_upb_failures.txt +1 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.c +1221 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode.h +94 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.c +1055 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_fast.h +153 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/decode_internal.h +211 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.c +3262 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.h +414 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/def.hpp +438 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/empty.proto +1 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.c +604 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/encode.h +71 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/BUILD +13 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/fuzz/file_descriptor_parsenew_fuzzer.cc +43 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.c +1509 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_decode.h +47 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.c +776 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/json_encode.h +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.c +1147 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.h +189 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table.hpp +112 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.c +363 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors.h +263 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_internal.h +59 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_accessors_test.cc +425 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/mini_table_test.cc +230 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.c +428 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg.h +114 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_internal.h +836 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.cc +491 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/msg_test.proto +195 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_def.inc +261 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/port_undef.inc +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.c +323 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.h +109 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/reflection.hpp +37 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table.c +926 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/table_internal.h +385 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test.proto +74 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.cc +186 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_cpp.proto +12 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_generated_code.cc +977 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/test_table.cc +580 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.c +472 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/text_encode.h +64 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.c +362 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.h +378 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb.hpp +115 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/upb_internal.h +68 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/BUILD +121 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/README.md +7 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.c +300 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare.h +66 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/compare_test.cc +236 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.c +572 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto.h +62 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_public_import_test.proto +32 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_regular_import_test.proto +36 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.cc +143 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_test.proto +119 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_weak_import_test.proto +28 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/def_to_proto_wweak_import_test.proto +28 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.c +311 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields.h +94 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.cc +202 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upb/util/required_fields_test.proto +48 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/BUILD +78 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.cc +77 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/common.h +112 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upb.cc +1997 -0
- data/ext/ruby_memprofiler_pprof/vendor/upb/upbc/protoc-gen-upbdefs.cc +193 -0
- data/lib/ruby_memprofiler_pprof/atfork.rb +77 -0
- data/lib/ruby_memprofiler_pprof/block_flusher.rb +61 -0
- data/lib/ruby_memprofiler_pprof/file_flusher.rb +45 -0
- data/lib/ruby_memprofiler_pprof/profile_app.rb +30 -0
- data/lib/ruby_memprofiler_pprof/profile_data.rb +18 -0
- data/lib/ruby_memprofiler_pprof/version.rb +5 -0
- data/lib/ruby_memprofiler_pprof.rb +8 -0
- data/libexec/ruby_memprofiler_pprof_profile +16 -0
- metadata +257 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// Copyright (c) 2009-2021, Google LLC
|
|
2
|
+
// All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// Redistribution and use in source and binary forms, with or without
|
|
5
|
+
// modification, are permitted provided that the following conditions are met:
|
|
6
|
+
// * Redistributions of source code must retain the above copyright
|
|
7
|
+
// notice, this list of conditions and the following disclaimer.
|
|
8
|
+
// * 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
|
+
// * Neither the name of Google LLC nor the
|
|
12
|
+
// names of its contributors may be used to endorse or promote products
|
|
13
|
+
// derived from this software without specific prior written permission.
|
|
14
|
+
//
|
|
15
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
16
|
+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
17
|
+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
18
|
+
// ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
|
|
19
|
+
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
20
|
+
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
21
|
+
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
22
|
+
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
23
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
24
|
+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
25
|
+
|
|
26
|
+
#include <memory>
|
|
27
|
+
|
|
28
|
+
#include "google/protobuf/compiler/code_generator.h"
|
|
29
|
+
#include "google/protobuf/compiler/plugin.h"
|
|
30
|
+
#include "google/protobuf/descriptor.h"
|
|
31
|
+
#include "google/protobuf/descriptor.pb.h"
|
|
32
|
+
#include "upbc/common.h"
|
|
33
|
+
|
|
34
|
+
namespace upbc {
|
|
35
|
+
namespace {
|
|
36
|
+
|
|
37
|
+
namespace protoc = ::google::protobuf::compiler;
|
|
38
|
+
namespace protobuf = ::google::protobuf;
|
|
39
|
+
|
|
40
|
+
std::string DefInitSymbol(const protobuf::FileDescriptor* file) {
|
|
41
|
+
return ToCIdent(file->name()) + "_upbdefinit";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static std::string DefHeaderFilename(std::string proto_filename) {
|
|
45
|
+
return StripExtension(proto_filename) + ".upbdefs.h";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static std::string DefSourceFilename(std::string proto_filename) {
|
|
49
|
+
return StripExtension(proto_filename) + ".upbdefs.c";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void GenerateMessageDefAccessor(const protobuf::Descriptor* d, Output& output) {
|
|
53
|
+
output("UPB_INLINE const upb_MessageDef *$0_getmsgdef(upb_DefPool *s) {\n",
|
|
54
|
+
ToCIdent(d->full_name()));
|
|
55
|
+
output(" _upb_DefPool_LoadDefInit(s, &$0);\n", DefInitSymbol(d->file()));
|
|
56
|
+
output(" return upb_DefPool_FindMessageByName(s, \"$0\");\n",
|
|
57
|
+
d->full_name());
|
|
58
|
+
output("}\n");
|
|
59
|
+
output("\n");
|
|
60
|
+
|
|
61
|
+
for (int i = 0; i < d->nested_type_count(); i++) {
|
|
62
|
+
GenerateMessageDefAccessor(d->nested_type(i), output);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void WriteDefHeader(const protobuf::FileDescriptor* file, Output& output) {
|
|
67
|
+
EmitFileWarning(file, output);
|
|
68
|
+
|
|
69
|
+
output(
|
|
70
|
+
"#ifndef $0_UPBDEFS_H_\n"
|
|
71
|
+
"#define $0_UPBDEFS_H_\n\n"
|
|
72
|
+
"#include \"upb/def.h\"\n"
|
|
73
|
+
"#include \"upb/port_def.inc\"\n"
|
|
74
|
+
"#ifdef __cplusplus\n"
|
|
75
|
+
"extern \"C\" {\n"
|
|
76
|
+
"#endif\n\n",
|
|
77
|
+
ToPreproc(file->name()));
|
|
78
|
+
|
|
79
|
+
output("#include \"upb/def.h\"\n");
|
|
80
|
+
output("\n");
|
|
81
|
+
output("#include \"upb/port_def.inc\"\n");
|
|
82
|
+
output("\n");
|
|
83
|
+
|
|
84
|
+
output("extern _upb_DefPool_Init $0;\n", DefInitSymbol(file));
|
|
85
|
+
output("\n");
|
|
86
|
+
|
|
87
|
+
for (int i = 0; i < file->message_type_count(); i++) {
|
|
88
|
+
GenerateMessageDefAccessor(file->message_type(i), output);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
output(
|
|
92
|
+
"#ifdef __cplusplus\n"
|
|
93
|
+
"} /* extern \"C\" */\n"
|
|
94
|
+
"#endif\n"
|
|
95
|
+
"\n"
|
|
96
|
+
"#include \"upb/port_undef.inc\"\n"
|
|
97
|
+
"\n"
|
|
98
|
+
"#endif /* $0_UPBDEFS_H_ */\n",
|
|
99
|
+
ToPreproc(file->name()));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
void WriteDefSource(const protobuf::FileDescriptor* file, Output& output) {
|
|
103
|
+
EmitFileWarning(file, output);
|
|
104
|
+
|
|
105
|
+
output("#include \"upb/def.h\"\n");
|
|
106
|
+
output("#include \"$0\"\n", DefHeaderFilename(file->name()));
|
|
107
|
+
output("#include \"$0\"\n", HeaderFilename(file));
|
|
108
|
+
output("\n");
|
|
109
|
+
|
|
110
|
+
for (int i = 0; i < file->dependency_count(); i++) {
|
|
111
|
+
output("extern _upb_DefPool_Init $0;\n",
|
|
112
|
+
DefInitSymbol(file->dependency(i)));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
protobuf::FileDescriptorProto file_proto;
|
|
116
|
+
file->CopyTo(&file_proto);
|
|
117
|
+
std::string file_data;
|
|
118
|
+
file_proto.SerializeToString(&file_data);
|
|
119
|
+
|
|
120
|
+
output("static const char descriptor[$0] = {", file_data.size());
|
|
121
|
+
|
|
122
|
+
// C90 only guarantees that strings can be up to 509 characters, and some
|
|
123
|
+
// implementations have limits here (for example, MSVC only allows 64k:
|
|
124
|
+
// https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/fatal-error-c1091.
|
|
125
|
+
// So we always emit an array instead of a string.
|
|
126
|
+
for (size_t i = 0; i < file_data.size();) {
|
|
127
|
+
for (size_t j = 0; j < 25 && i < file_data.size(); ++i, ++j) {
|
|
128
|
+
output("'$0', ", absl::CEscape(file_data.substr(i, 1)));
|
|
129
|
+
}
|
|
130
|
+
output("\n");
|
|
131
|
+
}
|
|
132
|
+
output("};\n\n");
|
|
133
|
+
|
|
134
|
+
output("static _upb_DefPool_Init *deps[$0] = {\n",
|
|
135
|
+
file->dependency_count() + 1);
|
|
136
|
+
for (int i = 0; i < file->dependency_count(); i++) {
|
|
137
|
+
output(" &$0,\n", DefInitSymbol(file->dependency(i)));
|
|
138
|
+
}
|
|
139
|
+
output(" NULL\n");
|
|
140
|
+
output("};\n");
|
|
141
|
+
output("\n");
|
|
142
|
+
|
|
143
|
+
output("_upb_DefPool_Init $0 = {\n", DefInitSymbol(file));
|
|
144
|
+
output(" deps,\n");
|
|
145
|
+
output(" &$0,\n", FileLayoutName(file));
|
|
146
|
+
output(" \"$0\",\n", file->name());
|
|
147
|
+
output(" UPB_STRINGVIEW_INIT(descriptor, $0)\n", file_data.size());
|
|
148
|
+
output("};\n");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
class Generator : public protoc::CodeGenerator {
|
|
152
|
+
~Generator() override {}
|
|
153
|
+
bool Generate(const protobuf::FileDescriptor* file,
|
|
154
|
+
const std::string& parameter, protoc::GeneratorContext* context,
|
|
155
|
+
std::string* error) const override;
|
|
156
|
+
uint64_t GetSupportedFeatures() const override {
|
|
157
|
+
return FEATURE_PROTO3_OPTIONAL;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
bool Generator::Generate(const protobuf::FileDescriptor* file,
|
|
162
|
+
const std::string& parameter,
|
|
163
|
+
protoc::GeneratorContext* context,
|
|
164
|
+
std::string* error) const {
|
|
165
|
+
std::vector<std::pair<std::string, std::string>> params;
|
|
166
|
+
google::protobuf::compiler::ParseGeneratorParameter(parameter, ¶ms);
|
|
167
|
+
|
|
168
|
+
for (const auto& pair : params) {
|
|
169
|
+
*error = "Unknown parameter: " + pair.first;
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
std::unique_ptr<protobuf::io::ZeroCopyOutputStream> h_output_stream(
|
|
174
|
+
context->Open(DefHeaderFilename(file->name())));
|
|
175
|
+
Output h_def_output(h_output_stream.get());
|
|
176
|
+
WriteDefHeader(file, h_def_output);
|
|
177
|
+
|
|
178
|
+
std::unique_ptr<protobuf::io::ZeroCopyOutputStream> c_output_stream(
|
|
179
|
+
context->Open(DefSourceFilename(file->name())));
|
|
180
|
+
Output c_def_output(c_output_stream.get());
|
|
181
|
+
WriteDefSource(file, c_def_output);
|
|
182
|
+
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
} // namespace
|
|
187
|
+
} // namespace upbc
|
|
188
|
+
|
|
189
|
+
int main(int argc, char** argv) {
|
|
190
|
+
std::unique_ptr<google::protobuf::compiler::CodeGenerator> generator(
|
|
191
|
+
new upbc::Generator());
|
|
192
|
+
return google::protobuf::compiler::PluginMain(argc, argv, generator.get());
|
|
193
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# A mechanism for adding atfork handlers, so that background profile flushing threads
|
|
4
|
+
# can re-create themselves in forked children.
|
|
5
|
+
# Mostly ripped off from the Datadog one here:
|
|
6
|
+
# https://github.com/DataDog/dd-trace-rb/blob/master/lib/datadog/profiling/ext/forking.rb
|
|
7
|
+
|
|
8
|
+
module MemprofilerPprof
|
|
9
|
+
module Atfork
|
|
10
|
+
class Handler
|
|
11
|
+
attr_accessor :block
|
|
12
|
+
attr_accessor :stage
|
|
13
|
+
|
|
14
|
+
def call
|
|
15
|
+
block.call
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def remove!
|
|
19
|
+
Atfork.at_fork_handlers.reject! { |h| h === self }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
module_function
|
|
24
|
+
def at_fork_handlers
|
|
25
|
+
@@at_fork_handlers ||= []
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def at_fork(stage = :prepare, &block)
|
|
29
|
+
handler = Handler.new.tap do |h|
|
|
30
|
+
h.block = block
|
|
31
|
+
h.stage = stage
|
|
32
|
+
end
|
|
33
|
+
at_fork_handlers << handler
|
|
34
|
+
handler
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def fork
|
|
38
|
+
# If a block is provided, it must be wrapped to trigger callbacks.
|
|
39
|
+
child_block = if block_given?
|
|
40
|
+
proc do
|
|
41
|
+
# Trigger :child callback
|
|
42
|
+
at_fork_handlers.select { |h| h.stage == :child }.each(&:call)
|
|
43
|
+
|
|
44
|
+
# Invoke original block
|
|
45
|
+
yield
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Trigger :prepare callback
|
|
50
|
+
at_fork_handlers.select { |h| h.stage == :prepare }.each(&:call)
|
|
51
|
+
|
|
52
|
+
# Start fork
|
|
53
|
+
# If a block is provided, use the wrapped version.
|
|
54
|
+
result = child_block.nil? ? super : super(&child_block)
|
|
55
|
+
|
|
56
|
+
# Trigger correct callbacks depending on whether we're in the parent or child.
|
|
57
|
+
# If we're in the fork, result = nil: trigger child callbacks.
|
|
58
|
+
# If we're in the parent, result = fork PID: trigger parent callbacks.
|
|
59
|
+
# rubocop:disable Style/IfInsideElse
|
|
60
|
+
if result.nil?
|
|
61
|
+
# Trigger :child callback
|
|
62
|
+
at_fork_handlers.select { |h| h.stage == :child }.each(&:call)
|
|
63
|
+
else
|
|
64
|
+
# Trigger :parent callback
|
|
65
|
+
at_fork_handlers.select { |h| h.stage == :parent }.each(&:call)
|
|
66
|
+
end
|
|
67
|
+
# rubocop:enable Style/IfInsideElse
|
|
68
|
+
|
|
69
|
+
# Return PID from #fork
|
|
70
|
+
result
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
::Process.singleton_class.prepend(MemprofilerPprof::Atfork)
|
|
76
|
+
::Kernel.singleton_class.prepend(MemprofilerPprof::Atfork)
|
|
77
|
+
TOPLEVEL_BINDING.receiver.class.prepend(MemprofilerPprof::Atfork)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module MemprofilerPprof
|
|
4
|
+
class BlockFlusher
|
|
5
|
+
attr_reader :collector
|
|
6
|
+
|
|
7
|
+
def initialize(collector, interval: 30, logger: nil, on_flush: nil)
|
|
8
|
+
@collector = collector
|
|
9
|
+
@interval = interval
|
|
10
|
+
@logger = logger
|
|
11
|
+
@thread = nil
|
|
12
|
+
@on_flush = on_flush
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def start!
|
|
16
|
+
stop!
|
|
17
|
+
@thread = Thread.new { flusher_thread }
|
|
18
|
+
@atfork_handler = MemprofilerPprof::Atfork.at_fork(:child, &method(:at_fork_in_child))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def stop!
|
|
22
|
+
@thread&.kill
|
|
23
|
+
@thread&.join
|
|
24
|
+
@thread = nil
|
|
25
|
+
@atfork_handler&.remove!
|
|
26
|
+
@atfork_handler = nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def run
|
|
30
|
+
start!
|
|
31
|
+
begin
|
|
32
|
+
yield
|
|
33
|
+
ensure
|
|
34
|
+
stop!
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def flusher_thread
|
|
41
|
+
prev_flush_duration = 0
|
|
42
|
+
loop do
|
|
43
|
+
sleep([0, @interval - prev_flush_duration].max)
|
|
44
|
+
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
45
|
+
begin
|
|
46
|
+
profile_data = @collector.flush
|
|
47
|
+
@on_flush&.call(profile_data)
|
|
48
|
+
rescue => e
|
|
49
|
+
@logger&.error("BaseFlusher: failed to flush profiling data: #{e.inspect}")
|
|
50
|
+
ensure
|
|
51
|
+
t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
52
|
+
prev_flush_duration = (t2 - t1)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def at_fork_in_child
|
|
58
|
+
start! if @thread && !@thread.alive?
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'forwardable'
|
|
5
|
+
|
|
6
|
+
module MemprofilerPprof
|
|
7
|
+
class FileFlusher
|
|
8
|
+
extend Forwardable
|
|
9
|
+
|
|
10
|
+
def initialize(collector, pattern: 'tmp/profiles/mem-%{pid}-%{isotime}.pprof', interval: 30, logger: nil)
|
|
11
|
+
@logger = logger
|
|
12
|
+
@pattern = pattern
|
|
13
|
+
@profile_counter = 0
|
|
14
|
+
@block_flusher = BlockFlusher.new(collector, interval: interval, logger: logger, on_flush: method(:on_flush))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def_delegators :@block_flusher, :start!, :stop!, :run
|
|
18
|
+
attr_accessor :pattern
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def on_flush(profile_data)
|
|
23
|
+
fname = template_string(@pattern)
|
|
24
|
+
dirname = File.dirname(fname)
|
|
25
|
+
FileUtils.mkdir_p dirname
|
|
26
|
+
# Need to explicitly specify the encoding, because some applications might do exotic
|
|
27
|
+
# things to File#default_external/#default_internal that would attempt to convert
|
|
28
|
+
# our protobuf to UTF-8.
|
|
29
|
+
File.write(template_string(@pattern), profile_data.pprof_data, encoding: 'ASCII-8BIT')
|
|
30
|
+
@profile_counter += 1
|
|
31
|
+
rescue => e
|
|
32
|
+
@logger&.error("FileFlusher: failed to flush profiling data: #{e.inspect}")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def template_string(tmpl)
|
|
36
|
+
vars = {
|
|
37
|
+
pid: Process.pid,
|
|
38
|
+
isotime: Time.now.iso8601,
|
|
39
|
+
unixtime: Time.now.to_i,
|
|
40
|
+
index: @profile_counter,
|
|
41
|
+
}
|
|
42
|
+
sprintf(tmpl, vars)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# This file gets loaded by libexec/ruby_memprofiler_pprof_profile as part
|
|
4
|
+
# of RUBYOPTS for a child process. This means we're going to run in some target
|
|
5
|
+
# process _before_ any of the app code is run. Our job here is to set up
|
|
6
|
+
# heap profiling in some default way.
|
|
7
|
+
|
|
8
|
+
require 'logger'
|
|
9
|
+
require 'ruby_memprofiler_pprof'
|
|
10
|
+
|
|
11
|
+
collector = MemprofilerPprof::Collector.new
|
|
12
|
+
collector.sample_rate = ENV.fetch('RUBY_MEMPROFILER_PPROF_SAMPLE_RATE', '1').to_f
|
|
13
|
+
collector.allocation_retain_rate = ENV.fetch('RUBY_MEMPROFILER_PPROF_ALLOC_RETAIN_RATE', '1').to_f
|
|
14
|
+
if ENV.key?('RUBY_MEMPROFILER_PPROF_MAX_ALLOC_SAMPLES')
|
|
15
|
+
collector.max_allocation_samples = ENV['RUBY_MEMPROFILER_PPROF_MAX_ALLOC_SAMPLES'].to_i
|
|
16
|
+
end
|
|
17
|
+
if ENV.key?('RUBY_MEMPROFILER_PPROF_MAX_HEAP_SAMPLES')
|
|
18
|
+
collector.max_heap_samples = ENV['RUBY_MEMPROFILER_PPROF_MAX_HEAP_SAMPLES'].to_i
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
kwargs = {
|
|
22
|
+
logger: Logger.new(STDERR)
|
|
23
|
+
}
|
|
24
|
+
if ENV.key?('RUBY_MEMPROFILER_PPROF_FILE_PATTERN')
|
|
25
|
+
kwargs[:pattern] = ENV['RUBY_MEMPROFILER_PPROF_FILE_PATTERN']
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
flusher = MemprofilerPprof::FileFlusher.new(collector, **kwargs)
|
|
29
|
+
collector.start!
|
|
30
|
+
flusher.start!
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module MemprofilerPprof
|
|
4
|
+
class ProfileData
|
|
5
|
+
attr_accessor :pprof_data, :allocation_samples_count, :heap_samples_count,
|
|
6
|
+
:dropped_samples_nolock, :dropped_samples_allocation_bufsize, :dropped_samples_heap_bufsize
|
|
7
|
+
|
|
8
|
+
def to_s
|
|
9
|
+
"<MemprofilerPprof::ProfileData:#{object_id.to_s(16)} (sample counts: " +
|
|
10
|
+
"allocation=#{allocation_samples_count}, " +
|
|
11
|
+
"heap=#{heap_samples_count}, " +
|
|
12
|
+
"dropped_nolock=#{dropped_samples_nolock}, " +
|
|
13
|
+
"dropped_allocation_bufsize=#{dropped_samples_allocation_bufsize}, " +
|
|
14
|
+
"dropped_heap_bufsize=#{dropped_samples_heap_bufsize}" +
|
|
15
|
+
")>"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "ruby_memprofiler_pprof/version"
|
|
4
|
+
require "ruby_memprofiler_pprof/profile_data"
|
|
5
|
+
require "ruby_memprofiler_pprof/ruby_memprofiler_pprof_ext"
|
|
6
|
+
require 'ruby_memprofiler_pprof/atfork'
|
|
7
|
+
require 'ruby_memprofiler_pprof/block_flusher'
|
|
8
|
+
require 'ruby_memprofiler_pprof/file_flusher'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Simply starts the provided program as-is, but sets RUBYLIB so that it will be
|
|
5
|
+
# profiled by ruby_memprofiler_pprof.
|
|
6
|
+
|
|
7
|
+
require 'shellwords'
|
|
8
|
+
|
|
9
|
+
base_path = File.expand_path("../lib", __dir__)
|
|
10
|
+
profile_lib = File.join(base_path, 'ruby_memprofiler_pprof', 'profile_app.rb')
|
|
11
|
+
opts = [
|
|
12
|
+
"-I#{Shellwords.escape base_path}",
|
|
13
|
+
"-r#{Shellwords.escape profile_lib}"
|
|
14
|
+
]
|
|
15
|
+
ENV['RUBYOPT'] = ([ENV.fetch('RUBYOPT', nil)] + opts).compact.join(" ")
|
|
16
|
+
exec *ARGV
|