Added stat for time spent opening files
This commit is contained in:
parent
c7cf0c5b17
commit
457ebf626d
@ -16,7 +16,8 @@ public:
|
||||
};
|
||||
|
||||
struct Stats {
|
||||
int file_opens = 0;
|
||||
int file_openings = 0;
|
||||
int time_spent_opening_files = 0;
|
||||
};
|
||||
|
||||
virtual void emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i origin_in_voxels, int lod);
|
||||
|
@ -47,7 +47,7 @@ void VoxelStreamBlockFiles::emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i o
|
||||
FileAccess *f = nullptr;
|
||||
{
|
||||
Error err;
|
||||
f = open_file(file_path, FileAccess::READ, err);
|
||||
f = open_file(file_path, FileAccess::READ, &err);
|
||||
// Had to add ERR_FILE_CANT_OPEN because that's what Godot actually returns when the file doesn't exist...
|
||||
if (f == nullptr && (err == ERR_FILE_NOT_FOUND || err == ERR_FILE_CANT_OPEN)) {
|
||||
emerge_block_fallback(out_buffer, origin_in_voxels, lod);
|
||||
@ -97,7 +97,7 @@ void VoxelStreamBlockFiles::immerge_block(Ref<VoxelBuffer> buffer, Vector3i orig
|
||||
{
|
||||
Error err;
|
||||
// Create file if not exists, always truncate
|
||||
f = open_file(file_path, FileAccess::WRITE, err);
|
||||
f = open_file(file_path, FileAccess::WRITE, &err);
|
||||
}
|
||||
ERR_FAIL_COND(f == nullptr);
|
||||
|
||||
@ -141,7 +141,7 @@ Error VoxelStreamBlockFiles::save_meta() {
|
||||
|
||||
{
|
||||
Error err;
|
||||
FileAccess *f = open_file(meta_path, FileAccess::WRITE, err);
|
||||
FileAccess *f = open_file(meta_path, FileAccess::WRITE, &err);
|
||||
ERR_FAIL_COND_V(f == nullptr, err);
|
||||
|
||||
f->store_buffer((uint8_t *)FORMAT_META_MAGIC, 4);
|
||||
@ -166,7 +166,7 @@ Error VoxelStreamBlockFiles::load_meta() {
|
||||
Meta meta;
|
||||
{
|
||||
Error err;
|
||||
FileAccessRef f = open_file(meta_path, FileAccess::READ, err);
|
||||
FileAccessRef f = open_file(meta_path, FileAccess::READ, &err);
|
||||
// Had to add ERR_FILE_CANT_OPEN because that's what Godot actually returns when the file doesn't exist...
|
||||
if (!_meta.saved && (err == ERR_FILE_NOT_FOUND || err == ERR_FILE_CANT_OPEN)) {
|
||||
// This is a new terrain, save the meta we have and consider it current
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "voxel_stream_file.h"
|
||||
#include <core/os/file_access.h>
|
||||
#include <core/os/os.h>
|
||||
|
||||
void VoxelStreamFile::set_save_fallback_output(bool enabled) {
|
||||
_save_fallback_output = enabled;
|
||||
@ -45,6 +46,15 @@ void VoxelStreamFile::emerge_blocks_fallback(Vector<VoxelStreamFile::BlockReques
|
||||
}
|
||||
}
|
||||
|
||||
FileAccess *VoxelStreamFile::open_file(const String &fpath, int mode_flags, Error *err) {
|
||||
uint64_t time_before = OS::get_singleton()->get_ticks_usec();
|
||||
FileAccess *f = FileAccess::open(fpath, mode_flags, err);
|
||||
uint64_t time_spent = OS::get_singleton()->get_ticks_usec() - time_before;
|
||||
_stats.time_spent_opening_files += time_spent;
|
||||
++_stats.file_openings;
|
||||
return f;
|
||||
}
|
||||
|
||||
void VoxelStreamFile::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_save_fallback_output", "enabled"), &VoxelStreamFile::set_save_fallback_output);
|
||||
|
@ -25,6 +25,8 @@ protected:
|
||||
void emerge_block_fallback(Ref<VoxelBuffer> out_buffer, Vector3i origin_in_voxels, int lod);
|
||||
void emerge_blocks_fallback(Vector<BlockRequest> &requests);
|
||||
|
||||
FileAccess *open_file(const String &fpath, int mode_flags, Error *err);
|
||||
|
||||
VoxelBlockSerializer _block_serializer;
|
||||
|
||||
private:
|
||||
|
@ -394,8 +394,7 @@ Error VoxelStreamRegionFiles::save_meta() {
|
||||
String meta_path = _directory_path.plus_file(META_FILE_NAME);
|
||||
|
||||
Error err;
|
||||
FileAccessRef f = FileAccess::open(meta_path, FileAccess::WRITE, &err);
|
||||
++_stats.file_opens;
|
||||
FileAccessRef f = open_file(meta_path, FileAccess::WRITE, &err);
|
||||
if (!f) {
|
||||
print_error(String("Could not save {0}").format(varray(meta_path)));
|
||||
return err;
|
||||
@ -421,8 +420,7 @@ Error VoxelStreamRegionFiles::load_meta() {
|
||||
|
||||
{
|
||||
Error err;
|
||||
FileAccessRef f = FileAccess::open(meta_path, FileAccess::READ, &err);
|
||||
++_stats.file_opens;
|
||||
FileAccessRef f = open_file(meta_path, FileAccess::READ, &err);
|
||||
if (!f) {
|
||||
//print_error(String("Could not load {0}").format(varray(meta_path)));
|
||||
return err;
|
||||
@ -483,9 +481,6 @@ void VoxelStreamRegionFiles::clear_cache() {
|
||||
|
||||
String VoxelStreamRegionFiles::get_region_file_path(const Vector3i ®ion_pos, unsigned int lod) const {
|
||||
|
||||
// TODO Separate lods in other region files is a bad idea
|
||||
// Better append them to the same regions so we don't re-create more file switching.
|
||||
// If a block spans a larger area, it will remain in the region where its origin is.
|
||||
Array a;
|
||||
a.resize(5);
|
||||
a[0] = lod;
|
||||
@ -523,8 +518,7 @@ VoxelStreamRegionFiles::CachedRegion *VoxelStreamRegionFiles::open_region(const
|
||||
|
||||
String fpath = get_region_file_path(region_pos, lod);
|
||||
Error existing_file_err;
|
||||
FileAccess *existing_f = FileAccess::open(fpath, FileAccess::READ_WRITE, &existing_file_err);
|
||||
++_stats.file_opens;
|
||||
FileAccess *existing_f = open_file(fpath, FileAccess::READ_WRITE, &existing_file_err);
|
||||
// TODO Cache the fact the file doesnt exist, so we won't need to do a system call to actually check it every time
|
||||
// TODO No need to read the header again when it has been read once, we assume no other process will modify region files
|
||||
|
||||
@ -542,8 +536,7 @@ VoxelStreamRegionFiles::CachedRegion *VoxelStreamRegionFiles::open_region(const
|
||||
}
|
||||
|
||||
Error file_err;
|
||||
FileAccess *f = FileAccess::open(fpath, FileAccess::WRITE_READ, &file_err);
|
||||
++_stats.file_opens;
|
||||
FileAccess *f = open_file(fpath, FileAccess::WRITE_READ, &file_err);
|
||||
ERR_FAIL_COND_V_MSG(!f, nullptr, "Failed to write file " + fpath + ", error " + String::num_int64(file_err));
|
||||
ERR_FAIL_COND_V_MSG(file_err != OK, nullptr, "Error " + String::num_int64(file_err));
|
||||
|
||||
|
@ -60,7 +60,8 @@ public:
|
||||
};
|
||||
|
||||
struct ProcessorStats {
|
||||
int file_opens = 0;
|
||||
int file_openings = 0;
|
||||
int time_spent_opening_files = 0;
|
||||
};
|
||||
|
||||
struct Stats {
|
||||
@ -277,7 +278,8 @@ public:
|
||||
remaining_blocks[i] = stats.remaining_blocks[i];
|
||||
}
|
||||
d["remaining_blocks_per_thread"] = remaining_blocks;
|
||||
d["file_opens"] = stats.processor.file_opens;
|
||||
d["file_openings"] = stats.processor.file_openings;
|
||||
d["time_spent_opening_files"] = stats.processor.time_spent_opening_files;
|
||||
return d;
|
||||
}
|
||||
|
||||
@ -316,7 +318,8 @@ private:
|
||||
a.sorting_time += b.sorting_time;
|
||||
a.dropped_count += b.dropped_count;
|
||||
|
||||
a.processor.file_opens += b.processor.file_opens;
|
||||
a.processor.file_openings += b.processor.file_openings;
|
||||
a.processor.time_spent_opening_files += b.processor.time_spent_opening_files;
|
||||
}
|
||||
|
||||
unsigned int push_block_requests(JobData &job, const std::vector<InputBlock> &input_blocks, int begin, int count) {
|
||||
|
@ -89,7 +89,9 @@ void VoxelDataLoader::process_blocks_thread_func(const ArraySlice<InputBlock> in
|
||||
stream->emerge_blocks(emerge_requests);
|
||||
stream->immerge_blocks(immerge_requests);
|
||||
|
||||
stats.file_opens = stream->get_stats().file_opens;
|
||||
VoxelStream::Stats stream_stats = stream->get_stats();
|
||||
stats.file_openings = stream_stats.file_openings;
|
||||
stats.time_spent_opening_files = stream_stats.time_spent_opening_files;
|
||||
|
||||
// Assumes the stream won't change output order
|
||||
int iload = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user