|
75 | 75 |
|
76 | 76 | #include "yb/tserver/server_main_util.h" |
77 | 77 |
|
| 78 | +#if defined(YB_PROFGEN) && defined(__clang__) |
| 79 | +extern "C" int __llvm_profile_write_file(void); |
| 80 | +extern "C" void __llvm_profile_set_filename(const char *); |
| 81 | +extern "C" void __llvm_profile_reset_counters(); |
| 82 | +#endif |
| 83 | + |
| 84 | + |
78 | 85 | using namespace std::placeholders; |
79 | 86 |
|
80 | 87 | using yb::redisserver::RedisServer; |
@@ -159,6 +166,18 @@ void SetProxyAddresses() { |
159 | 166 | SetProxyAddress(&FLAGS_pgsql_proxy_bind_address, "YSQL", PgProcessConf::kDefaultPort); |
160 | 167 | } |
161 | 168 |
|
| 169 | +#if defined(YB_PROFGEN) && defined(__clang__) |
| 170 | +// Force profile dumping |
| 171 | +void PeriodicDumpLLVMProfileFile() { |
| 172 | + __llvm_profile_set_filename("tserver-%p-%m.profraw"); |
| 173 | + while (true) { |
| 174 | + __llvm_profile_write_file(); |
| 175 | + __llvm_profile_reset_counters(); |
| 176 | + SleepFor(MonoDelta::FromSeconds(60)); |
| 177 | + } |
| 178 | +} |
| 179 | +#endif |
| 180 | + |
162 | 181 | int TabletServerMain(int argc, char** argv) { |
163 | 182 | #ifndef NDEBUG |
164 | 183 | HybridTime::TEST_SetPrettyToString(true); |
@@ -274,6 +293,13 @@ int TabletServerMain(int argc, char** argv) { |
274 | 293 | LOG(INFO) << "Redis server successfully started."; |
275 | 294 | } |
276 | 295 |
|
| 296 | +#if defined(YB_PROFGEN) && defined(__clang__) |
| 297 | + // TODO After the TODO below is fixed the call of |
| 298 | + // PeriodicDumpLLVMProfileFile can be moved to the infinite while loop |
| 299 | + // at the end of the function. |
| 300 | + std::thread llvm_profile_dump_thread(PeriodicDumpLLVMProfileFile); |
| 301 | +#endif |
| 302 | + |
277 | 303 | // TODO(neil): After CQL server is starting, it blocks this thread from moving on. |
278 | 304 | // This should be fixed such that all processes or service by tablet server are treated equally |
279 | 305 | // by using different threads for each process. |
@@ -310,6 +336,11 @@ int TabletServerMain(int argc, char** argv) { |
310 | 336 | SleepFor(MonoDelta::FromSeconds(60)); |
311 | 337 | } |
312 | 338 |
|
| 339 | +#if defined(YB_PROFGEN) && defined(__clang__) |
| 340 | + // Currently unreachable |
| 341 | + llvm_profile_dump_thread.join(); |
| 342 | +#endif |
| 343 | + |
313 | 344 | return 0; |
314 | 345 | } |
315 | 346 |
|
|
0 commit comments