aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Barron <tjbarron@google.com>2022-08-10 23:59:08 +0000
committerTim Barron <tjbarron@google.com>2022-08-11 19:45:57 +0000
commitdc41cd4265cb5b743fa1183cd51196f1737303e4 (patch)
treec6ffc22566d6ae9e2564cdaba6a6431a826e928a
parentecb3673040687444c8e6a573b54a3affc4e3a963 (diff)
downloadicing-dc41cd4265cb5b743fa1183cd51196f1737303e4.tar.gz
Remove use of StringPrintf in ICING_LOG statements
Many of these log statements won't do anything (because they're filtered out by logging level). Using the << operator allows Icing's Logger class to drop those parameters efficiently. Using StringPrintf is expensive and will run regardless of whether the log is actually printed. This change reduces total query latency in Relevance scoring by ~19% when all results are retrieved and by ~56% when the top 40 results are retrieved. This change is a cherrypick of cl/466073938. Test: m com.android.appsearch Change-Id: Id2e6f695e50906720cf56df99d7a5e4e972a4ba7
-rw-r--r--icing/file/file-backed-bitmap.cc3
-rw-r--r--icing/file/filesystem.cc100
-rw-r--r--icing/icing-search-engine.cc6
-rw-r--r--icing/index/lite/lite-index.cc15
-rw-r--r--icing/index/main/flash-index-storage.cc41
-rw-r--r--icing/index/main/main-index.cc9
-rw-r--r--icing/legacy/index/icing-array-storage.cc37
-rw-r--r--icing/legacy/index/icing-dynamic-trie.cc47
-rw-r--r--icing/legacy/index/icing-filesystem.cc95
-rw-r--r--icing/legacy/index/icing-flash-bitmap.cc28
-rw-r--r--icing/legacy/index/icing-mmapper.cc6
-rw-r--r--icing/legacy/index/icing-storage-file.cc13
-rw-r--r--icing/scoring/bm25f-calculator.cc27
13 files changed, 166 insertions, 261 deletions
diff --git a/icing/file/file-backed-bitmap.cc b/icing/file/file-backed-bitmap.cc
index eec7668..a8231e3 100644
--- a/icing/file/file-backed-bitmap.cc
+++ b/icing/file/file-backed-bitmap.cc
@@ -269,8 +269,7 @@ libtextclassifier3::Status FileBackedBitmap::GrowTo(int new_num_bits) {
return status;
}
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "Grew file %s to new size %zd", file_path_.c_str(), new_file_size);
+ ICING_VLOG(1) << "Grew file " << file_path_ << " to new size " << new_file_size;
mutable_header()->state = Header::ChecksumState::kStale;
return libtextclassifier3::Status::OK;
}
diff --git a/icing/file/filesystem.cc b/icing/file/filesystem.cc
index 82b8d98..4897001 100644
--- a/icing/file/filesystem.cc
+++ b/icing/file/filesystem.cc
@@ -63,18 +63,16 @@ void LogOpenFileDescriptors() {
constexpr int kMaxFileDescriptorsToStat = 4096;
struct rlimit rlim = {0, 0};
if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "getrlimit() failed (errno=%d)", errno);
+ ICING_LOG(ERROR) << "getrlimit() failed (errno=" << errno << ")";
return;
}
int fd_lim = rlim.rlim_cur;
if (fd_lim > kMaxFileDescriptorsToStat) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Maximum number of file descriptors (%d) too large.", fd_lim);
+ ICING_LOG(ERROR) << "Maximum number of file descriptors (" << fd_lim
+ << ") too large.";
fd_lim = kMaxFileDescriptorsToStat;
}
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Listing up to %d file descriptors.", fd_lim);
+ ICING_LOG(ERROR) << "Listing up to " << fd_lim << " file descriptors.";
// Verify that /proc/self/fd is a directory. If not, procfs is not mounted or
// inaccessible for some other reason. In that case, there's no point trying
@@ -96,15 +94,12 @@ void LogOpenFileDescriptors() {
if (len >= 0) {
// Zero-terminate the buffer, because readlink() won't.
target[len < target_size ? len : target_size - 1] = '\0';
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("fd %d -> \"%s\"", fd,
- target);
+ ICING_LOG(ERROR) << "fd " << fd << " -> \"" << target << "\"";
} else if (errno != ENOENT) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("fd %d -> ? (errno=%d)",
- fd, errno);
+ ICING_LOG(ERROR) << "fd " << fd << " -> ? (errno=" << errno << ")";
}
}
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "File descriptor list complete.");
+ ICING_LOG(ERROR) << "File descriptor list complete.";
}
// Logs an error formatted as: desc1 + file_name + desc2 + strerror(errnum).
@@ -113,8 +108,7 @@ void LogOpenFileDescriptors() {
// file descriptors (see LogOpenFileDescriptors() above).
void LogOpenError(const char* desc1, const char* file_name, const char* desc2,
int errnum) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "%s%s%s%s", desc1, file_name, desc2, strerror(errnum));
+ ICING_LOG(ERROR) << desc1 << file_name << desc2 << strerror(errnum);
if (errnum == EMFILE) {
LogOpenFileDescriptors();
}
@@ -155,8 +149,7 @@ bool ListDirectoryInternal(const char* dir_name,
}
}
if (closedir(dir) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Error closing %s: %s", dir_name, strerror(errno));
+ ICING_LOG(ERROR) << "Error closing " << dir_name << " " << strerror(errno);
}
return true;
}
@@ -179,11 +172,10 @@ void ScopedFd::reset(int fd) {
const int64_t Filesystem::kBadFileSize;
bool Filesystem::DeleteFile(const char* file_name) const {
- ICING_VLOG(1) << IcingStringUtil::StringPrintf("Deleting file %s", file_name);
+ ICING_VLOG(1) << "Deleting file " << file_name;
int ret = unlink(file_name);
if (ret != 0 && errno != ENOENT) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Deleting file %s failed: %s", file_name, strerror(errno));
+ ICING_LOG(ERROR) << "Deleting file " << file_name << " failed: " << strerror(errno);
return false;
}
return true;
@@ -192,8 +184,7 @@ bool Filesystem::DeleteFile(const char* file_name) const {
bool Filesystem::DeleteDirectory(const char* dir_name) const {
int ret = rmdir(dir_name);
if (ret != 0 && errno != ENOENT) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Deleting directory %s failed: %s", dir_name, strerror(errno));
+ ICING_LOG(ERROR) << "Deleting directory " << dir_name << " failed: " << strerror(errno);
return false;
}
return true;
@@ -206,8 +197,7 @@ bool Filesystem::DeleteDirectoryRecursively(const char* dir_name) const {
if (errno == ENOENT) {
return true; // If directory didn't exist, this was successful.
}
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Stat %s failed: %s", dir_name, strerror(errno));
+ ICING_LOG(ERROR) << "Stat " << dir_name << " failed: " << strerror(errno);
return false;
}
vector<std::string> entries;
@@ -220,8 +210,7 @@ bool Filesystem::DeleteDirectoryRecursively(const char* dir_name) const {
++i) {
std::string filename = std::string(dir_name) + '/' + *i;
if (stat(filename.c_str(), &st) < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Stat %s failed: %s", filename.c_str(), strerror(errno));
+ ICING_LOG(ERROR) << "Stat " << filename << " failed: " << strerror(errno);
success = false;
} else if (S_ISDIR(st.st_mode)) {
success = DeleteDirectoryRecursively(filename.c_str()) && success;
@@ -244,8 +233,7 @@ bool Filesystem::FileExists(const char* file_name) const {
exists = S_ISREG(st.st_mode) != 0;
} else {
if (errno != ENOENT) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Unable to stat file %s: %s", file_name, strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat file " << file_name << ": " << strerror(errno);
}
exists = false;
}
@@ -259,8 +247,7 @@ bool Filesystem::DirectoryExists(const char* dir_name) const {
exists = S_ISDIR(st.st_mode) != 0;
} else {
if (errno != ENOENT) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Unable to stat directory %s: %s", dir_name, strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat directory " << dir_name << ": " << strerror(errno);
}
exists = false;
}
@@ -316,8 +303,7 @@ bool Filesystem::GetMatchingFiles(const char* glob,
int basename_idx = GetBasenameIndex(glob);
if (basename_idx == 0) {
// We need a directory.
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "Expected directory, no matching files for: %s", glob);
+ ICING_VLOG(1) << "Expected directory, no matching files for: " << glob;
return true;
}
const char* basename_glob = glob + basename_idx;
@@ -372,8 +358,7 @@ int Filesystem::OpenForRead(const char* file_name) const {
int64_t Filesystem::GetFileSize(int fd) const {
struct stat st;
if (fstat(fd, &st) < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to stat file: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat file: " << strerror(errno);
return kBadFileSize;
}
return st.st_size;
@@ -383,11 +368,11 @@ int64_t Filesystem::GetFileSize(const char* filename) const {
struct stat st;
if (stat(filename, &st) < 0) {
if (errno == ENOENT) {
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "Unable to stat file %s: %s", filename, strerror(errno));
+ ICING_VLOG(1) << "Unable to stat file " << filename << ": "
+ << strerror(errno);
} else {
- ICING_LOG(WARNING) << IcingStringUtil::StringPrintf(
- "Unable to stat file %s: %s", filename, strerror(errno));
+ ICING_LOG(WARNING) << "Unable to stat file " << filename << ": "
+ << strerror(errno);
}
return kBadFileSize;
}
@@ -396,8 +381,7 @@ int64_t Filesystem::GetFileSize(const char* filename) const {
bool Filesystem::Truncate(int fd, int64_t new_size) const {
if (ftruncate(fd, new_size) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Unable to truncate file: %s", strerror(errno));
+ ICING_LOG(ERROR) << "Unable to truncate file: " << strerror(errno);
return false;
}
lseek(fd, new_size, SEEK_SET);
@@ -416,8 +400,7 @@ bool Filesystem::Truncate(const char* filename, int64_t new_size) const {
bool Filesystem::Grow(int fd, int64_t new_size) const {
if (ftruncate(fd, new_size) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to grow file: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Unable to grow file: " << strerror(errno);
return false;
}
@@ -442,8 +425,7 @@ bool Filesystem::Write(int fd, const void* data, size_t data_size) const {
size_t chunk_size = std::min<size_t>(write_len, 64u * 1024);
ssize_t wrote = write(fd, data, chunk_size);
if (wrote < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Bad write: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Bad write: " << strerror(errno);
return false;
}
data = static_cast<const uint8_t*>(data) + wrote;
@@ -521,8 +503,7 @@ bool Filesystem::CopyDirectory(const char* src_dir, const char* dst_dir,
}
}
if (closedir(dir) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Error closing %s: %s",
- src_dir, strerror(errno));
+ ICING_LOG(ERROR) << "Error closing " << src_dir << ": " << strerror(errno);
}
return true;
}
@@ -535,8 +516,7 @@ bool Filesystem::PWrite(int fd, off_t offset, const void* data,
size_t chunk_size = std::min<size_t>(write_len, 64u * 1024);
ssize_t wrote = pwrite(fd, data, chunk_size, offset);
if (wrote < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Bad write: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Bad write: " << strerror(errno);
return false;
}
data = static_cast<const uint8_t*>(data) + wrote;
@@ -561,8 +541,7 @@ bool Filesystem::PWrite(const char* filename, off_t offset, const void* data,
bool Filesystem::Read(int fd, void* buf, size_t buf_size) const {
ssize_t read_status = read(fd, buf, buf_size);
if (read_status < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Bad read: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Bad read: " << strerror(errno);
return false;
}
return true;
@@ -582,8 +561,7 @@ bool Filesystem::Read(const char* filename, void* buf, size_t buf_size) const {
bool Filesystem::PRead(int fd, void* buf, size_t buf_size, off_t offset) const {
ssize_t read_status = pread(fd, buf, buf_size, offset);
if (read_status < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Bad read: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Bad read: " << strerror(errno);
return false;
}
return true;
@@ -609,8 +587,7 @@ bool Filesystem::DataSync(int fd) const {
#endif
if (result < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to sync data: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Unable to sync data: " << strerror(errno);
return false;
}
return true;
@@ -618,9 +595,8 @@ bool Filesystem::DataSync(int fd) const {
bool Filesystem::RenameFile(const char* old_name, const char* new_name) const {
if (rename(old_name, new_name) < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Unable to rename file %s to %s: %s", old_name, new_name,
- strerror(errno));
+ ICING_LOG(ERROR) << "Unable to rename file " << old_name << " to "
+ << new_name << ": " << strerror(errno);
return false;
}
return true;
@@ -658,8 +634,7 @@ bool Filesystem::CreateDirectory(const char* dir_name) const {
if (mkdir(dir_name, S_IRUSR | S_IWUSR | S_IXUSR) == 0) {
success = true;
} else {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Creating directory %s failed: %s", dir_name, strerror(errno));
+ ICING_LOG(ERROR) << "Creating directory " << dir_name << " failed: " << strerror(errno);
}
}
return success;
@@ -679,8 +654,7 @@ bool Filesystem::CreateDirectoryRecursively(const char* dir_name) const {
int64_t Filesystem::GetDiskUsage(int fd) const {
struct stat st;
if (fstat(fd, &st) < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to stat file: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat file: " << strerror(errno);
return kBadFileSize;
}
return st.st_blocks * kStatBlockSize;
@@ -689,8 +663,7 @@ int64_t Filesystem::GetDiskUsage(int fd) const {
int64_t Filesystem::GetFileDiskUsage(const char* path) const {
struct stat st;
if (stat(path, &st) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to stat %s: %s",
- path, strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat " << path << ": " << strerror(errno);
return kBadFileSize;
}
return st.st_blocks * kStatBlockSize;
@@ -699,8 +672,7 @@ int64_t Filesystem::GetFileDiskUsage(const char* path) const {
int64_t Filesystem::GetDiskUsage(const char* path) const {
struct stat st;
if (stat(path, &st) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to stat %s: %s",
- path, strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat " << path << ": " << strerror(errno);
return kBadFileSize;
}
int64_t result = st.st_blocks * kStatBlockSize;
diff --git a/icing/icing-search-engine.cc b/icing/icing-search-engine.cc
index e390f0f..2768a06 100644
--- a/icing/icing-search-engine.cc
+++ b/icing/icing-search-engine.cc
@@ -263,9 +263,9 @@ void TransformStatus(const libtextclassifier3::Status& internal_status,
case libtextclassifier3::StatusCode::UNAUTHENTICATED:
// Other internal status codes aren't supported externally yet. If it
// should be supported, add another switch-case above.
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Internal status code %d not supported in the external API",
- internal_status.error_code());
+ ICING_LOG(ERROR) << "Internal status code "
+ << internal_status.error_code()
+ << " not supported in the external API";
code = StatusProto::UNKNOWN;
break;
}
diff --git a/icing/index/lite/lite-index.cc b/icing/index/lite/lite-index.cc
index fc40225..9faa871 100644
--- a/icing/index/lite/lite-index.cc
+++ b/icing/index/lite/lite-index.cc
@@ -197,8 +197,7 @@ libtextclassifier3::Status LiteIndex::Initialize() {
}
}
- ICING_VLOG(2) << IcingStringUtil::StringPrintf("Lite index init ok in %.3fms",
- timer.Elapsed() * 1000);
+ ICING_VLOG(2) << "Lite index init ok in " << timer.Elapsed() * 1000 << "ms";
return status;
error:
@@ -230,8 +229,7 @@ Crc32 LiteIndex::ComputeChecksum() {
Crc32 all_crc(header_->CalculateHeaderCrc());
all_crc.Append(std::string_view(reinterpret_cast<const char*>(dependent_crcs),
sizeof(dependent_crcs)));
- ICING_VLOG(2) << IcingStringUtil::StringPrintf(
- "Lite index crc computed in %.3fms", timer.Elapsed() * 1000);
+ ICING_VLOG(2) << "Lite index crc computed in " << timer.Elapsed() * 1000 << "ms";
return all_crc;
}
@@ -245,9 +243,7 @@ libtextclassifier3::Status LiteIndex::Reset() {
hit_buffer_.Clear();
header_->Reset();
UpdateChecksum();
-
- ICING_VLOG(2) << IcingStringUtil::StringPrintf("Lite index clear in %.3fms",
- timer.Elapsed() * 1000);
+ ICING_VLOG(2) << "Lite index clear in " << timer.Elapsed() * 1000 << "ms";
return libtextclassifier3::Status::OK;
}
@@ -457,9 +453,8 @@ uint32_t LiteIndex::Seek(uint32_t term_id) {
std::inplace_merge(array_start, array_start + header_->searchable_end(),
array_start + header_->cur_size());
}
- ICING_VLOG(2) << IcingStringUtil::StringPrintf(
- "Lite index sort and merge %u into %u in %.3fms", sort_len,
- header_->searchable_end(), timer.Elapsed() * 1000);
+ ICING_VLOG(2) << "Lite index sort and merge " << sort_len << " into "
+ << header_->searchable_end() << " in " << timer.Elapsed() * 1000 << "ms";
// Now the entire array is sorted.
header_->set_searchable_end(header_->cur_size());
diff --git a/icing/index/main/flash-index-storage.cc b/icing/index/main/flash-index-storage.cc
index dabff28..d769669 100644
--- a/icing/index/main/flash-index-storage.cc
+++ b/icing/index/main/flash-index-storage.cc
@@ -133,9 +133,9 @@ bool FlashIndexStorage::CreateHeader() {
posting_list_bytes /= 2) {
uint32_t aligned_posting_list_bytes =
(posting_list_bytes / sizeof(Hit) * sizeof(Hit));
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "Block size %u: %u", header_block_->header()->num_index_block_infos,
- aligned_posting_list_bytes);
+ ICING_VLOG(1) << "Block size "
+ << header_block_->header()->num_index_block_infos << ": "
+ << aligned_posting_list_bytes;
// Initialize free list to empty.
HeaderBlock::Header::IndexBlockInfo* block_info =
@@ -169,23 +169,22 @@ bool FlashIndexStorage::OpenHeader(int64_t file_size) {
return false;
}
if (file_size % read_header.header()->block_size != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Index size %" PRIu64 " not a multiple of block size %u", file_size,
- read_header.header()->block_size);
+ ICING_LOG(ERROR) << "Index size " << file_size
+ << " not a multiple of block size "
+ << read_header.header()->block_size;
return false;
}
if (file_size < static_cast<int64_t>(read_header.header()->block_size)) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Index size %" PRIu64 " shorter than block size %u", file_size,
- read_header.header()->block_size);
+ ICING_LOG(ERROR) << "Index size " << file_size
+ << " shorter than block size "
+ << read_header.header()->block_size;
return false;
}
if (read_header.header()->block_size % getpagesize() != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Block size %u is not a multiple of page size %d",
- read_header.header()->block_size, getpagesize());
+ ICING_LOG(ERROR) << "Block size " << read_header.header()->block_size
+ << " is not a multiple of page size " << getpagesize();
return false;
}
num_blocks_ = file_size / read_header.header()->block_size;
@@ -215,11 +214,10 @@ bool FlashIndexStorage::OpenHeader(int64_t file_size) {
int posting_list_bytes =
header_block_->header()->index_block_infos[i].posting_list_bytes;
if (posting_list_bytes % sizeof(Hit) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Posting list size misaligned, index %u, size %u, hit %zu, "
- "file_size %" PRIu64,
- i, header_block_->header()->index_block_infos[i].posting_list_bytes,
- sizeof(Hit), file_size);
+ ICING_LOG(ERROR) << "Posting list size misaligned, index " << i
+ << ", size "
+ << header_block_->header()->index_block_infos[i].posting_list_bytes
+ << ", hit " << sizeof(Hit) << ", file_size " << file_size;
return false;
}
}
@@ -229,8 +227,7 @@ bool FlashIndexStorage::OpenHeader(int64_t file_size) {
bool FlashIndexStorage::PersistToDisk() {
// First, write header.
if (!header_block_->Write(block_fd_.get())) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Write index header failed: %s", strerror(errno));
+ ICING_LOG(ERROR) << "Write index header failed: " << strerror(errno);
return false;
}
@@ -456,8 +453,7 @@ void FlashIndexStorage::FreePostingList(PostingListHolder holder) {
int FlashIndexStorage::GrowIndex() {
if (num_blocks_ >= kMaxBlockIndex) {
- ICING_VLOG(1) << IcingStringUtil::StringPrintf("Reached max block index %u",
- kMaxBlockIndex);
+ ICING_VLOG(1) << "Reached max block index " << kMaxBlockIndex;
return kInvalidBlockIndex;
}
@@ -465,8 +461,7 @@ int FlashIndexStorage::GrowIndex() {
if (!filesystem_->Grow(
block_fd_.get(),
static_cast<uint64_t>(num_blocks_ + 1) * block_size())) {
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "Error growing index file: %s", strerror(errno));
+ ICING_VLOG(1) << "Error growing index file: " << strerror(errno);
return kInvalidBlockIndex;
}
diff --git a/icing/index/main/main-index.cc b/icing/index/main/main-index.cc
index 158c287..f56d189 100644
--- a/icing/index/main/main-index.cc
+++ b/icing/index/main/main-index.cc
@@ -490,8 +490,7 @@ libtextclassifier3::Status MainIndex::AddHits(
}
// Now copy remaining backfills.
- ICING_VLOG(1) << IcingStringUtil::StringPrintf("Remaining backfills %zu",
- backfill_map.size());
+ ICING_VLOG(1) << "Remaining backfills " << backfill_map.size();
for (auto other_tvi_main_tvi_pair : backfill_map) {
PostingListIdentifier backfill_posting_list_id =
PostingListIdentifier::kInvalid;
@@ -524,9 +523,9 @@ libtextclassifier3::Status MainIndex::AddHitsForTerm(
std::unique_ptr<PostingListAccessor> pl_accessor;
if (posting_list_id.is_valid()) {
if (posting_list_id.block_index() >= flash_index_storage_->num_blocks()) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Index dropped hits. Invalid block index %u >= %u",
- posting_list_id.block_index(), flash_index_storage_->num_blocks());
+ ICING_LOG(ERROR) << "Index dropped hits. Invalid block index "
+ << posting_list_id.block_index() << " >= "
+ << flash_index_storage_->num_blocks();
// TODO(b/159918304) : Consider revising the checksumming strategy in the
// main index. Providing some mechanism to check for corruption - either
// during initialization or some later time would allow us to avoid
diff --git a/icing/legacy/index/icing-array-storage.cc b/icing/legacy/index/icing-array-storage.cc
index 4d2ef67..4e1f53e 100644
--- a/icing/legacy/index/icing-array-storage.cc
+++ b/icing/legacy/index/icing-array-storage.cc
@@ -65,17 +65,15 @@ bool IcingArrayStorage::Init(int fd, size_t fd_offset, bool map_shared,
return false;
}
if (file_size < fd_offset) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Array storage file size %" PRIu64 " less than offset %zu", file_size,
- fd_offset);
+ ICING_LOG(ERROR) << "Array storage file size " << file_size
+ << " less than offset " << fd_offset;
return false;
}
uint32_t capacity_num_elts = (file_size - fd_offset) / elt_size;
if (capacity_num_elts < num_elts) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Array storage num elts %u > capacity num elts %u", num_elts,
- capacity_num_elts);
+ ICING_LOG(ERROR) << "Array storage num elts " << num_elts
+ << " > capacity num elts " << capacity_num_elts;
return false;
}
@@ -108,8 +106,8 @@ bool IcingArrayStorage::Init(int fd, size_t fd_offset, bool map_shared,
if (init_crc) {
*crc_ptr_ = crc;
} else if (crc != *crc_ptr_) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Array storage bad crc %u vs %u", crc, *crc_ptr_);
+ ICING_LOG(ERROR) << "Array storage bad crc " << crc << " vs "
+ << *crc_ptr_;
goto failed;
}
}
@@ -276,9 +274,9 @@ void IcingArrayStorage::UpdateCrc() {
cur_offset += change.elt_len * elt_size_;
}
if (!changes_.empty()) {
- ICING_VLOG(2) << IcingStringUtil::StringPrintf(
- "Array update partial crcs %d truncated %d overlapped %d duplicate %d",
- num_partial_crcs, num_truncated, num_overlapped, num_duplicate);
+ ICING_VLOG(2) << "Array update partial crcs " << num_partial_crcs
+ << " truncated " << num_truncated << " overlapped " << num_overlapped
+ << " duplicate " << num_duplicate;
}
// Now update with grown area.
@@ -286,8 +284,7 @@ void IcingArrayStorage::UpdateCrc() {
cur_crc = IcingStringUtil::UpdateCrc32(
cur_crc, array_cast<char>() + changes_end_ * elt_size_,
(cur_num_ - changes_end_) * elt_size_);
- ICING_VLOG(2) << IcingStringUtil::StringPrintf(
- "Array update tail crc offset %u -> %u", changes_end_, cur_num_);
+ ICING_VLOG(2) << "Array update tail crc offset " << changes_end_ << " -> " << cur_num_;
}
// Clear, now that we've applied changes.
@@ -341,8 +338,8 @@ uint32_t IcingArrayStorage::Sync() {
if (pwrite(fd_, array() + dirty_start, dirty_end - dirty_start,
fd_offset_ + dirty_start) !=
static_cast<ssize_t>(dirty_end - dirty_start)) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Flushing pages failed (%u, %u)", dirty_start, dirty_end);
+ ICING_LOG(ERROR) << "Flushing pages failed (" << dirty_start << ", "
+ << dirty_end << ")";
}
in_dirty = false;
} else if (!in_dirty && is_dirty) {
@@ -361,8 +358,8 @@ uint32_t IcingArrayStorage::Sync() {
if (pwrite(fd_, array() + dirty_start, dirty_end - dirty_start,
fd_offset_ + dirty_start) !=
static_cast<ssize_t>(dirty_end - dirty_start)) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Flushing pages failed (%u, %u)", dirty_start, dirty_end);
+ ICING_LOG(ERROR) << "Flushing pages failed (" << dirty_start << ", "
+ << dirty_end << ")";
}
}
@@ -377,9 +374,9 @@ uint32_t IcingArrayStorage::Sync() {
}
if (num_flushed > 0) {
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "Flushing %u/%u %u contiguous pages in %.3fms", num_flushed,
- dirty_pages_size, num_contiguous, timer.Elapsed() * 1000.);
+ ICING_VLOG(1) << "Flushing " << num_flushed << "/" << dirty_pages_size
+ << " " << num_contiguous << " contiguous pages in "
+ << timer.Elapsed() * 1000 << "ms.";
}
return num_flushed;
diff --git a/icing/legacy/index/icing-dynamic-trie.cc b/icing/legacy/index/icing-dynamic-trie.cc
index 4428599..4bac329 100644
--- a/icing/legacy/index/icing-dynamic-trie.cc
+++ b/icing/legacy/index/icing-dynamic-trie.cc
@@ -460,8 +460,7 @@ bool IcingDynamicTrie::IcingDynamicTrieStorage::Init() {
if (i == 0) {
// Header.
if (file_size != IcingMMapper::system_page_size()) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Trie hdr wrong size: %" PRIu64, file_size);
+ ICING_LOG(ERROR) << "Trie hdr wrong size: " << file_size;
goto failed;
}
@@ -522,8 +521,7 @@ bool IcingDynamicTrie::IcingDynamicTrieStorage::Init() {
sizeof(char), hdr_.hdr.suffixes_size(),
hdr_.hdr.max_suffixes_size(),
&crcs_->array_crcs[SUFFIX], init_crcs)) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Trie mmap suffix failed");
+ ICING_LOG(ERROR) << "Trie mmap suffix failed";
goto failed;
}
@@ -671,8 +669,7 @@ bool IcingDynamicTrie::IcingDynamicTrieStorage::Sync() {
}
if (!WriteHeader()) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Flushing trie header failed: %s", strerror(errno));
+ ICING_LOG(ERROR) << "Flushing trie header failed: " << strerror(errno);
success = false;
}
@@ -686,8 +683,7 @@ bool IcingDynamicTrie::IcingDynamicTrieStorage::Sync() {
}
if (total_flushed > 0) {
- ICING_VLOG(1) << IcingStringUtil::StringPrintf("Flushing %u pages of trie",
- total_flushed);
+ ICING_VLOG(1) << "Flushing " << total_flushed << " pages of trie";
}
return success;
@@ -817,8 +813,7 @@ uint32_t IcingDynamicTrie::IcingDynamicTrieStorage::UpdateCrc() {
uint32_t IcingDynamicTrie::IcingDynamicTrieStorage::UpdateCrcInternal(
bool write_hdr) {
if (write_hdr && !WriteHeader()) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Flushing trie header failed: %s", strerror(errno));
+ ICING_LOG(ERROR) << "Flushing trie header failed: " << strerror(errno);
}
crcs_->header_crc = GetHeaderCrc();
@@ -912,8 +907,7 @@ bool IcingDynamicTrie::IcingDynamicTrieStorage::Header::SerializeToArray(
bool IcingDynamicTrie::IcingDynamicTrieStorage::Header::Verify() {
// Check version.
if (hdr.version() != kCurVersion) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Trie version %u mismatch", hdr.version());
+ ICING_LOG(ERROR) << "Trie version " << hdr.version() << " mismatch";
return false;
}
@@ -1155,9 +1149,8 @@ bool IcingDynamicTrie::Sync() {
Warm();
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "Syncing dynamic trie %s took %.3fms", filename_base_.c_str(),
- timer.Elapsed() * 1000.);
+ ICING_VLOG(1) << "Syncing dynamic trie " << filename_base_.c_str()
+ << " took " << timer.Elapsed() * 1000 << "ms";
return success;
}
@@ -1207,8 +1200,7 @@ std::unique_ptr<IcingFlashBitmap> IcingDynamicTrie::OpenAndInitBitmap(
const IcingFilesystem *filesystem) {
auto bitmap = std::make_unique<IcingFlashBitmap>(filename, filesystem);
if (!bitmap->Init() || (verify && !bitmap->Verify())) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Init of %s failed",
- filename.c_str());
+ ICING_LOG(ERROR) << "Init of " << filename.c_str() << " failed";
return nullptr;
}
return bitmap;
@@ -1238,16 +1230,14 @@ bool IcingDynamicTrie::InitPropertyBitmaps() {
vector<std::string> files;
if (!filesystem_->GetMatchingFiles((property_bitmaps_prefix_ + "*").c_str(),
&files)) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Could not get files at prefix %s", property_bitmaps_prefix_.c_str());
+ ICING_LOG(ERROR) << "Could not get files at prefix " << property_bitmaps_prefix_;
goto failed;
}
for (size_t i = 0; i < files.size(); i++) {
// Decode property id from filename.
size_t property_id_start_idx = files[i].rfind('.');
if (property_id_start_idx == std::string::npos) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Malformed filename %s",
- files[i].c_str());
+ ICING_LOG(ERROR) << "Malformed filename " << files[i];
continue;
}
property_id_start_idx++; // skip dot
@@ -1255,8 +1245,7 @@ bool IcingDynamicTrie::InitPropertyBitmaps() {
uint32_t property_id =
strtol(files[i].c_str() + property_id_start_idx, &end, 10); // NOLINT
if (!end || end != (files[i].c_str() + files[i].size())) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Malformed filename %s",
- files[i].c_str());
+ ICING_LOG(ERROR) << "Malformed filename " << files[i];
continue;
}
std::unique_ptr<IcingFlashBitmap> bitmap = OpenAndInitBitmap(
@@ -1264,8 +1253,7 @@ bool IcingDynamicTrie::InitPropertyBitmaps() {
runtime_options_.storage_policy == RuntimeOptions::kMapSharedWithCrc,
filesystem_);
if (!bitmap) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Open prop bitmap failed: %s", files[i].c_str());
+ ICING_LOG(ERROR) << "Open prop bitmap failed: " << files[i];
goto failed;
}
bitmap->Truncate(truncate_idx);
@@ -2320,8 +2308,7 @@ void IcingDynamicTrie::GetDebugInfo(int verbosity, std::string *out) const {
vector<std::string> files;
if (!filesystem_->GetMatchingFiles((property_bitmaps_prefix_ + "*").c_str(),
&files)) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Could not get files at prefix %s", property_bitmaps_prefix_.c_str());
+ ICING_LOG(ERROR) << "Could not get files at prefix " << property_bitmaps_prefix_;
return;
}
for (size_t i = 0; i < files.size(); i++) {
@@ -2393,8 +2380,7 @@ IcingFlashBitmap *IcingDynamicTrie::OpenOrCreatePropertyBitmap(
}
if (property_id > kMaxPropertyId) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Property id %u out of range", property_id);
+ ICING_LOG(ERROR) << "Property id " << property_id << " out of range";
return nullptr;
}
@@ -2567,8 +2553,7 @@ bool IcingDynamicTrie::ClearPropertyForAllValues(uint32_t property_id) {
PropertyReadersAll readers(*this);
if (!readers.Exists(property_id)) {
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "Properties for id %u don't exist", property_id);
+ ICING_VLOG(1) << "Properties for id " << property_id << " don't exist";
return true;
}
diff --git a/icing/legacy/index/icing-filesystem.cc b/icing/legacy/index/icing-filesystem.cc
index 4f5e571..a8c7c79 100644
--- a/icing/legacy/index/icing-filesystem.cc
+++ b/icing/legacy/index/icing-filesystem.cc
@@ -65,18 +65,16 @@ void LogOpenFileDescriptors() {
constexpr int kMaxFileDescriptorsToStat = 4096;
struct rlimit rlim = {0, 0};
if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "getrlimit() failed (errno=%d)", errno);
+ ICING_LOG(ERROR) << "getrlimit() failed (errno=" << errno << ")";
return;
}
int fd_lim = rlim.rlim_cur;
if (fd_lim > kMaxFileDescriptorsToStat) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Maximum number of file descriptors (%d) too large.", fd_lim);
+ ICING_LOG(ERROR) << "Maximum number of file descriptors (" << fd_lim
+ << ") too large.";
fd_lim = kMaxFileDescriptorsToStat;
}
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Listing up to %d file descriptors.", fd_lim);
+ ICING_LOG(ERROR) << "Listing up to " << fd_lim << " file descriptors.";
// Verify that /proc/self/fd is a directory. If not, procfs is not mounted or
// inaccessible for some other reason. In that case, there's no point trying
@@ -98,15 +96,12 @@ void LogOpenFileDescriptors() {
if (len >= 0) {
// Zero-terminate the buffer, because readlink() won't.
target[len < target_size ? len : target_size - 1] = '\0';
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("fd %d -> \"%s\"", fd,
- target);
+ ICING_LOG(ERROR) << "fd " << fd << " -> \"" << target << "\"";
} else if (errno != ENOENT) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("fd %d -> ? (errno=%d)",
- fd, errno);
+ ICING_LOG(ERROR) << "fd " << fd << " -> ? (errno=" << errno << ")";
}
}
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "File descriptor list complete.");
+ ICING_LOG(ERROR) << "File descriptor list complete.";
}
// Logs an error formatted as: desc1 + file_name + desc2 + strerror(errnum).
@@ -115,8 +110,7 @@ void LogOpenFileDescriptors() {
// file descriptors (see LogOpenFileDescriptors() above).
void LogOpenError(const char *desc1, const char *file_name, const char *desc2,
int errnum) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "%s%s%s%s", desc1, file_name, desc2, strerror(errnum));
+ ICING_LOG(ERROR) << desc1 << file_name << desc2 << strerror(errnum);
if (errnum == EMFILE) {
LogOpenFileDescriptors();
}
@@ -157,8 +151,7 @@ bool ListDirectoryInternal(const char *dir_name,
}
}
if (closedir(dir) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Error closing %s: %s", dir_name, strerror(errno));
+ ICING_LOG(ERROR) << "Error closing " << dir_name << ": " << strerror(errno);
}
return true;
}
@@ -181,12 +174,12 @@ void IcingScopedFd::reset(int fd) {
const uint64_t IcingFilesystem::kBadFileSize;
bool IcingFilesystem::DeleteFile(const char *file_name) const {
- ICING_VLOG(1) << IcingStringUtil::StringPrintf("Deleting file %s", file_name);
+ ICING_VLOG(1) << "Deleting file " << file_name;
int ret = unlink(file_name);
bool success = (ret == 0) || (errno == ENOENT);
if (!success) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Deleting file %s failed: %s", file_name, strerror(errno));
+ ICING_LOG(ERROR) << "Deleting file " << file_name << " failed: "
+ << strerror(errno);
}
return success;
}
@@ -195,8 +188,8 @@ bool IcingFilesystem::DeleteDirectory(const char *dir_name) const {
int ret = rmdir(dir_name);
bool success = (ret == 0) || (errno == ENOENT);
if (!success) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Deleting directory %s failed: %s", dir_name, strerror(errno));
+ ICING_LOG(ERROR) << "Deleting directory " << dir_name << " failed: "
+ << strerror(errno);
}
return success;
}
@@ -208,8 +201,7 @@ bool IcingFilesystem::DeleteDirectoryRecursively(const char *dir_name) const {
if (errno == ENOENT) {
return true; // If directory didn't exist, this was successful.
}
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Stat %s failed: %s", dir_name, strerror(errno));
+ ICING_LOG(ERROR) << "Stat " << dir_name << " failed: " << strerror(errno);
return false;
}
vector<std::string> entries;
@@ -222,8 +214,7 @@ bool IcingFilesystem::DeleteDirectoryRecursively(const char *dir_name) const {
++i) {
std::string filename = std::string(dir_name) + '/' + *i;
if (stat(filename.c_str(), &st) < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Stat %s failed: %s", filename.c_str(), strerror(errno));
+ ICING_LOG(ERROR) << "Stat " << filename << " failed: " << strerror(errno);
success = false;
} else if (S_ISDIR(st.st_mode)) {
success = DeleteDirectoryRecursively(filename.c_str()) && success;
@@ -246,8 +237,8 @@ bool IcingFilesystem::FileExists(const char *file_name) const {
exists = S_ISREG(st.st_mode) != 0;
} else {
if (errno != ENOENT) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Unable to stat file %s: %s", file_name, strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat file " << file_name << ": "
+ << strerror(errno);
}
exists = false;
}
@@ -261,8 +252,8 @@ bool IcingFilesystem::DirectoryExists(const char *dir_name) const {
exists = S_ISDIR(st.st_mode) != 0;
} else {
if (errno != ENOENT) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Unable to stat directory %s: %s", dir_name, strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat directory " << dir_name << ": "
+ << strerror(errno);
}
exists = false;
}
@@ -317,8 +308,7 @@ bool IcingFilesystem::GetMatchingFiles(const char *glob,
int basename_idx = GetBasenameIndex(glob);
if (basename_idx == 0) {
// We need a directory.
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "Expected directory, no matching files for: %s", glob);
+ ICING_VLOG(1) << "Expected directory, no matching files for: " << glob;
return true;
}
const char *basename_glob = glob + basename_idx;
@@ -374,8 +364,7 @@ uint64_t IcingFilesystem::GetFileSize(int fd) const {
struct stat st;
uint64_t size = kBadFileSize;
if (fstat(fd, &st) < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to stat file: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat file: " << strerror(errno);
} else {
size = st.st_size;
}
@@ -386,8 +375,8 @@ uint64_t IcingFilesystem::GetFileSize(const char *filename) const {
struct stat st;
uint64_t size = kBadFileSize;
if (stat(filename, &st) < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Unable to stat file %s: %s", filename, strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat file " << filename << ": "
+ << strerror(errno);
} else {
size = st.st_size;
}
@@ -399,8 +388,7 @@ bool IcingFilesystem::Truncate(int fd, uint64_t new_size) const {
if (ret == 0) {
lseek(fd, new_size, SEEK_SET);
} else {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Unable to truncate file: %s", strerror(errno));
+ ICING_LOG(ERROR) << "Unable to truncate file: " << strerror(errno);
}
return (ret == 0);
}
@@ -418,8 +406,7 @@ bool IcingFilesystem::Truncate(const char *filename, uint64_t new_size) const {
bool IcingFilesystem::Grow(int fd, uint64_t new_size) const {
int ret = ftruncate(fd, new_size);
if (ret != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to grow file: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Unable to grow file: " << strerror(errno);
}
return (ret == 0);
}
@@ -431,8 +418,7 @@ bool IcingFilesystem::Write(int fd, const void *data, size_t data_size) const {
size_t chunk_size = std::min<size_t>(write_len, 64u * 1024);
ssize_t wrote = write(fd, data, chunk_size);
if (wrote < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Bad write: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Bad write: " << strerror(errno);
return false;
}
data = static_cast<const uint8_t *>(data) + wrote;
@@ -449,8 +435,7 @@ bool IcingFilesystem::PWrite(int fd, off_t offset, const void *data,
size_t chunk_size = std::min<size_t>(write_len, 64u * 1024);
ssize_t wrote = pwrite(fd, data, chunk_size, offset);
if (wrote < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Bad write: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Bad write: " << strerror(errno);
return false;
}
data = static_cast<const uint8_t *>(data) + wrote;
@@ -468,8 +453,7 @@ bool IcingFilesystem::DataSync(int fd) const {
#endif
if (result < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to sync data: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Unable to sync data: " << strerror(errno);
return false;
}
return true;
@@ -478,9 +462,8 @@ bool IcingFilesystem::DataSync(int fd) const {
bool IcingFilesystem::RenameFile(const char *old_name,
const char *new_name) const {
if (rename(old_name, new_name) < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Unable to rename file %s to %s: %s", old_name, new_name,
- strerror(errno));
+ ICING_LOG(ERROR) << "Unable to rename file " << old_name << " to "
+ << new_name << ": " << strerror(errno);
return false;
}
return true;
@@ -518,8 +501,8 @@ bool IcingFilesystem::CreateDirectory(const char *dir_name) const {
if (mkdir(dir_name, S_IRUSR | S_IWUSR | S_IXUSR) == 0) {
success = true;
} else {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Creating directory %s failed: %s", dir_name, strerror(errno));
+ ICING_LOG(ERROR) << "Creating directory " << dir_name << " failed: "
+ << strerror(errno);
}
}
return success;
@@ -561,8 +544,7 @@ end:
if (src_fd > 0) close(src_fd);
if (dst_fd > 0) close(dst_fd);
if (!success) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Couldn't copy file %s to %s", src, dst);
+ ICING_LOG(ERROR) << "Couldn't copy file " << src << " to " << dst;
}
return success;
}
@@ -583,8 +565,7 @@ bool IcingFilesystem::ComputeChecksum(int fd, uint32_t *checksum,
uint64_t IcingFilesystem::GetDiskUsage(int fd) const {
struct stat st;
if (fstat(fd, &st) < 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to stat file: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat file: " << strerror(errno);
return kBadFileSize;
}
return st.st_blocks * kStatBlockSize;
@@ -593,8 +574,7 @@ uint64_t IcingFilesystem::GetDiskUsage(int fd) const {
uint64_t IcingFilesystem::GetFileDiskUsage(const char *path) const {
struct stat st;
if (stat(path, &st) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to stat %s: %s",
- path, strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat " << path << ": " << strerror(errno);
return kBadFileSize;
}
return st.st_blocks * kStatBlockSize;
@@ -603,8 +583,7 @@ uint64_t IcingFilesystem::GetFileDiskUsage(const char *path) const {
uint64_t IcingFilesystem::GetDiskUsage(const char *path) const {
struct stat st;
if (stat(path, &st) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Unable to stat %s: %s",
- path, strerror(errno));
+ ICING_LOG(ERROR) << "Unable to stat " << path << ": " << strerror(errno);
return kBadFileSize;
}
uint64_t result = st.st_blocks * kStatBlockSize;
diff --git a/icing/legacy/index/icing-flash-bitmap.cc b/icing/legacy/index/icing-flash-bitmap.cc
index 56dec00..2b2f9af 100644
--- a/icing/legacy/index/icing-flash-bitmap.cc
+++ b/icing/legacy/index/icing-flash-bitmap.cc
@@ -73,8 +73,7 @@ class IcingFlashBitmap::Accessor {
bool IcingFlashBitmap::Verify() const {
if (!is_initialized()) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Can't verify unopened flash bitmap %s", filename_.c_str());
+ ICING_LOG(ERROR) << "Can't verify unopened flash bitmap " << filename_;
return false;
}
if (mmapper_ == nullptr) {
@@ -83,26 +82,23 @@ bool IcingFlashBitmap::Verify() const {
}
Accessor accessor(mmapper_.get());
if (accessor.header()->magic != kMagic) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Flash bitmap %s has incorrect magic header", filename_.c_str());
+ ICING_LOG(ERROR) << "Flash bitmap " << filename_
+ << " has incorrect magic header";
return false;
}
if (accessor.header()->version != kCurVersion) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Flash bitmap %s has incorrect version", filename_.c_str());
+ ICING_LOG(ERROR) << "Flash bitmap " << filename_ << " has incorrect version";
return false;
}
if (accessor.header()->dirty) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Flash bitmap %s is dirty", filename_.c_str());
+ ICING_LOG(ERROR) << "Flash bitmap " << filename_ << " is dirty";
return false;
}
uint32_t crc =
IcingStringUtil::UpdateCrc32(0, accessor.data(), accessor.data_size());
if (accessor.header()->crc != crc) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Flash bitmap %s has incorrect CRC32 %u %u", filename_.c_str(),
- accessor.header()->crc, crc);
+ ICING_LOG(ERROR) << "Flash bitmap " << filename_ << " has incorrect CRC32 "
+ << accessor.header()->crc << " " << crc;
return false;
}
return true;
@@ -265,17 +261,15 @@ uint32_t IcingFlashBitmap::UpdateCrc() const {
bool IcingFlashBitmap::Grow(size_t new_file_size) {
IcingScopedFd fd(filesystem_->OpenForWrite(filename_.c_str()));
if (!filesystem_->Grow(fd.get(), new_file_size)) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Grow %s to new size %zu failed", filename_.c_str(), new_file_size);
+ ICING_LOG(ERROR) << "Grow " << filename_ << " to new size " << new_file_size
+ << " failed";
return false;
}
if (!mmapper_->Remap(fd.get(), 0, new_file_size)) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Remap of %s after grow failed", filename_.c_str());
+ ICING_LOG(ERROR) << "Remap of " << filename_ << " after grow failed";
return false;
}
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "Grew %s new size %zu", filename_.c_str(), new_file_size);
+ ICING_VLOG(1) << "Grew " << filename_ << " new size " << new_file_size;
Accessor accessor(mmapper_.get());
accessor.header()->dirty = true;
return true;
diff --git a/icing/legacy/index/icing-mmapper.cc b/icing/legacy/index/icing-mmapper.cc
index 7946c82..d086da2 100644
--- a/icing/legacy/index/icing-mmapper.cc
+++ b/icing/legacy/index/icing-mmapper.cc
@@ -67,8 +67,7 @@ void IcingMMapper::DoMapping(int fd, uint64_t location, size_t size) {
address_ = reinterpret_cast<uint8_t *>(mmap_result_) + alignment_adjustment;
} else {
const char *errstr = strerror(errno);
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "Could not mmap file for reading: %s", errstr);
+ ICING_LOG(ERROR) << "Could not mmap file for reading: " << errstr;
mmap_result_ = nullptr;
}
}
@@ -95,8 +94,7 @@ IcingMMapper::~IcingMMapper() { Unmap(); }
bool IcingMMapper::Sync() {
if (is_valid() && !read_only_) {
if (msync(mmap_result_, mmap_len_, MS_SYNC) != 0) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("msync failed: %s",
- strerror(errno));
+ ICING_LOG(ERROR) << "msync failed: " << strerror(errno);
return false;
}
}
diff --git a/icing/legacy/index/icing-storage-file.cc b/icing/legacy/index/icing-storage-file.cc
index 35a4418..20ecfa1 100644
--- a/icing/legacy/index/icing-storage-file.cc
+++ b/icing/legacy/index/icing-storage-file.cc
@@ -69,22 +69,19 @@ bool IcingStorageFile::Sync() {
IcingTimer timer;
if (!PreSync()) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Pre-sync %s failed",
- filename_.c_str());
+ ICING_LOG(ERROR) << "Pre-sync " << filename_ << " failed";
return false;
}
if (!filesystem_->DataSync(fd_.get())) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Sync %s failed",
- filename_.c_str());
+ ICING_LOG(ERROR) << "Sync " << filename_ << " failed";
return false;
}
if (!PostSync()) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf("Post-sync %s failed",
- filename_.c_str());
+ ICING_LOG(ERROR) << "Post-sync " << filename_ << " failed";
return false;
}
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "Syncing %s took %.3fms", filename_.c_str(), timer.Elapsed() * 1000.);
+ ICING_VLOG(1) << "Syncing " << filename_ << " took " << timer.Elapsed() * 1000
+ << "ms";
return true;
}
diff --git a/icing/scoring/bm25f-calculator.cc b/icing/scoring/bm25f-calculator.cc
index 4b426a9..28ee2ba 100644
--- a/icing/scoring/bm25f-calculator.cc
+++ b/icing/scoring/bm25f-calculator.cc
@@ -20,7 +20,6 @@
#include <unordered_set>
#include <vector>
-#include "icing/absl_ports/str_cat.h"
#include "icing/index/hit/doc-hit-info.h"
#include "icing/index/iterator/doc-hit-info-iterator.h"
#include "icing/store/corpus-associated-scoring-data.h"
@@ -116,9 +115,8 @@ float Bm25fCalculator::ComputeScore(const DocHitInfoIterator* query_it,
score += idf_weight * normalized_tf;
}
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "BM25F: corpus_id:%d docid:%d score:%f\n", data.corpus_id(),
- hit_info.document_id(), score);
+ ICING_VLOG(1) << "BM25F: corpus_id:" << data.corpus_id() << " docid:"
+ << hit_info.document_id() << " score:" << score;
return score;
}
@@ -144,8 +142,7 @@ float Bm25fCalculator::GetCorpusIdfWeightForTerm(std::string_view term,
// First, figure out corpus scoring data.
auto status_or = document_store_->GetCorpusAssociatedScoreData(corpus_id);
if (!status_or.ok()) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "No scoring data for corpus [%d]", corpus_id);
+ ICING_LOG(ERROR) << "No scoring data for corpus [" << corpus_id << "]";
return 0;
}
CorpusAssociatedScoreData csdata = status_or.ValueOrDie();
@@ -155,9 +152,8 @@ float Bm25fCalculator::GetCorpusIdfWeightForTerm(std::string_view term,
float idf =
nqi != 0 ? log(1.0f + (num_docs - nqi + 0.5f) / (nqi + 0.5f)) : 0.0f;
corpus_idf_map_.insert({corpus_term_info.value, idf});
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "corpus_id:%d term:%s N:%d nqi:%d idf:%f", corpus_id,
- std::string(term).c_str(), num_docs, nqi, idf);
+ ICING_VLOG(1) << "corpus_id:" << corpus_id << " term:"
+ << term << " N:" << num_docs << "nqi:" << nqi << " idf:" << idf;
return idf;
}
@@ -176,8 +172,7 @@ float Bm25fCalculator::GetCorpusAvgDocLength(CorpusId corpus_id) {
// First, figure out corpus scoring data.
auto status_or = document_store_->GetCorpusAssociatedScoreData(corpus_id);
if (!status_or.ok()) {
- ICING_LOG(ERROR) << IcingStringUtil::StringPrintf(
- "No scoring data for corpus [%d]", corpus_id);
+ ICING_LOG(ERROR) << "No scoring data for corpus [" << corpus_id << "]";
return 0;
}
CorpusAssociatedScoreData csdata = status_or.ValueOrDie();
@@ -205,9 +200,9 @@ float Bm25fCalculator::ComputedNormalizedTermFrequency(
float normalized_tf =
f_q * (k1_ + 1) / (f_q + k1_ * (1 - b_ + b_ * dl / avgdl));
- ICING_VLOG(1) << IcingStringUtil::StringPrintf(
- "corpus_id:%d docid:%d dl:%d avgdl:%f f_q:%f norm_tf:%f\n",
- data.corpus_id(), hit_info.document_id(), dl, avgdl, f_q, normalized_tf);
+ ICING_VLOG(1) << "corpus_id:" << data.corpus_id() << " docid:"
+ << hit_info.document_id() << " dl:" << dl << " avgdl:" << avgdl << " f_q:"
+ << f_q << " norm_tf:" << normalized_tf;
return normalized_tf;
}
@@ -240,8 +235,8 @@ SchemaTypeId Bm25fCalculator::GetSchemaTypeId(DocumentId document_id) const {
// GetDocumentFilterData is if the document_id is outside of the range of
// allocated document_ids, which shouldn't be possible since we're getting
// this document_id from the posting lists.
- ICING_LOG(WARNING) << IcingStringUtil::StringPrintf(
- "No document filter data for document [%d]", document_id);
+ ICING_LOG(WARNING) << "No document filter data for document ["
+ << document_id << "]";
return kInvalidSchemaTypeId;
}
return filter_data_optional.value().schema_type_id();