Add proto full name support for tracing.
Creates a tracing helper function to associate mini tables with proto full names to use for upcoming upb metrics collectors. PiperOrigin-RevId: 613290255pull/16021/head
parent
3d7e75fb98
commit
f2242d7136
|
@ -57,11 +57,16 @@ struct upb_MiniTable {
|
|||
uint8_t UPB_PRIVATE(dense_below);
|
||||
uint8_t UPB_PRIVATE(table_mask);
|
||||
uint8_t UPB_PRIVATE(required_count); // Required fields have the low hasbits.
|
||||
#ifdef UPB_TRACING_ENABLED
|
||||
const char* UPB_PRIVATE(full_name);
|
||||
#endif
|
||||
|
||||
#ifdef UPB_FASTTABLE_ENABLED
|
||||
// To statically initialize the tables of variable length, we need a flexible
|
||||
// array member, and we need to compile in gnu99 mode (constant initialization
|
||||
// of flexible array members is a GNU extension, not in C99 unfortunately.
|
||||
_upb_FastTable_Entry UPB_PRIVATE(fasttable)[];
|
||||
#endif
|
||||
};
|
||||
// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table.ts)
|
||||
|
||||
|
@ -154,6 +159,13 @@ UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) {
|
|||
return (1ULL << n) - 1;
|
||||
}
|
||||
|
||||
#ifdef UPB_TRACING_ENABLED
|
||||
UPB_INLINE const char* upb_MiniTable_FullName(
|
||||
const struct upb_MiniTable* mini_table) {
|
||||
return mini_table->UPB_PRIVATE(full_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
@ -344,3 +344,9 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
|||
#define UPB_DESC(sym) google_protobuf_##sym
|
||||
#define UPB_DESC_MINITABLE(sym) &google__protobuf__##sym##_msg_init
|
||||
#endif
|
||||
|
||||
#ifdef UPB_TRACING_ENABLED
|
||||
#ifdef NDEBUG
|
||||
error UPB_TRACING_ENABLED Tracing should be disabled in production builds
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -68,6 +68,7 @@ proto_library(
|
|||
name = "test_proto",
|
||||
testonly = 1,
|
||||
srcs = ["test.proto"],
|
||||
visibility = ["//upb:__subpackages__"],
|
||||
)
|
||||
|
||||
upb_minitable_proto_library(
|
||||
|
|
|
@ -339,6 +339,7 @@ void WriteMessage(upb::MessageDefPtr message, const DefPoolPair& pools,
|
|||
const upb_MiniTable* mt_64 = pools.GetMiniTable64(message);
|
||||
std::map<int, std::string> subs;
|
||||
|
||||
// Construct map of sub messages by field number.
|
||||
for (int i = 0; i < mt_64->UPB_PRIVATE(field_count); i++) {
|
||||
const upb_MiniTableField* f = &mt_64->UPB_PRIVATE(fields)[i];
|
||||
uint32_t index = f->UPB_PRIVATE(submsg_index);
|
||||
|
@ -349,7 +350,7 @@ void WriteMessage(upb::MessageDefPtr message, const DefPoolPair& pools,
|
|||
ABSL_CHECK(pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
// Write upb_MiniTableSub table for sub messages referenced from fields.
|
||||
if (!subs.empty()) {
|
||||
std::string submsgs_array_name = msg_name + "_submsgs";
|
||||
submsgs_array_ref = "&" + submsgs_array_name + "[0]";
|
||||
|
@ -365,6 +366,7 @@ void WriteMessage(upb::MessageDefPtr message, const DefPoolPair& pools,
|
|||
output("};\n\n");
|
||||
}
|
||||
|
||||
// Write upb_MiniTableField table.
|
||||
if (mt_64->UPB_PRIVATE(field_count) > 0) {
|
||||
std::string fields_array_name = msg_name + "__fields";
|
||||
fields_array_ref = "&" + fields_array_name + "[0]";
|
||||
|
@ -407,6 +409,9 @@ void WriteMessage(upb::MessageDefPtr message, const DefPoolPair& pools,
|
|||
mt_64->UPB_PRIVATE(field_count), msgext,
|
||||
mt_64->UPB_PRIVATE(dense_below), table_mask,
|
||||
mt_64->UPB_PRIVATE(required_count));
|
||||
output("#ifdef UPB_TRACING_ENABLED\n");
|
||||
output(" \"$0\",\n", message.full_name());
|
||||
output("#endif\n");
|
||||
if (!table.empty()) {
|
||||
output(" UPB_FASTTABLE_INIT({\n");
|
||||
for (const auto& ent : table) {
|
||||
|
|
Loading…
Reference in New Issue