未验证 提交 30fdbc6b 编写于 作者: J Jeff Wang 提交者: GitHub

Add manual Save feature. (#332)

* Add manual Save feature.

* Fix the incorrect style
上级 2267c4e8
...@@ -86,6 +86,7 @@ PYBIND11_MODULE(core, m) { ...@@ -86,6 +86,7 @@ PYBIND11_MODULE(core, m) {
})) }))
.def("set_mode", &vs::LogWriter::SetMode) .def("set_mode", &vs::LogWriter::SetMode)
.def("as_mode", &vs::LogWriter::AsMode) .def("as_mode", &vs::LogWriter::AsMode)
.def("save", &vs::LogWriter::Save)
// clang-format off // clang-format off
#define WRITER_ADD_SCALAR(T) \ #define WRITER_ADD_SCALAR(T) \
.def("new_scalar_" #T, [](vs::LogWriter& self, const std::string& tag) { \ .def("new_scalar_" #T, [](vs::LogWriter& self, const std::string& tag) { \
...@@ -128,9 +129,14 @@ PYBIND11_MODULE(core, m) { ...@@ -128,9 +129,14 @@ PYBIND11_MODULE(core, m) {
#undef ADD_SCALAR_READER #undef ADD_SCALAR_READER
#define ADD_SCALAR_WRITER(T) \ #define ADD_SCALAR_WRITER(T) \
py::class_<cp::Scalar<T>>(m, "ScalarWriter__" #T, R"pbdoc(PyBind class. Must instantiate through the LogWriter.)pbdoc") \ 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("set_caption", &cp::Scalar<T>::SetCaption) \
.def("add_record", &cp::Scalar<T>::AddRecord, R"pbdoc(add a record with the step and value)pbdoc"); .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(int);
ADD_SCALAR_WRITER(float); ADD_SCALAR_WRITER(float);
ADD_SCALAR_WRITER(double); ADD_SCALAR_WRITER(double);
...@@ -193,8 +199,11 @@ PYBIND11_MODULE(core, m) { ...@@ -193,8 +199,11 @@ PYBIND11_MODULE(core, m) {
.def("timestamp", &cp::ImageReader::timestamp); .def("timestamp", &cp::ImageReader::timestamp);
#define ADD_HISTOGRAM_WRITER(T) \ #define ADD_HISTOGRAM_WRITER(T) \
py::class_<cp::Histogram<T>>(m, "HistogramWriter__" #T, R"pbdoc(PyBind class. Must instantiate through the LogWriter.)pbdoc") \ py::class_<cp::Histogram<T>>(m, "HistogramWriter__" #T, \
.def("add_record", &cp::Histogram<T>::AddRecord, R"pbdoc(add a record with the step and histogram_value)pbdoc"); 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) ADD_FULL_TYPE_IMPL(ADD_HISTOGRAM_WRITER)
#undef ADD_HISTOGRAM_WRITER #undef ADD_HISTOGRAM_WRITER
......
...@@ -44,7 +44,7 @@ public: ...@@ -44,7 +44,7 @@ public:
mode_ = mode; mode_ = mode;
storage_.AddMode(mode); storage_.AddMode(mode);
} }
void Save() { storage_.PersistToDisk(); }
LogWriter AsMode(const std::string& mode); LogWriter AsMode(const std::string& mode);
Tablet AddTablet(const std::string& tag); Tablet AddTablet(const std::string& tag);
......
...@@ -222,6 +222,9 @@ class LogWriter(object): ...@@ -222,6 +222,9 @@ class LogWriter(object):
} }
return types[type](tag, num_buckets) return types[type](tag, num_buckets)
def save(self):
self.writer.save()
def __enter__(self): def __enter__(self):
return self return self
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册