-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32585 from vespa-engine/toregge/add-field-index-s…
…tats Add field index stats.
- Loading branch information
Showing
8 changed files
with
171 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. | ||
|
||
#include "field_index_stats.h" | ||
#include <ostream> | ||
|
||
namespace search { | ||
|
||
std::ostream& operator<<(std::ostream& os, const FieldIndexStats& stats) { | ||
os << "{memory: " << stats.memory_usage() << ", disk: " << stats.size_on_disk() << "}"; | ||
return os; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. | ||
#pragma once | ||
|
||
#include <vespa/vespalib/util/memoryusage.h> | ||
|
||
namespace search { | ||
|
||
/** | ||
* Statistics for a single field index. | ||
**/ | ||
class FieldIndexStats | ||
{ | ||
private: | ||
vespalib::MemoryUsage _memory_usage; | ||
size_t _size_on_disk; // in bytes | ||
|
||
public: | ||
FieldIndexStats() noexcept | ||
: _memory_usage(), | ||
_size_on_disk(0) | ||
{} | ||
FieldIndexStats &memory_usage(const vespalib::MemoryUsage &usage) noexcept { | ||
_memory_usage = usage; | ||
return *this; | ||
} | ||
const vespalib::MemoryUsage &memory_usage() const noexcept { return _memory_usage; } | ||
FieldIndexStats &size_on_disk(size_t value) noexcept { | ||
_size_on_disk = value; | ||
return *this; | ||
} | ||
size_t size_on_disk() const noexcept { return _size_on_disk; } | ||
|
||
void merge(const FieldIndexStats &rhs) noexcept { | ||
_memory_usage.merge(rhs._memory_usage); | ||
_size_on_disk += rhs._size_on_disk; | ||
} | ||
|
||
bool operator==(const FieldIndexStats& rhs) const noexcept { | ||
return _memory_usage == rhs._memory_usage && | ||
_size_on_disk == rhs._size_on_disk; | ||
} | ||
}; | ||
|
||
std::ostream& operator<<(std::ostream& os, const FieldIndexStats& stats); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. | ||
|
||
#include "searchable_stats.h" | ||
#include <ostream> | ||
|
||
namespace search { | ||
|
||
SearchableStats::SearchableStats() | ||
: _memoryUsage(), | ||
_docsInMemory(0), | ||
_sizeOnDisk(0), | ||
_fusion_size_on_disk(0), | ||
_field_stats() | ||
{ | ||
} | ||
|
||
SearchableStats::~SearchableStats() = default; | ||
|
||
SearchableStats& | ||
SearchableStats::merge(const SearchableStats &rhs) { | ||
_memoryUsage.merge(rhs._memoryUsage); | ||
_docsInMemory += rhs._docsInMemory; | ||
_sizeOnDisk += rhs._sizeOnDisk; | ||
_fusion_size_on_disk += rhs._fusion_size_on_disk; | ||
for (auto& rhs_field : rhs._field_stats) { | ||
_field_stats[rhs_field.first].merge(rhs_field.second); | ||
} | ||
return *this; | ||
} | ||
|
||
bool | ||
SearchableStats::operator==(const SearchableStats& rhs) const noexcept | ||
{ | ||
return _memoryUsage == rhs._memoryUsage && | ||
_docsInMemory == rhs._docsInMemory && | ||
_sizeOnDisk == rhs._sizeOnDisk && | ||
_fusion_size_on_disk == rhs._fusion_size_on_disk && | ||
_field_stats == rhs._field_stats; | ||
} | ||
|
||
SearchableStats& | ||
SearchableStats::add_field_stats(const std::string& name, const FieldIndexStats& stats) | ||
{ | ||
_field_stats[name].merge(stats); | ||
return *this; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, const SearchableStats& stats) { | ||
os << "{memory: " << stats.memoryUsage() << ", docsInMemory: " << stats.docsInMemory() << | ||
", disk: " << stats.sizeOnDisk() << ", fusion_size_on_disk: " << stats.fusion_size_on_disk() << ", "; | ||
os << "fields: {"; | ||
bool first = true; | ||
for (auto& field : stats.get_field_stats()) { | ||
if (!first) { | ||
os << ", "; | ||
} | ||
first = false; | ||
os << "\"" << field.first << "\": " << field.second; | ||
} | ||
os << "}"; | ||
return os; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters