MCPcopy Create free account
hub / github.com/apache/brpc / dumping_thread

Function dumping_thread

src/bvar/variable.cpp:730–860  ·  view source on GitHub ↗

The background thread to export all bvar periodically.

Source from the content-addressed store, hash-verified

728
729// The background thread to export all bvar periodically.
730static void* dumping_thread(void*) {
731 // NOTE: this variable was declared as static <= r34381, which was
732 // destructed when program exits and caused coredumps.
733 butil::PlatformThread::SetNameSimple("bvar_dumper");
734 const std::string command_name = read_command_name();
735 std::string last_filename;
736 std::string mbvar_last_filename;
737 while (1) {
738 // We can't access string flags directly because it's thread-unsafe.
739 std::string filename;
740 DumpOptions options;
741 std::string prefix;
742 std::string tabs;
743 std::string mbvar_filename;
744 std::string mbvar_prefix;
745 std::string mbvar_format;
746 if (!GFLAGS_NAMESPACE::GetCommandLineOption("bvar_dump_file", &filename)) {
747 LOG(ERROR) << "Fail to get gflag bvar_dump_file";
748 return NULL;
749 }
750 if (!GFLAGS_NAMESPACE::GetCommandLineOption("bvar_dump_include",
751 &options.white_wildcards)) {
752 LOG(ERROR) << "Fail to get gflag bvar_dump_include";
753 return NULL;
754 }
755 if (!GFLAGS_NAMESPACE::GetCommandLineOption("bvar_dump_exclude",
756 &options.black_wildcards)) {
757 LOG(ERROR) << "Fail to get gflag bvar_dump_exclude";
758 return NULL;
759 }
760 if (!GFLAGS_NAMESPACE::GetCommandLineOption("bvar_dump_prefix", &prefix)) {
761 LOG(ERROR) << "Fail to get gflag bvar_dump_prefix";
762 return NULL;
763 }
764 if (!GFLAGS_NAMESPACE::GetCommandLineOption("bvar_dump_tabs", &tabs)) {
765 LOG(ERROR) << "Fail to get gflags bvar_dump_tabs";
766 return NULL;
767 }
768
769 // We can't access string flags directly because it's thread-unsafe.
770 if (!GFLAGS_NAMESPACE::GetCommandLineOption("mbvar_dump_file", &mbvar_filename)) {
771 LOG(ERROR) << "Fail to get gflag mbvar_dump_file";
772 return NULL;
773 }
774 if (!GFLAGS_NAMESPACE::GetCommandLineOption("mbvar_dump_prefix", &mbvar_prefix)) {
775 LOG(ERROR) << "Fail to get gflag mbvar_dump_prefix";
776 return NULL;
777 }
778 if (!GFLAGS_NAMESPACE::GetCommandLineOption("mbvar_dump_format", &mbvar_format)) {
779 LOG(ERROR) << "Fail to get gflag mbvar_dump_format";
780 return NULL;
781 }
782
783 if (FLAGS_bvar_dump && !filename.empty()) {
784 // Replace first <app> in filename with program name. We can't use
785 // pid because a same binary should write the data to the same
786 // place, otherwise restarting of app may confuse noah with a lot
787 // of *.data. noah takes 1.5 days to figure out that some data is

Callers

nothing calls this directly

Calls 6

read_command_nameFunction · 0.85
milliseconds_from_nowFunction · 0.85
pthread_mutex_lockFunction · 0.85
pthread_mutex_unlockFunction · 0.85
emptyMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected