MCPcopy Create free account
hub / github.com/Snapchat/Valdi / enableTSNForModule

Method enableTSNForModule

valdi/src/valdi/runtime/ValdiRuntimeTweaks.cpp:62–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62bool ValdiRuntimeTweaks::enableTSNForModule(const StringBox& moduleName) const {
63 auto const key = StringCache::getGlobal().makeStringFromLiteral(std::string_view("VALDI_TSN_ENABLED_MODULES"));
64 auto const fallback = Value(makeShared<ValueTypedArray>(TypedArrayType::Uint8Array, Valdi::BytesView()));
65
66 Value binary = _tweakValueProvider->getBinary(key, fallback);
67
68 // If configured (has at least one per-module config, use per-module config)
69 if (binary.isTypedArray()) {
70 const ValueTypedArray* array = binary.getTypedArray();
71 const BytesView& bytes = array->getBuffer();
72
73 Valdi::TsnConfig tsnConfig;
74 bool parsed = tsnConfig.ParseFromArray(bytes.data(), static_cast<int>(bytes.size()));
75
76 if (parsed) {
77 // trivial first pass because this is only used for a very small number of elements
78 for (const auto& module : tsnConfig.enabled_modules()) {
79 if (moduleName.hasPrefix(module.c_str())) {
80 Valdi::ConsoleLogger::getLogger().log(
81 Valdi::LogTypeDebug, fmt::format("TSN enabled for module: {} ", moduleName.slowToString()));
82 return true; // prefix match success
83 }
84 }
85 // has configured modules, but not a match, return false
86 // not configured (empty list), return true
87 return tsnConfig.enabled_modules_size() == 0;
88 }
89 }
90 // If not configured(null, failing to parse), return true
91 // (fallback to global tsn config)
92 return true;
93}
94
95bool ValdiRuntimeTweaks::shouldCrashOnANR() const {
96 return getConfigKey("VALDI_ENABLE_CRASH_ON_ANR");

Callers 1

TESTFunction · 0.45

Calls 13

getGlobalFunction · 0.85
makeStringFromLiteralMethod · 0.80
isTypedArrayMethod · 0.80
hasPrefixMethod · 0.80
slowToStringMethod · 0.80
enabled_modules_sizeMethod · 0.80
getBinaryMethod · 0.65
logMethod · 0.65
ValueClass · 0.50
BytesViewClass · 0.50
getTypedArrayMethod · 0.45
dataMethod · 0.45

Tested by 1

TESTFunction · 0.36