Skip to content

Commit

Permalink
Add manual Save feature. (#332)
Browse files Browse the repository at this point in the history
* Add manual Save feature.

* Fix the incorrect style
  • Loading branch information
jetfuel authored Mar 22, 2018
1 parent 2267c4e commit 30fdbc6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
23 changes: 16 additions & 7 deletions visualdl/logic/pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ PYBIND11_MODULE(core, m) {
}))
.def("set_mode", &vs::LogWriter::SetMode)
.def("as_mode", &vs::LogWriter::AsMode)
.def("save", &vs::LogWriter::Save)
// clang-format off
#define WRITER_ADD_SCALAR(T) \
.def("new_scalar_" #T, [](vs::LogWriter& self, const std::string& tag) { \
Expand Down Expand Up @@ -127,10 +128,15 @@ PYBIND11_MODULE(core, m) {
ADD_SCALAR_READER(int64_t);
#undef ADD_SCALAR_READER

#define ADD_SCALAR_WRITER(T) \
py::class_<cp::Scalar<T>>(m, "ScalarWriter__" #T, R"pbdoc(PyBind class. Must instantiate through the LogWriter.)pbdoc") \
.def("set_caption", &cp::Scalar<T>::SetCaption) \
.def("add_record", &cp::Scalar<T>::AddRecord, R"pbdoc(add a record with the step and value)pbdoc");
#define ADD_SCALAR_WRITER(T) \
py::class_<cp::Scalar<T>>( \
m, \
"ScalarWriter__" #T, \
R"pbdoc(PyBind class. Must instantiate through the LogWriter.)pbdoc") \
.def("set_caption", &cp::Scalar<T>::SetCaption) \
.def("add_record", \
&cp::Scalar<T>::AddRecord, \
R"pbdoc(add a record with the step and value)pbdoc");
ADD_SCALAR_WRITER(int);
ADD_SCALAR_WRITER(float);
ADD_SCALAR_WRITER(double);
Expand Down Expand Up @@ -192,9 +198,12 @@ PYBIND11_MODULE(core, m) {
.def("record", &cp::ImageReader::record)
.def("timestamp", &cp::ImageReader::timestamp);

#define ADD_HISTOGRAM_WRITER(T) \
py::class_<cp::Histogram<T>>(m, "HistogramWriter__" #T, R"pbdoc(PyBind class. Must instantiate through the LogWriter.)pbdoc") \
.def("add_record", &cp::Histogram<T>::AddRecord, R"pbdoc(add a record with the step and histogram_value)pbdoc");
#define ADD_HISTOGRAM_WRITER(T) \
py::class_<cp::Histogram<T>>(m, "HistogramWriter__" #T, \
R"pbdoc(PyBind class. Must instantiate through the LogWriter.)pbdoc") \
.def("add_record", \
&cp::Histogram<T>::AddRecord, \
R"pbdoc(add a record with the step and histogram_value)pbdoc");
ADD_FULL_TYPE_IMPL(ADD_HISTOGRAM_WRITER)
#undef ADD_HISTOGRAM_WRITER

Expand Down
2 changes: 1 addition & 1 deletion visualdl/logic/sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LogWriter {
mode_ = mode;
storage_.AddMode(mode);
}

void Save() { storage_.PersistToDisk(); }
LogWriter AsMode(const std::string& mode);

Tablet AddTablet(const std::string& tag);
Expand Down
3 changes: 3 additions & 0 deletions visualdl/python/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ def histogram(self, tag, num_buckets, type='float'):
}
return types[type](tag, num_buckets)

def save(self):
self.writer.save()

def __enter__(self):
return self

Expand Down

0 comments on commit 30fdbc6

Please sign in to comment.