Skip to content

Commit d4705ca

Browse files
hdikemanfacebook-github-bot
authored andcommitted
velox(feat): add Task/Operator/Driver Stats toString() utils
Summary: Needed a way to summarize plan execution for the native execution project. I was unable to find a TaskStats logging function Adding Task/Operator/DriverStat logging utilities The caller is responsible for synchronization, no special effort is made to ensure that the stat structures are not being modified during logging. Ideally a copy would be created and the logger invoked on the copy Differential Revision: D80673402
1 parent 23b1d9a commit d4705ca

File tree

7 files changed

+166
-0
lines changed

7 files changed

+166
-0
lines changed

velox/exec/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ velox_add_library(
2828
ContainerRowSerde.cpp
2929
DistinctAggregations.cpp
3030
Driver.cpp
31+
DriverStats.cpp
3132
EnforceSingleRow.cpp
3233
Exchange.cpp
3334
ExchangeClient.cpp
@@ -56,6 +57,7 @@ velox_add_library(
5657
NestedLoopJoinBuild.cpp
5758
NestedLoopJoinProbe.cpp
5859
Operator.cpp
60+
OperatorStats.cpp
5961
OperatorUtils.cpp
6062
OrderBy.cpp
6163
OutputBuffer.cpp
@@ -91,6 +93,7 @@ velox_add_library(
9193
TableWriteMerge.cpp
9294
TableWriter.cpp
9395
Task.cpp
96+
TaskStats.cpp
9497
TopN.cpp
9598
TopNRowNumber.cpp
9699
Unnest.cpp

velox/exec/DriverStats.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "velox/exec/DriverStats.h"
18+
#include <sstream>
19+
20+
namespace facebook::velox::exec {
21+
22+
std::string DriverStats::toString() const {
23+
std::stringstream out;
24+
25+
out << "[DriverStats] runtimeStats: {";
26+
bool first = true;
27+
for (const auto& [name, metric] : runtimeStats) {
28+
if (!first) {
29+
out << ", ";
30+
}
31+
out << name << ":" << metric.sum;
32+
first = false;
33+
}
34+
out << "}";
35+
36+
return out.str();
37+
}
38+
39+
} // namespace facebook::velox::exec

velox/exec/DriverStats.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct DriverStats {
2727
"totalDriverOffThreadWallNanos";
2828

2929
std::unordered_map<std::string, RuntimeMetric> runtimeStats;
30+
31+
std::string toString() const;
3032
};
3133

3234
} // namespace facebook::velox::exec

velox/exec/OperatorStats.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "velox/exec/OperatorStats.h"
18+
#include <fmt/format.h>
19+
#include <sstream>
20+
21+
namespace facebook::velox::exec {
22+
23+
std::string OperatorStats::toString() const {
24+
std::stringstream out;
25+
26+
out << "[OperatorStats][" << operatorId << "] " << operatorType << " ["
27+
<< planNodeId << "]";
28+
29+
out << "\n input: " << inputPositions << " rows (" << inputBytes
30+
<< " bytes, " << inputVectors << " vectors)";
31+
out << "\n output: " << outputPositions << " rows (" << outputBytes
32+
<< " bytes, " << outputVectors << " vectors)";
33+
34+
if (numSplits > 0) {
35+
out << "\n splits: " << numSplits;
36+
}
37+
38+
if (spilledBytes > 0) {
39+
out << "\n spilled: " << spilledBytes << " bytes (" << spilledRows
40+
<< " rows, " << spilledPartitions << " partitions)";
41+
}
42+
43+
if (blockedWallNanos > 0) {
44+
out << "\n blockedWallMs: "
45+
<< fmt::format("{:.2f}ms", blockedWallNanos / 1e6);
46+
}
47+
48+
out << "\n runtimeStats: {";
49+
for (const auto& [name, metric] : runtimeStats) {
50+
out << "\n " << name << ":" << metric.sum << ",";
51+
}
52+
out << "\n }";
53+
54+
return out.str();
55+
}
56+
57+
} // namespace facebook::velox::exec

velox/exec/OperatorStats.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ struct OperatorStats {
222222
void addRuntimeStat(const std::string& name, const RuntimeCounter& value);
223223
void add(const OperatorStats& other);
224224
void clear();
225+
std::string toString() const;
225226
};
226227

228+
std::string toString(const OperatorStats& stats);
229+
227230
} // namespace facebook::velox::exec

velox/exec/TaskStats.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "velox/exec/TaskStats.h"
18+
#include <fmt/format.h>
19+
#include <sstream>
20+
21+
namespace facebook::velox::exec {
22+
23+
std::string PipelineStats::toString() const {
24+
std::stringstream out;
25+
26+
out << "[PipelineStats] " << (inputPipeline ? "INPUT " : "")
27+
<< (outputPipeline ? "OUTPUT " : "") << operatorStats.size()
28+
<< " operators, " << driverStats.size() << " drivers.";
29+
30+
for (const auto& operatorStat : operatorStats) {
31+
out << "\n " << operatorStat.toString();
32+
}
33+
34+
for (const auto& driverStat : driverStats) {
35+
out << "\n " << driverStat.toString();
36+
}
37+
38+
return out.str();
39+
}
40+
41+
std::string TaskStats::toString() const {
42+
std::stringstream out;
43+
out << "[TaskStats] " << numFinishedSplits << "/" << numTotalSplits
44+
<< " splits completed, " << numCompletedDrivers << "/" << numTotalDrivers
45+
<< " drivers completed, " << pipelineStats.size() << " pipelines";
46+
47+
if (executionStartTimeMs > 0 && executionEndTimeMs > 0) {
48+
out << " (" << (executionEndTimeMs - executionStartTimeMs) << "ms)";
49+
}
50+
51+
for (const auto& pipelineStat : pipelineStats) {
52+
out << "\n " << pipelineStat.toString();
53+
}
54+
55+
return out.str();
56+
}
57+
58+
} // namespace facebook::velox::exec

velox/exec/TaskStats.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ struct PipelineStats {
4747

4848
PipelineStats(bool _inputPipeline, bool _outputPipeline)
4949
: inputPipeline{_inputPipeline}, outputPipeline{_outputPipeline} {}
50+
51+
std::string toString() const;
5052
};
5153

5254
/// Stores execution stats per task.
@@ -126,6 +128,8 @@ struct TaskStats {
126128
uint32_t memoryReclaimCount{0};
127129
/// The total memory reclamation time.
128130
uint64_t memoryReclaimMs{0};
131+
132+
std::string toString() const;
129133
};
130134

131135
} // namespace facebook::velox::exec

0 commit comments

Comments
 (0)