Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
VisualDL
提交
a81d5171
V
VisualDL
项目概览
PaddlePaddle
/
VisualDL
大约 1 年 前同步成功
通知
88
Star
4655
Fork
642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
2
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VisualDL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a81d5171
编写于
11月 24, 2017
作者:
S
superjom
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add Storage Interface and MemoryStorage baisc implementation
上级
fb08734e
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
127 addition
and
4 deletion
+127
-4
visualdl/backend/storage/storage.cc
visualdl/backend/storage/storage.cc
+52
-0
visualdl/backend/storage/storage.h
visualdl/backend/storage/storage.h
+72
-3
visualdl/backend/storage/storage.proto
visualdl/backend/storage/storage.proto
+3
-1
未找到文件。
visualdl/backend/storage/storage.cc
浏览文件 @
a81d5171
...
...
@@ -2,9 +2,61 @@
#include <fstream>
#include "visualdl/backend/storage/storage.h"
#include "visualdl/backend/utils/filesystem.h"
namespace
visualdl
{
std
::
string
GenPathFromTag
(
const
std
::
string
&
dir
,
const
std
::
string
&
tag
)
{
return
dir
+
"/"
+
tag
;
}
const
std
::
string
StorageBase
::
meta_file_name
=
"storage.meta"
;
storage
::
Tablet
*
MemoryStorage
::
NewTablet
(
const
std
::
string
&
tag
,
int
num_samples
)
{
auto
it
=
tablets_
.
find
(
tag
);
if
(
it
==
tablets_
.
end
())
{
// create new tablet
tablets_
[
tag
]
=
storage
::
Tablet
();
*
storage_
.
add_tags
()
=
tag
;
}
else
{
return
&
it
->
second
;
}
return
&
tablets_
[
tag
];
}
storage
::
Tablet
*
MemoryStorage
::
tablet
(
const
std
::
string
&
tag
)
{
auto
it
=
tablets_
.
find
(
tag
);
CHECK
(
it
!=
tablets_
.
end
())
<<
"tablet tagged as "
<<
tag
<<
" not exists"
;
return
&
it
->
second
;
}
void
MemoryStorage
::
PersistToDisk
()
const
{
// write storage out
const
auto
meta_path
=
storage_
.
dir
()
+
"/"
+
meta_file_name
;
fs
::
Write
(
meta_path
,
storage_
.
SerializeAsString
());
// write all the tablets
for
(
auto
tag
:
storage_
.
tags
())
{
auto
path
=
GenPathFromTag
(
storage_
.
dir
(),
tag
);
auto
it
=
tablets_
.
find
(
tag
);
CHECK
(
it
!=
tablets_
.
end
());
fs
::
Write
(
path
,
it
->
second
.
SerializeAsString
());
}
}
void
MemoryStorage
::
LoadFromDisk
(
const
std
::
string
&
dir
)
{
// load storage
const
auto
meta_path
=
storage_
.
dir
()
+
"/"
+
meta_file_name
;
storage_
.
ParseFromString
(
fs
::
Read
(
meta_path
));
// load all the tablets
for
(
auto
tag
:
storage_
.
tags
())
{
auto
path
=
GenPathFromTag
(
storage_
.
dir
(),
tag
);
tablets_
[
tag
];
tablets_
[
tag
].
ParseFromString
(
fs
::
Read
(
path
));
}
}
storage
::
Tablet
*
Storage
::
Add
(
const
std
::
string
&
tag
,
int
num_samples
)
{
auto
*
tablet
=
&
(
*
proto_
.
mutable_tablets
())[
tag
];
tablet
->
set_num_samples
(
num_samples
);
...
...
visualdl/backend/storage/storage.h
浏览文件 @
a81d5171
#ifndef VISUALDL_STORAGE_H
#define VISUALDL_STORAGE_H
#include <string>
#include <time.h>
#include <map>
#include <string>
#include "visualdl/backend/storage/storage.pb.h"
namespace
visualdl
{
/*
* Generate a tablet path in disk from its tag.
*/
inline
std
::
string
GenPathFromTag
(
const
std
::
string
&
dir
,
const
std
::
string
&
tag
);
/*
* Storage Interface. The might be a bunch of implementations, for example, a
* MemStorage that keep a copy of all the taplets in memory, can be changed with
* a higher performance; a DiskStorage that keep all the data in disk, apply to
* the scenerios where memory consumption should be considered.
*/
class
StorageBase
{
public:
const
static
std
::
string
meta_file_name
;
void
SetStorage
(
const
std
::
string
&
dir
)
{
time_t
t
;
time
(
&
t
);
storage_
.
set_timestamp
(
t
);
storage_
.
set_dir
(
dir
);
}
/*
* Create a new Tablet storage.
*/
virtual
storage
::
Tablet
*
NewTablet
(
const
std
::
string
&
tag
,
int
num_samples
)
=
0
;
/*
* Get a tablet from memory, this can be viewed as a cache, if the storage is
* in disk, a hash map in memory will first load the corresponding Tablet
* Protobuf from disk and hold all the changes.
*/
virtual
storage
::
Tablet
*
tablet
(
const
std
::
string
&
tag
)
=
0
;
/*
* Persist the data from cache to disk. Both the memory storage or disk
* storage should write changes to disk for persistence.
*/
virtual
void
PersistToDisk
()
const
=
0
;
/*
* Load data from disk.
*/
virtual
void
LoadFromDisk
(
const
std
::
string
&
dir
)
=
0
;
protected:
storage
::
Storage
storage_
;
};
/*
* Storage in Memory, that will support quick edits on data.
*/
class
MemoryStorage
final
:
public
StorageBase
{
public:
storage
::
Tablet
*
NewTablet
(
const
std
::
string
&
tag
,
int
num_samples
)
override
;
storage
::
Tablet
*
tablet
(
const
std
::
string
&
tag
)
override
;
void
PersistToDisk
()
const
override
;
void
LoadFromDisk
(
const
std
::
string
&
dir
)
override
;
private:
std
::
map
<
std
::
string
,
storage
::
Tablet
>
tablets_
;
};
class
Storage
final
{
public:
Storage
()
{
...
...
visualdl/backend/storage/storage.proto
浏览文件 @
a81d5171
...
...
@@ -130,7 +130,9 @@ The Storage stores all the records.
*/
message
Storage
{
// tags to Tablet, should be thread safe if fix the keys after initialization.
// TODO to delete in the new storage interface.
map
<
string
,
Tablet
>
tablets
=
1
;
repeated
string
tags
=
4
;
string
dir
=
2
;
int64
timestamp
=
3
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录