Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit 958cc0b

Browse files
authored
CPU Frequency Modeling Augmentation (#1428)
1 parent 208c13c commit 958cc0b

File tree

6 files changed

+44
-33
lines changed

6 files changed

+44
-33
lines changed

script/model/info/data_info.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from type import OpUnit, ArithmeticFeature, Target, ExecutionFeature
1+
from type import OpUnit, Target, ExecutionFeature
22

33
# Boundary from input feature -> outputs
44
# The field >= boundary is the inputs and outputs
5-
INPUT_OUTPUT_BOUNDARY = ExecutionFeature.EXEC_MODE
5+
INPUT_OUTPUT_BOUNDARY = ExecutionFeature.CPU_FREQ
66

77
# End of the input features
88
INPUT_END_BOUNDARY = Target.START_TIME
@@ -19,12 +19,6 @@
1919
# The index for different targets in the output
2020
TARGET_CSV_INDEX = {}
2121

22-
# The mini model features for arithmetic operations
23-
ARITHMETIC_FEATURE_INDEX = {
24-
ArithmeticFeature.EXEC_NUMBER: 0,
25-
ArithmeticFeature.EXEC_MODE: 1,
26-
}
27-
2822
# The position of the name of the operating unit in the execution engine csv metrics file
2923
EXECUTION_CSV_NAME_POSITION = 0
3024

script/model/type.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,22 @@ class ExecutionFeature(enum.IntEnum):
8080
FEATURES = 3,
8181

8282
# input features
83-
EXEC_MODE = 4,
84-
NUM_ROWS = 5,
85-
KEY_SIZES = 6,
86-
NUM_KEYS = 7,
87-
EST_CARDINALITIES = 8,
88-
MEM_FACTOR = 9,
89-
NUM_LOOPS = 10,
90-
NUM_CONCURRENT = 11,
83+
CPU_FREQ = 4,
84+
EXEC_MODE = 5,
85+
NUM_ROWS = 6,
86+
KEY_SIZES = 7,
87+
NUM_KEYS = 8,
88+
EST_CARDINALITIES = 9,
89+
MEM_FACTOR = 10,
90+
NUM_LOOPS = 11,
91+
NUM_CONCURRENT = 12,
9192

9293
# interval input features
93-
TXNS_DEALLOCATED = 12,
94-
TXNS_UNLINKED = 13,
95-
BUFFER_UNLINKED = 14,
96-
READONLY_UNLINKED = 15,
97-
INTERVAL = 16,
98-
99-
100-
class ArithmeticFeature(enum.Enum):
101-
"""The input fields of the arithmetic operating units
102-
"""
103-
EXEC_NUMBER = 0,
104-
EXEC_MODE = 1,
94+
TXNS_DEALLOCATED = 13,
95+
TXNS_UNLINKED = 14,
96+
BUFFER_UNLINKED = 15,
97+
READONLY_UNLINKED = 16,
98+
INTERVAL = 17,
10599

106100

107101
class ConcurrentCountingMode(enum.Enum):

src/include/execution/util/cpu_info.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ y * @return The size of a cache line at level @em level.
8888
*/
8989
uint64_t GetRefCyclesUs() const { return ref_cycles_us_; }
9090

91+
/**
92+
* @return The CPU Frequency in MHz recorded at initialization
93+
*/
94+
double GetCpuFreq() const { return cpu_mhz_; }
95+
9196
/**
9297
* @return True if the CPU has the input hardware feature @em feature; false otherwise;
9398
*/

src/include/metrics/metrics_util.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@
22

33
#include <chrono> // NOLINT
44

5+
#include "execution/util/cpu_info.h"
6+
57
namespace noisepage::metrics {
68

9+
/**
10+
* Struct used to represent the hardware context that we are interested in capturing.
11+
* We currently capture only the CPU frequency.
12+
*/
13+
struct HardwareContext {
14+
/** CPU Frequency (MHz) */
15+
double cpu_mhz_;
16+
};
17+
718
/**
819
* Static utility methods for the metrics component
920
*/
@@ -19,5 +30,10 @@ struct MetricsUtil {
1930
std::chrono::high_resolution_clock::now().time_since_epoch())
2031
.count();
2132
}
33+
34+
/**
35+
* @return The hardware context to record
36+
*/
37+
static HardwareContext GetHardwareContext() { return HardwareContext{execution::CpuInfo::Instance()->GetCpuFreq()}; }
2238
};
2339
} // namespace noisepage::metrics

src/include/metrics/pipeline_metric.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ class PipelineMetricRawData : public AbstractRawData {
5050
"Not all files are open.");
5151

5252
auto &outfile = (*outfiles)[0];
53+
auto context = MetricsUtil::GetHardwareContext();
5354

5455
for (auto &data : pipeline_data_) {
5556
outfile << data.query_id_.UnderlyingValue() << ", ";
5657
outfile << data.pipeline_id_.UnderlyingValue() << ", ";
5758
outfile << data.features_.size() << ", ";
5859
outfile << data.GetFeatureVectorString() << ", ";
60+
outfile << context.cpu_mhz_ << ", ";
5961
outfile << static_cast<uint32_t>(data.execution_mode_) << ", ";
6062
outfile << data.GetEstRowsVectorString() << ", ";
6163
outfile << data.GetKeySizeVectorString() << ", ";
@@ -81,7 +83,7 @@ class PipelineMetricRawData : public AbstractRawData {
8183
* Note: This includes the columns for the input feature, but not the output (resource counters)
8284
*/
8385
static constexpr std::array<std::string_view, 1> FEATURE_COLUMNS = {
84-
"query_id, pipeline_id, num_features, features, exec_mode, num_rows, key_sizes, num_keys, "
86+
"query_id, pipeline_id, num_features, features, cpu_freq, exec_mode, num_rows, key_sizes, num_keys, "
8587
"est_cardinalities, mem_factor, num_loops, num_concurrent"};
8688

8789
private:

test/self_driving/modeling_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ TEST_F(ModelServerTest, PipelineTest) {
6969
}
7070

7171
std::vector<std::vector<double>> features{
72-
{0, 10000, 4, 1, 10000, 1, 0, 0},
73-
{0, 10000, 4, 1, 10000, 1, 0, 0},
74-
{0, 10000, 4, 1, 10000, 1, 0, 0},
75-
{0, 10000, 4, 1, 10000, 1, 0, 0},
72+
{0, 0, 10000, 4, 1, 10000, 1, 0, 0},
73+
{0, 0, 10000, 4, 1, 10000, 1, 0, 0},
74+
{0, 0, 10000, 4, 1, 10000, 1, 0, 0},
75+
{0, 0, 10000, 4, 1, 10000, 1, 0, 0},
7676
};
7777

7878
// Send a message

0 commit comments

Comments
 (0)