2016-05-23 6 views
2

私のC++プログラムを最適化しようとしています。それはcaffeを使用します。
私のプログラムを実行すると、caffeは15分ごとに約1GB(!)の情報ログを出力します。私はこれが効率に大きな影響を与えると考えています。しかし、私はログオフする方法を見つけていません。 this questionでは誰かが手動でFLAGS_vを設定することを提案しました。glogの "LOG(INFO)"ログを無効にする

次のコードでは、レベル別にVLOGログを無効にできますが、LOG(x)ログには影響しません。 main()

ファーストライン:

FLAGS_v = 1; //disables vlog(2), vlog(3), vlog(4) 
VLOG(0) << "Verbose 0"; 
VLOG(1) << "Verbose 1"; 
VLOG(2) << "Verbose 2"; 
VLOG(3) << "Verbose 3"; 
VLOG(4) << "Verbose 4"; 
LOG(INFO) << "LOG(INFO)"; 
LOG(WARNING) << "LOG(WARNING)"; 
LOG(ERROR) << "LOG(ERROR)"; 

出力:

WARNING: Logging before InitGoogleLogging() is written to STDERR 
I0523 19:06:51.484634 14115 main.cpp:381] Verbose 0 
I0523 19:06:51.484699 14115 main.cpp:382] Verbose 1 
I0523 19:06:51.484705 14115 main.cpp:386] LOG(INFO) 
W0523 19:06:51.484710 14115 main.cpp:387] LOG(WARNING) 
E0523 19:06:51.484715 14115 main.cpp:388] LOG(ERROR) 

私は気づいていないのだ別のflagはありますか?私はすべてのLOG(INFO)ラインのコメントを考えていますが、私はより洗練されたソリューションを望みます。 (私は、コマンドラインフラグソリューションよりもC++のソリューションを好むだろう)。

答えて

3

あなたの実行可能ファイルを実行し

GLOG_minloglevel=2 

あなたの環境変数を設定する必要があります。

here(このページの下部には、マクロ定義を使用してコードからを取り除くセクションがあります)があります。

+0

環境変数を設定する代わりにコードから行う方法はありますか?ありがとう。 – rkellerm

4

これはC++ソースコードで動作します。

google::InitGoogleLogging("XXX"); 
google::SetCommandLineOption("GLOG_minloglevel", "2"); 
1

環境変数 "GLOG_minloglevel"はログをフィルタリングしますが、実行可能ファイルでコンパイルされています。あなたが時間をコンパイル時にそれらを無効にしたい場合は、マクロを定義:

「の#define GOOGLE_STRIP_LOG 1」

これはlogging.h内のコメントです:

111 // The global value of GOOGLE_STRIP_LOG. All the messages logged to    
112 // LOG(XXX) with severity less than GOOGLE_STRIP_LOG will not be displayed.  
113 // If it can be determined at compile time that the message will not be   
114 // printed, the statement will be compiled out.         
115 //                    
116 // Example: to strip out all INFO and WARNING messages, use the value   
117 // of 2 below. To make an exception for WARNING messages from a single   
118 // file, add "#define GOOGLE_STRIP_LOG 1" to that file _before_ including  
119 // base/logging.h                
120 #ifndef GOOGLE_STRIP_LOG                                             
121 #define GOOGLE_STRIP_LOG 0              
122 #endif 
0

はちょうどあなたの行の下に追加しますInit方法でのsrc /カフェ/ net.cppでとカフェを構築するC++コード:functioの

fLI::FLAGS_minloglevel=3; 

パーシャルビューこの行を追加する必要がある場所:

template <typename Dtype> 
    void Net<Dtype>::Init(const NetParameter& in_param) { 

     fLI::FLAGS_minloglevel=3; 


     // Set phase from the state. 
     phase_ = in_param.state().phase(); 
     // Filter layers based on their include/exclude rules and 
     // the current NetState. 
     NetParameter filtered_param; 
     FilterNet(in_param, &filtered_param); 
     LOG(INFO) << "Initializing net from parameters: " << std::endl 
       << filtered_param.DebugString(); 
     // Create a copy of filtered_param with splits added where necessary. 
     NetParameter param; 
     InsertSplits(filtered_param, &param); 
     // Basically, build all the layers and set up their connections. 
     name_ = param.name(); 

     . 
     . 
     . 
     . 

必要に応じてログレベルを設定します。

関連する問題