Skip to content

Commit

Permalink
format cpp (#106)
Browse files Browse the repository at this point in the history
* infrastructure

* format files
  • Loading branch information
adriandavila authored Dec 28, 2023
1 parent 2a4fe6c commit 51f3e27
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Expand Down
39 changes: 12 additions & 27 deletions scripts/ortoa-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ ortoa-lib: a collection of bash functions to ease development
Formatters:
ortoa-clang-format: --------- Check staged C++ files for formatting issues
ortoa-clang-format-all: ----- Check all C++ projects for formatting issues
ortoa-format-python: -------- Format all the python files
ortoa-sort-python: ---------- Sort the imports in python files
ortoa-typecheck-python: ----- Typecheck the python files
Other:
ortoa-help: ----------------- Prints this help message
Expand Down Expand Up @@ -193,32 +193,17 @@ Syntax: ortoa-clang-format [-h] [DIRECTORY]...
esac
done

if [[ ${#} -ge 1 ]]
then
git clang-format "${@}"
else
git clang-format ${REPO_ROOT}
fi
}


ortoa-clang-format-all() {
local HELP="""\
Check all C++ projects for formatting issues.
Syntax: ortoa-clang-format [-h]
-------------------------------
-h Print this help message
"""

OPTIND=1
while getopts ":h" option; do
case "${option}" in
h) echo "${HELP}"; return 0 ;;
esac
done

source ${REPO_ROOT}/scripts/formatting-and-linting/clang-format-all.sh host/ enclave/ crypto/ client/
clang-format -i --style=file \
"${REPO_ROOT}"/src/client/*.h \
"${REPO_ROOT}"/src/client/*.cpp \
"${REPO_ROOT}"/src/enclave/*.h \
"${REPO_ROOT}"/src/enclave/*.cpp \
"${REPO_ROOT}"/src/host/*.h \
"${REPO_ROOT}"/src/host/*.cpp \
"${REPO_ROOT}"/src/libcommon/**/*.h \
"${REPO_ROOT}"/src/libcommon/**/*.cpp \
"${REPO_ROOT}"/src/libstorage/**/*.h \
"${REPO_ROOT}"/src/libstorage/**/*.cpp
}


Expand Down
40 changes: 21 additions & 19 deletions src/client/SharedQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
#define SHARED_QUEUE_H

#include <atomic>
#include <condition_variable>
#include <iostream>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <queue>
#include <thread>

#include <chrono>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransportUtils.h>

#include "constants.h"
#include "RPC.h"
#include "clientUtils.h"
#include "constants.h"

using namespace std::chrono;
using namespace apache::thrift;
Expand All @@ -28,10 +28,10 @@ class SharedQueue {
std::queue<Operation> queue;

ClientConfig &config;

public:
SharedQueue(ClientConfig &config): config(config) {};
SharedQueue(ClientConfig &config) : config(config){};

int enqueue() {
std::unique_lock<std::mutex> lock(mutex);

Expand Down Expand Up @@ -65,12 +65,13 @@ class DataHandler {
SharedQueue &sharedQueue;

public:
DataHandler(SharedQueue& sharedQueue): sharedQueue(sharedQueue) {}
DataHandler(SharedQueue &sharedQueue) : sharedQueue(sharedQueue) {}

void operator()() {
while (true) {
int enqueue_result = sharedQueue.enqueue();
if (enqueue_result == 1) return;
if (enqueue_result == 1)
return;
}
}
};
Expand All @@ -80,27 +81,28 @@ class WarmUpRunner {
SharedQueue &sharedQueue;
inline static std::mutex mutex;

public:
inline static std::atomic<int> warmupOperations;
public:
inline static std::atomic<int> warmupOperations;

WarmUpRunner(SharedQueue& sharedQueue): sharedQueue(sharedQueue) {}
WarmUpRunner(SharedQueue &sharedQueue) : sharedQueue(sharedQueue) {}

void operator()() {
auto socket = std::make_shared<TSocket>(HOST_IP, HOST_PORT);
auto transport = std::make_shared<TBufferedTransport>(socket);
auto protocol = std::make_shared<TBinaryProtocol>(transport);
RPCClient client(protocol);

transport->open();

while (warmupOperations--) {
Operation data = sharedQueue.dequeue();
if (data.op == OpType::EOD) return;
if (data.op == OpType::EOD)
return;

std::string out;
client.access(out, data);
}

transport->close();
}
};
Expand All @@ -111,8 +113,8 @@ class ClientRunner {
std::vector<double> &latencies;

public:
ClientRunner(SharedQueue& sharedQueue, std::vector<double> &latencies):
sharedQueue(sharedQueue), latencies(latencies) {}
ClientRunner(SharedQueue &sharedQueue, std::vector<double> &latencies)
: sharedQueue(sharedQueue), latencies(latencies) {}

void operator()() {
auto socket = std::make_shared<TSocket>(HOST_IP, HOST_PORT);
Expand All @@ -124,14 +126,14 @@ class ClientRunner {

while (true) {
Operation data = sharedQueue.dequeue();
if (data.op == OpType::EOD) return;
if (data.op == OpType::EOD)
return;

auto start = high_resolution_clock::now();
std::string out;
client.access(out, data);
auto end = high_resolution_clock::now();
latencies.push_back(
duration_cast<milliseconds>(end - start).count());
latencies.push_back(duration_cast<milliseconds>(end - start).count());
}

transport->close();
Expand Down
17 changes: 10 additions & 7 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <numeric>
#include <sstream>

#include "redis.h"
#include "SharedQueue.h"
#include "redis.h"
#include "spdlog/spdlog.h"

using namespace std::chrono;
Expand Down Expand Up @@ -43,7 +43,8 @@ class ClientHandler {
for (int i = 0; i < config.num_clients; ++i) {
data_handler_threads.push_back(std::thread(DataHandler(sharedQueue)));
}
for (auto &thread : data_handler_threads) thread.join();
for (auto &thread : data_handler_threads)
thread.join();

// Warm up client-host communication
WarmUpRunner::warmupOperations = config.num_warmup_operations;
Expand All @@ -56,19 +57,20 @@ class ClientHandler {
for (int i = 0; i < config.num_clients; ++i) {
runner_threads.push_back(std::thread(ClientRunner(sharedQueue, latencies)));
}
for (auto &thread : runner_threads) thread.join();
for (auto &thread : runner_threads)
thread.join();
auto end = high_resolution_clock::now();

for (auto &thread : warmup_threads) thread.join();
for (auto &thread : warmup_threads)
thread.join();

total_duration = duration_cast<milliseconds>(end - start).count();
}

float getAveLatency() {
assert(latencies.size() > 0);

auto average_latency =
std::accumulate(latencies.begin(), latencies.end(), 0.0) / latencies.size();
auto average_latency = std::accumulate(latencies.begin(), latencies.end(), 0.0) / latencies.size();

spdlog::info("[Client]: Data access complete, average latency: {0} milliseconds", average_latency);
return average_latency;
Expand All @@ -82,7 +84,8 @@ class ClientHandler {
}

void writeOutput() {
if (config.init_db) return;
if (config.init_db)
return;

if (!config.experiment_result_file.is_open()) {
getAveLatency();
Expand Down
10 changes: 4 additions & 6 deletions src/client/clientUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
#include "constants.h"
#include "encryption_engine.h"

#include <sstream>
#include <argparse/argparse.hpp>
#include <mutex>
#include <sstream>

std::mutex fileMutex;

bool moreOperationsExist(ClientConfig &config) {
return (config.use_seed && !config.seed_data.eof()) ||
(!config.use_seed && config.num_operations > 0);
return (config.use_seed && !config.seed_data.eof()) || (!config.use_seed && config.num_operations > 0);
}

Operation getInitKV(ClientConfig &config) {
Expand Down Expand Up @@ -95,8 +94,7 @@ std::string clientEncrypt(const std::string &value) {
encryption_engine engine;

std::unique_ptr<unsigned char> cipher_text(new unsigned char[4096]);
size_t out_len =
(size_t)engine.encryptNonDeterministic(value, cipher_text.get());
size_t out_len = (size_t)engine.encryptNonDeterministic(value, cipher_text.get());
std::string updated_val((const char *)cipher_text.get(), out_len);
return updated_val;
}
Expand Down Expand Up @@ -142,7 +140,7 @@ void parseArgs(int argc, char *argv[], ClientConfig &config) {
if (!config.experiment_result_file.is_open()) {
throw std::runtime_error("Invalid path to experiment result file");
}
}
}

config.num_clients = program.get<int>("--nthreads");
config.num_warmup_operations = program.get<int>("--warmup");
Expand Down
2 changes: 1 addition & 1 deletion src/client/clientUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define CLIENT_UTILS_H

#include <fstream>
#include <string>
#include <sodium.h>
#include <string>

#include "RPC.h"

Expand Down
5 changes: 2 additions & 3 deletions src/enclave/ecalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
#include <openenclave/enclave.h>
#include <string>

#include "shared.h"
#include "encryption_engine.h"
#include "ortoa_t.h"
#include "shared.h"

void access_data(int op_const, const char *in_val, size_t in_size,
const char *update_val, size_t update_size,
void access_data(int op_const, const char *in_val, size_t in_size, const char *update_val, size_t update_size,
unsigned char *cipher_text, size_t *out_size) {
encryption_engine engine;

Expand Down
3 changes: 1 addition & 2 deletions src/enclave/trace.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright (c) Open Enclave SDK contributors.
// Licensed under the MIT License.

#define TRACE_ENCLAVE(fmt, ...) \
printf("Enclave: %s(%d): " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define TRACE_ENCLAVE(fmt, ...) printf("Enclave: %s(%d): " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
Loading

0 comments on commit 51f3e27

Please sign in to comment.