im.h 1.5 KB
Newer Older
S
superjom 已提交
1 2 3
#ifndef VISUALDL_BACKEND_LOGIC_IM_H
#define VISUALDL_BACKEND_LOGIC_IM_H

S
superjom 已提交
4 5
#include <glog/logging.h>
#include <memory>
S
superjom 已提交
6 7 8 9 10 11 12 13 14 15 16 17
#include <string>

#include "visualdl/backend/storage/storage.h"

namespace visualdl {

/*
 * Maintain the Storage singleton in memory, pre-compute some the statical
 * information to help visualizaton.
 */
class InformationMaintainer final {
public:
S
superjom 已提交
18 19 20 21 22 23 24 25 26
  InformationMaintainer(StorageBase::Type type = StorageBase::Type::kMemory) {
    switch (type) {
      case StorageBase::Type::kMemory:
        storage_.reset(new MemoryStorage);
        break;
      default:
        CHECK(false) << "Unsupported storage kind " << type;
    }
  }
S
superjom 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

  static InformationMaintainer &Global() {
    static InformationMaintainer *x = new InformationMaintainer();
    return *x;
  }

  /*
   * Set the disk path to store the Storage object.
   */
  void SetPersistDest(const std::string &path);

  storage::Tablet *AddTablet(const std::string &tag, int num_samples);

  /*
   * @tag: tag of the target Tablet.
S
superjom 已提交
42
   * @record: a record
S
superjom 已提交
43 44 45 46
   *
   * NOTE pass in the serialized protobuf message will trigger copying, but
   * simpler to support different Tablet data formats.
   */
S
superjom 已提交
47
  void AddRecord(const std::string &tag, const storage::Record &record);
S
superjom 已提交
48

S
superjom 已提交
49 50 51 52 53
  /*
   * delete all the information.
   */
  void Clear();

S
superjom 已提交
54 55 56 57 58
  /*
   * Save the Storage Protobuf to disk.
   */
  void PersistToDisk();

S
superjom 已提交
59
  StorageBase &storage() { return *storage_; }
S
superjom 已提交
60 61

private:
S
superjom 已提交
62
  std::unique_ptr<StorageBase> storage_;
S
superjom 已提交
63 64
};

S
superjom 已提交
65
}  // namespace visualdl
S
superjom 已提交
66

S
superjom 已提交
67
#endif  // VISUALDL_BACKEND_LOGIC_IM_H