Skip to content

Commit c114a83

Browse files
committed
nice
1 parent 4b44a4f commit c114a83

15 files changed

+253
-111
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@
2323
[submodule "lib/eth_hashjoin"]
2424
path = lib/eth_hashjoin
2525
url = https://github.com/mars-research/vldb13-eth-hashjoin.git
26+
[submodule "perf-cpp"]
27+
path = perf-cpp
28+
url = https://github.com/jmuehlig/perf-cpp.git

.vscode/settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
"variant": "cpp",
7373
"codecvt": "cpp",
7474
"unordered_set": "cpp",
75-
"syncstream": "cpp"
75+
"syncstream": "cpp",
76+
"*.h++": "cpp",
77+
"regex": "cpp",
78+
"shared_mutex": "cpp"
7679
}
7780
}

1.txt

-58
This file was deleted.

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ if (PERFCPP)
260260

261261
target_include_directories(dramhit PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/lib/perf-cpp/src/perf-cpp-external/include)
262262
target_link_libraries(dramhit PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/lib/perf-cpp/src/perf-cpp-external-build/libperf-cpp.a)
263-
263+
add_definitions(-DWITH_PERFCPP)
264264
endif()
265265

266266
if (VTUNE)

include/PerfMultiCounter.hpp

+75-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,64 @@
11
#pragma once
22

33
#include <perfcpp/event_counter.h>
4-
54
#include <iostream>
5+
#include <fstream>
66
#include <mutex>
77
#include <vector>
8+
#include <stdexcept>
9+
#include <string>
810

911
namespace kmercounter {
10-
class MultithreadCounter {
12+
13+
class PerfCounterResult {
14+
private:
15+
std::vector<std::pair<std::string, double>> _results;
1116
public:
12-
MultithreadCounter() {
13-
MultithreadCounter(1);
17+
PerfCounterResult(const std::vector<std::string>& events) {
18+
for (const auto& event : events) {
19+
_results.emplace_back(event, 0);
20+
}
21+
}
22+
23+
void add(const perf::CounterResult& result) {
24+
for (auto& [counter_name, counter_value] : _results) {
25+
counter_value += result.get(counter_name).value_or(0);
26+
}
27+
}
28+
29+
void print() {
30+
for (auto& [counter_name, counter_value] : _results) {
31+
std::cout << counter_name << ": " << counter_value << std::endl;
32+
}
1433
}
34+
};
1535

16-
MultithreadCounter(size_t num_threads)
17-
: num_threads(num_threads),
18-
def()
36+
class MultithreadCounter {
37+
public:
38+
// Default constructor
39+
MultithreadCounter() {}
40+
41+
// Delegating constructor: reads events from a file then delegates
42+
MultithreadCounter(size_t num_threads, const std::string& cnt_path, const std::string& def_path)
43+
: MultithreadCounter(num_threads, readEventsFromFile(cnt_path), def_path)
1944
{
45+
// Nothing to do here, delegation took care of initialization.
46+
}
47+
48+
// Main constructor: uses events vector
49+
MultithreadCounter(size_t num_threads, const std::vector<std::string>& events, const std::string& def_path)
50+
: num_threads(num_threads), events(events) {
51+
results.reserve(num_threads);
52+
defs.reserve(num_threads);
2053
counters.reserve(num_threads);
2154
for (size_t i = 0; i < num_threads; ++i) {
22-
counters.emplace_back(def);
55+
results.emplace_back(this->events);
56+
if (def_path.empty())
57+
defs.emplace_back();
58+
else
59+
defs.emplace_back(def_path);
60+
counters.emplace_back(defs[i]);
61+
counters[i].add(this->events);
2362
}
2463
}
2564

@@ -32,28 +71,44 @@ class MultithreadCounter {
3271
void stop(size_t thread_idx) {
3372
if (thread_idx < num_threads) {
3473
counters[thread_idx].stop();
74+
results[thread_idx].add(counters[thread_idx].result());
75+
counters[thread_idx].close();
3576
}
3677
}
3778

38-
void add(const std::vector<std::string>& events) {
79+
void print() {
80+
std::cout << "\n------- PERFCPP ------- " << std::endl;
3981
for (size_t i = 0; i < num_threads; i++) {
40-
counters[i].add(events);
82+
std::cout << "\nThread ID: " << i << std::endl;
83+
results[i].print();
4184
}
85+
std::cout << "\n----------------------- " << std::endl;
4286
}
4387

44-
void show() {
45-
for (int i = 0; i < num_threads; i++) {
46-
auto result = counters[i].result();
47-
std::cout << "\n TID: " << i << " PERFCPP Results:" << std::endl;
48-
for (const auto& [counter_name, counter_value] : result) {
49-
std::cout << counter_value << " " << counter_name << std::endl;
88+
private:
89+
// Helper function to read events from file
90+
static std::vector<std::string> readEventsFromFile(const std::string& path) {
91+
std::vector<std::string> events;
92+
if(path.empty())
93+
return events;
94+
95+
std::ifstream file(path);
96+
if (!file.is_open()) {
97+
throw std::runtime_error("Error: Unable to open file " + path);
98+
}
99+
std::string line;
100+
while (std::getline(file, line)) {
101+
if (!line.empty()) {
102+
events.push_back(line);
50103
}
51104
}
105+
return events;
52106
}
53107

54-
private:
55-
std::vector<perf::EventCounter> counters;
56-
perf::CounterDefinition def;
108+
std::vector<perf::EventCounter> counters; // Each counter needs its own definitions
109+
std::vector<perf::CounterDefinition> defs;
110+
std::vector<PerfCounterResult> results;
57111
size_t num_threads;
112+
std::vector<std::string> events;
58113
};
59-
} // namespace kmercounter
114+
} // namespace kmercounter

include/hashtables/cas_kht.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class CASHashTable : public BaseHashTable {
4848

4949
uint32_t find_queue_sz;
5050

51+
CASHashTable(uint64_t c) : CASHashTable(c, 8) {};
52+
5153
CASHashTable(uint64_t c, uint32_t queue_sz)
5254
: fd(-1), id(1), find_head(0), find_tail(0), ins_head(0), ins_tail(0) {
5355
this->capacity = kmercounter::utils::next_pow2(c);

include/types.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ struct Configuration {
166166
bool rw_queues;
167167
unsigned pollute_ratio;
168168
uint32_t find_queue_sz;
169+
std::string perf_cnt_path;
170+
std::string perf_def_path;
169171

170172
void dump_configuration() {
171173
printf("Run configuration {\n");
@@ -190,6 +192,8 @@ struct Configuration {
190192
printf(" relation_r_size %" PRIu64 "\n", relation_r_size);
191193
printf(" relation_s_size %" PRIu64 "\n", relation_s_size);
192194
printf(" delimitor %s\n", delimitor.c_str());
195+
printf(" perf cnt path %s\n", perf_cnt_path.c_str());
196+
printf(" perf def path %s\n", perf_def_path.c_str());
193197
printf("}\n");
194198
}
195199
};

notes.txt

Whitespace-only changes.

perf-cpp

Submodule perf-cpp added at 1b64f42

perf_cnt.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
seconds
2+
instructions
3+
cycles
4+
cache-misses
5+
CYCLE_ACTIVITY.CYCLES_L1D_MISS

scripts/change_device.sh

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
# README: this script can help when you run out of primary disk space
4+
# you can point this to any path and create corresponding tmp on your large disk on cloud lab
5+
# for example, /dev/nvme0n1p1 only has 16 GB memory on cloudlab but /dev/nvme0n1p4 has ~700 gigs
6+
# On boot typically /opt/mnt/ is mounted on /dev/nvme0n1p4
7+
8+
# so let us say your home directory is taking up space, check by du utility
9+
# ./this_script <home_dir> /dev/nvme0n1p4 /opt/mnt/backup/
10+
# should make sure the storage on this disk correctly transfered.
11+
12+
# Ensure we have the correct number of arguments
13+
if [ "$#" -ne 3 ]; then
14+
echo "Usage: $0 <old_dir> <new_dev> <tmp_dir>"
15+
exit 1
16+
fi
17+
18+
# Input arguments
19+
old_dir="$1"
20+
new_dev="$2"
21+
tmp_dir="$3"
22+
23+
# Check if old_dir exists
24+
if [ ! -d "$old_dir" ]; then
25+
echo "Error: Directory '$old_dir' does not exist."
26+
exit 1
27+
fi
28+
29+
# Check if tmp_dir exists and is writable
30+
if [ ! -d "$tmp_dir" ] || [ ! -w "$tmp_dir" ]; then
31+
echo "Error: Temporary directory '$tmp_dir' does not exist or is not writable."
32+
exit 1
33+
fi
34+
35+
# Check if new_dev is a valid device
36+
if [ ! -b "$new_dev" ]; then
37+
echo "Error: Device '$new_dev' is not a valid block device."
38+
exit 1
39+
fi
40+
41+
# Step 1: Backup old_dir to tmp_dir using rsync
42+
echo "Backing up '$old_dir' to '$tmp_dir'..."
43+
rsync -a --progress "$old_dir" "$tmp_dir/"
44+
if [ $? -ne 0 ]; then
45+
echo "Error: Failed to backup '$old_dir' to '$tmp_dir'."
46+
exit 1
47+
fi
48+
49+
# Step 2: Remove old_dir
50+
echo "Removing '$old_dir'..."
51+
rm -rf "$old_dir"
52+
if [ $? -ne 0 ]; then
53+
echo "Error: Failed to remove '$old_dir'."
54+
exit 1
55+
fi
56+
57+
# Step 3: Create the old_dir again
58+
echo "Recreating '$old_dir'..."
59+
mkdir -p "$old_dir"
60+
if [ $? -ne 0 ]; then
61+
echo "Error: Failed to recreate '$old_dir'."
62+
exit 1
63+
fi
64+
65+
# Step 4: Mount the new device to old_dir
66+
echo "Mounting '$new_dev' to '$old_dir'..."
67+
mount "$new_dev" "$old_dir"
68+
if [ $? -ne 0 ]; then
69+
echo "Error: Failed to mount '$new_dev' to '$old_dir'."
70+
exit 1
71+
fi
72+
73+
# Step 5: Restore data from tmp_dir to old_dir
74+
echo "Restoring data from '$tmp_dir' to '$old_dir'..."
75+
rsync -a --progress "$tmp_dir/" "$old_dir/"
76+
if [ $? -ne 0 ]; then
77+
echo "Error: Failed to restore data from '$tmp_dir' to '$old_dir'."
78+
exit 1
79+
fi
80+
81+
# Step 6: Clean up temporary files
82+
echo "Cleaning up temporary files..."
83+
rm -rf "$tmp_dir"
84+
if [ $? -ne 0 ]; then
85+
echo "Error: Failed to remove temporary directory '$tmp_dir'."
86+
exit 1
87+
fi
88+
89+
# Success message
90+
echo "Operation completed successfully. '$old_dir' has been moved to '$new_dev' and data restored."
91+

scripts/get_perf_list.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
#!/bin/bash
3+
4+
# Get the script's directory
5+
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
6+
echo "Script is located at: $script_dir"
7+
8+
# Clone the perf-cpp repository inside the script's directory
9+
git clone https://github.com/jmuehlig/perf-cpp "$script_dir/../perf-cpp"
10+
11+
# Go to the newly cloned repository
12+
cd "$script_dir/../perf-cpp" || exit
13+
14+
# Run cmake and build perf-list
15+
cmake .
16+
cmake --build . --target perf-list
17+
18+
cd ..

0 commit comments

Comments
 (0)