This is an automated email from the ASF dual-hosted git repository.
chengchengjin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git
The following commit(s) were added to refs/heads/main by this push:
new 51a013b8e4 [VL] Minor refactor to replace START_TIMEING with
SCOPE_TIMER (#11320)
51a013b8e4 is described below
commit 51a013b8e44021dd6f601f6775c8240295468916
Author: Yang Zhang <[email protected]>
AuthorDate: Mon Dec 22 10:25:16 2025 +0800
[VL] Minor refactor to replace START_TIMEING with SCOPE_TIMER (#11320)
---
cpp/velox/shuffle/VeloxHashShuffleWriter.cc | 56 ++++++++++++++------------
cpp/velox/shuffle/VeloxRssSortShuffleWriter.cc | 35 ++++++++--------
cpp/velox/utils/Common.h | 18 +++------
3 files changed, 55 insertions(+), 54 deletions(-)
diff --git a/cpp/velox/shuffle/VeloxHashShuffleWriter.cc
b/cpp/velox/shuffle/VeloxHashShuffleWriter.cc
index 6a1298d743..dda2c42a2e 100644
--- a/cpp/velox/shuffle/VeloxHashShuffleWriter.cc
+++ b/cpp/velox/shuffle/VeloxHashShuffleWriter.cc
@@ -269,13 +269,14 @@ arrow::Status
VeloxHashShuffleWriter::write(std::shared_ptr<ColumnarBatch> cb, i
VELOX_CHECK(numColumns >= 2);
auto pidBatch = veloxColumnBatch->select(veloxPool_.get(), {0});
auto pidArr = getFirstColumn(*(pidBatch->getRowVector()));
- START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
- std::fill(std::begin(partition2RowCount_), std::end(partition2RowCount_),
0);
- RETURN_NOT_OK(partitioner_->compute(pidArr, pidBatch->numRows(),
row2Partition_));
- for (auto& pid : row2Partition_) {
- partition2RowCount_[pid]++;
+ {
+ SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
+ std::fill(std::begin(partition2RowCount_),
std::end(partition2RowCount_), 0);
+ RETURN_NOT_OK(partitioner_->compute(pidArr, pidBatch->numRows(),
row2Partition_));
+ for (auto& pid : row2Partition_) {
+ partition2RowCount_[pid]++;
+ }
}
- END_TIMING();
std::vector<int32_t> range;
range.reserve(numColumns);
for (int32_t i = 1; i < numColumns; i++) {
@@ -289,9 +290,10 @@ arrow::Status
VeloxHashShuffleWriter::write(std::shared_ptr<ColumnarBatch> cb, i
auto veloxColumnBatch = VeloxColumnarBatch::from(veloxPool_.get(), cb);
VELOX_CHECK_NOT_NULL(veloxColumnBatch);
facebook::velox::RowVectorPtr rv;
- START_TIMING(cpuWallTimingList_[CpuWallTimingFlattenRV]);
- rv = veloxColumnBatch->getFlattenedRowVector();
- END_TIMING();
+ {
+ SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingFlattenRV]);
+ rv = veloxColumnBatch->getFlattenedRowVector();
+ }
if (isExtremelyLargeBatch(rv)) {
auto numRows = rv->size();
int32_t offset = 0;
@@ -313,23 +315,25 @@ arrow::Status
VeloxHashShuffleWriter::partitioningAndDoSplit(facebook::velox::Ro
std::fill(std::begin(partition2RowCount_), std::end(partition2RowCount_), 0);
if (partitioner_->hasPid()) {
auto pidArr = getFirstColumn(*rv);
- START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
- RETURN_NOT_OK(partitioner_->compute(pidArr, rv->size(), row2Partition_));
- for (auto& pid : row2Partition_) {
- partition2RowCount_[pid]++;
+ {
+ SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
+ RETURN_NOT_OK(partitioner_->compute(pidArr, rv->size(), row2Partition_));
+ for (auto& pid : row2Partition_) {
+ partition2RowCount_[pid]++;
+ }
}
- END_TIMING();
auto strippedRv = getStrippedRowVector(*rv);
RETURN_NOT_OK(initFromRowVector(*strippedRv));
RETURN_NOT_OK(doSplit(*strippedRv, memLimit));
} else {
RETURN_NOT_OK(initFromRowVector(*rv));
- START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
- RETURN_NOT_OK(partitioner_->compute(nullptr, rv->size(), row2Partition_));
- for (auto& pid : row2Partition_) {
- partition2RowCount_[pid]++;
+ {
+ SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
+ RETURN_NOT_OK(partitioner_->compute(nullptr, rv->size(),
row2Partition_));
+ for (auto& pid : row2Partition_) {
+ partition2RowCount_[pid]++;
+ }
}
- END_TIMING();
RETURN_NOT_OK(doSplit(*rv, memLimit));
}
return arrow::Status::OK();
@@ -416,13 +420,13 @@ arrow::Status VeloxHashShuffleWriter::doSplit(const
facebook::velox::RowVector&
RETURN_NOT_OK(buildPartition2Row(rowNum));
RETURN_NOT_OK(updateInputHasNull(rv));
- START_TIMING(cpuWallTimingList_[CpuWallTimingIteratePartitions]);
-
- setSplitState(SplitState::kPreAlloc);
- // Calculate buffer size based on available offheap memory, history average
bytes per row and options_.bufferSize.
- auto preAllocBufferSize = calculatePartitionBufferSize(rv, memLimit);
- RETURN_NOT_OK(preAllocPartitionBuffers(preAllocBufferSize));
- END_TIMING();
+ {
+ SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingIteratePartitions]);
+ setSplitState(SplitState::kPreAlloc);
+ // Calculate buffer size based on available offheap memory, history
average bytes per row and options_.bufferSize.
+ auto preAllocBufferSize = calculatePartitionBufferSize(rv, memLimit);
+ RETURN_NOT_OK(preAllocPartitionBuffers(preAllocBufferSize));
+ }
printPartitionBuffer();
diff --git a/cpp/velox/shuffle/VeloxRssSortShuffleWriter.cc
b/cpp/velox/shuffle/VeloxRssSortShuffleWriter.cc
index 54e2539720..0f9297ac5f 100644
--- a/cpp/velox/shuffle/VeloxRssSortShuffleWriter.cc
+++ b/cpp/velox/shuffle/VeloxRssSortShuffleWriter.cc
@@ -21,7 +21,6 @@
#include "shuffle/ShuffleSchema.h"
#include "utils/Common.h"
#include "utils/Macros.h"
-#include "utils/VeloxArrowUtils.h"
#include "velox/common/base/Nulls.h"
#include "velox/type/Type.h"
@@ -79,10 +78,11 @@ arrow::Status
VeloxRssSortShuffleWriter::write(std::shared_ptr<ColumnarBatch> cb
VELOX_CHECK(numColumns >= 2);
auto pidBatch = veloxColumnBatch->select(veloxPool_.get(), {0});
auto pidArr = getFirstColumn(*(pidBatch->getRowVector()));
- START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
- setSortState(RssSortState::kSort);
- RETURN_NOT_OK(partitioner_->compute(pidArr, pidBatch->numRows(),
batches_.size(), rowVectorIndexMap_));
- END_TIMING();
+ {
+ SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
+ setSortState(RssSortState::kSort);
+ RETURN_NOT_OK(partitioner_->compute(pidArr, pidBatch->numRows(),
batches_.size(), rowVectorIndexMap_));
+ }
std::vector<int32_t> range;
range.reserve(numColumns);
for (int32_t i = 1; i < numColumns; i++) {
@@ -96,24 +96,27 @@ arrow::Status
VeloxRssSortShuffleWriter::write(std::shared_ptr<ColumnarBatch> cb
auto veloxColumnBatch = VeloxColumnarBatch::from(veloxPool_.get(), cb);
VELOX_CHECK_NOT_NULL(veloxColumnBatch);
facebook::velox::RowVectorPtr rv;
- START_TIMING(cpuWallTimingList_[CpuWallTimingFlattenRV]);
- rv = veloxColumnBatch->getFlattenedRowVector();
- END_TIMING();
+ {
+ SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingFlattenRV]);
+ rv = veloxColumnBatch->getFlattenedRowVector();
+ }
if (partitioner_->hasPid()) {
auto pidArr = getFirstColumn(*rv);
- START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
- setSortState(RssSortState::kSort);
- RETURN_NOT_OK(partitioner_->compute(pidArr, rv->size(), batches_.size(),
rowVectorIndexMap_));
- END_TIMING();
+ {
+ SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
+ setSortState(RssSortState::kSort);
+ RETURN_NOT_OK(partitioner_->compute(pidArr, rv->size(),
batches_.size(), rowVectorIndexMap_));
+ }
auto strippedRv = getStrippedRowVector(*rv);
RETURN_NOT_OK(initFromRowVector(*strippedRv));
RETURN_NOT_OK(doSort(strippedRv, sortBufferMaxSize_));
} else {
RETURN_NOT_OK(initFromRowVector(*rv));
- START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
- setSortState(RssSortState::kSort);
- RETURN_NOT_OK(partitioner_->compute(nullptr, rv->size(),
batches_.size(), rowVectorIndexMap_));
- END_TIMING();
+ {
+ SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
+ setSortState(RssSortState::kSort);
+ RETURN_NOT_OK(partitioner_->compute(nullptr, rv->size(),
batches_.size(), rowVectorIndexMap_));
+ }
RETURN_NOT_OK(doSort(rv, sortBufferMaxSize_));
}
}
diff --git a/cpp/velox/utils/Common.h b/cpp/velox/utils/Common.h
index eaa551da05..6dd92b409d 100644
--- a/cpp/velox/utils/Common.h
+++ b/cpp/velox/utils/Common.h
@@ -35,17 +35,11 @@ static inline void fastCopy(void* dst, const void* src,
size_t n) {
facebook::velox::simd::memcpy(dst, src, n);
}
-#define START_TIMING(timing) \
- { \
- auto ptiming = &timing; \
- facebook::velox::DeltaCpuWallTimer timer{ \
- [ptiming](const facebook::velox::CpuWallTiming& delta) {
ptiming->add(delta); }};
-
-#define END_TIMING() }
-
-#define SCOPED_TIMER(timing) \
- auto ptiming = &timing; \
- facebook::velox::DeltaCpuWallTimer timer{ \
- [ptiming](const facebook::velox::CpuWallTiming& delta) {
ptiming->add(delta); }};
+#define SCOPED_TIMER(timing)
\
+ do {
\
+ auto ptiming = &timing;
\
+ facebook::velox::DeltaCpuWallTimer timer{
\
+ [ptiming](const facebook::velox::CpuWallTiming& delta) {
ptiming->add(delta); }}; \
+ } while (0)
} // namespace gluten
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]