提交 d537276a 编写于 作者: S superjom

recover some code

上级 29259816
...@@ -60,8 +60,6 @@ std::string TabletHelper::human_readable_buffer() const { ...@@ -60,8 +60,6 @@ std::string TabletHelper::human_readable_buffer() const {
return buffer; return buffer;
} }
void ImHelper::PersistToDisk() const { IM::Global().PersistToDisk(); }
// implementations for components // implementations for components
namespace components { namespace components {
......
...@@ -96,12 +96,55 @@ class ImHelper { ...@@ -96,12 +96,55 @@ class ImHelper {
public: public:
ImHelper() {} ImHelper() {}
/* StorageHelper storage() {
* mode: return StorageHelper(IM::Global().storage().mutable_data());
* 0: read }
* 1: write TabletHelper tablet(const std::string &tag) {
* 2: none return TabletHelper(IM::Global().storage().tablet(tag));
*/ }
TabletHelper AddTablet(const std::string &tag, int num_samples) {
return TabletHelper(IM::Global().AddTablet(tag, num_samples));
}
void ClearTablets() {
IM::Global().storage().mutable_data()->clear_tablets();
}
void PersistToDisk() const;
};
namespace components {
/*
* Read and write support for Scalar component.
*/
template <typename T>
class ScalarHelper {
public:
ScalarHelper(storage::Tablet *tablet) : data_(tablet) {}
void SetCaptions(const std::vector<std::string> &captions);
void AddRecord(int id, const std::vector<T> &values);
std::vector<std::vector<T>> GetRecords() const;
std::vector<int> GetIds() const;
std::vector<int> GetTimestamps() const;
std::vector<std::string> GetCaptions() const;
size_t GetSize() const { return data_->records_size(); }
private:
storage::Tablet *data_;
};
} // namespace components
static ImHelper &get_im() {
static ImHelper im;
return im;
} }
} // namespace visualdl } // namespace visualdl
......
...@@ -30,12 +30,27 @@ struct PeriodExector { ...@@ -30,12 +30,27 @@ struct PeriodExector {
void Start() { quit = false; } void Start() { quit = false; }
void operator()(task_t&& task, int msec) { void operator()(task_t&& task, int msec) {
const int interval = 500;
auto task_wrapper = [=] { auto task_wrapper = [=] {
while (!quit) { while (!quit) {
if (!task()) break; if (!task()) break;
std::this_thread::sleep_for(std::chrono::milliseconds(msec)); // if the program is terminated, quit while as soon as possible.
// this is just trick, but should works.
if (msec > 1000) {
int i;
for (i = 0; i < msec / interval; i++) {
if (quit) break;
std::this_thread::sleep_for(std::chrono::milliseconds(interval));
}
std::this_thread::sleep_for(
std::chrono::milliseconds(msec - i * interval));
if (quit) break;
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(msec));
}
} }
LOG(INFO) << "quit job"; LOG(INFO) << "quit concurrent job";
}; };
threads_.emplace_back(std::thread(std::move(task_wrapper))); threads_.emplace_back(std::thread(std::move(task_wrapper)));
msec_ = msec; msec_ = msec;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册