Apache Singa
A General Distributed Deep Learning Library
channel.h
1 /************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21 
22 #ifndef SINGA_UTILS_CHANNEL_H_
23 #define SINGA_UTILS_CHANNEL_H_
24 
25 #include <google/protobuf/message.h>
26 
27 #include <iostream>
28 #include <fstream>
29 #include <map>
30 #include <string>
31 
32 namespace singa {
33 
35 class Channel {
36  public:
37  explicit Channel(const std::string& name);
38  ~Channel();
39 
41  inline const std::string& GetName() { return name_; }
43  inline void EnableDestStderr(bool enable) { stderr_ = enable; }
45  inline void EnableDestFile(bool enable) { file_ = enable; }
48  void SetDestFilePath(const std::string& file);
50  void Send(const std::string& message);
52  void Send(const google::protobuf::Message& message);
53 
54  private:
55  std::string name_ = "";
56  bool stderr_ = false;
57  bool file_ = false;
58  std::ofstream os_;
59 };
60 
62  public:
63  ChannelManager() {}
64  ~ChannelManager();
65 
66  void Init();
67  void SetDefaultDir(const char* dir);
68  Channel* GetInstance(const std::string& channel);
69 
70  private:
71  std::string dir_ = "";
72  std::map<std::string, Channel*> name2ptr_;
73 };
74 
77 void InitChannel(const char* argv);
79 void SetChannelDirectory(const char* path);
81 Channel* GetChannel(const std::string& channel_name);
82 
83 } // namespace singa
84 
85 #endif // SINGA_UTILS_CHANNEL_H__
const std::string & GetName()
Return the channel name, which is also used for naming the output file.
Definition: channel.h:41
void Send(const std::string &message)
Append a string message.
Definition: channel.h:61
void EnableDestStderr(bool enable)
Disabled by default.
Definition: channel.h:43
void EnableDestFile(bool enable)
Enabled by default.
Definition: channel.h:45
void SetChannelDirectory(const char *path)
Set the directory name for persisting channel content.
void SetDestFilePath(const std::string &file)
Reset the output file path.
Channel for appending metrics or other information into files or screen.
Definition: channel.h:35
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: common.h:48
Channel * GetChannel(const std::string &channel_name)
Get the channel instance.
void InitChannel(const char *argv)
Initial function for global usage of channel.