Skip to content

Commit

Permalink
code reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hariharan-devarajan committed Oct 10, 2023
1 parent 2bddb99 commit bbc5797
Show file tree
Hide file tree
Showing 28 changed files with 502 additions and 357 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: Google
11 changes: 10 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ jobs:
sudo apt-get update
sudo apt-get install gcc g++ libtool-bin openmpi-bin libopenmpi-dev
sudo apt-get install python3.10 python3-pip
sudo apt-get install gcovr
sudo apt-get install gcovr clang-format
- name: Check code formatting
if: matrix.os == 'ubuntu-22.04' && matrix.dir == 'clone' && matrix.perm == 'user'
run: |
ls -a
git clang-format --diff HEAD~1 -q
if git clang-format --diff HEAD~1 -q | grep -m 1 '^' >/dev/null; then
echo >&2 "Failed clang-format check. Run: git clang-format HEAD~1"
exit 1
fi
- name: Install dlio benchmark
if: matrix.os == 'ubuntu-22.04' && matrix.dir == 'clone' && matrix.perm == 'user'
run: |
Expand Down
11 changes: 8 additions & 3 deletions dlio_profiler/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from functools import wraps
from typing import Dict
import os

DLIO_PROFILER_ENABLE_ENV = "DLIO_PROFILER_ENABLE"
DLIO_PROFILER_INIT_ENV = "DLIO_PROFILER_INIT"

Expand All @@ -12,13 +13,17 @@

from pathlib import Path
import inspect
import sys,signal
import sys, signal


def capture_signal(signal_number, frame):
dlio_logger.get_instance().finalize()
sys.exit(1)


signal.signal(signal.SIGABRT, capture_signal)


class dlio_logger:
__instance = None

Expand All @@ -38,7 +43,7 @@ def get_instance(cls, log_file=None):
@staticmethod
def initialize_log(logfile, data_dir, process_id):
log_file = None
if logfile :
if logfile:
log_file = Path(logfile)
instance = dlio_logger.get_instance(log_file)
if DLIO_PROFILER_ENABLE:
Expand All @@ -51,7 +56,7 @@ def initialize_log(logfile, data_dir, process_id):
log_file = f"{instance.logfile}"
if data_dir:
data_dir = f"{data_dir}"
instance.logger.initialize(log_file = log_file, data_dirs = data_dir, process_id=process_id)
instance.logger.initialize(log_file=log_file, data_dirs=data_dir, process_id=process_id)
return instance

def get_time(self):
Expand Down
18 changes: 13 additions & 5 deletions include/dlio_profiler/core/dlio_profiler_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#ifndef DLIO_PROFILER_DLIO_PROFILER_MAIN_H
#define DLIO_PROFILER_DLIO_PROFILER_MAIN_H

#include <cstring>
#include <thread>
#include <stdexcept>
Expand Down Expand Up @@ -31,16 +32,23 @@ namespace dlio_profiler {
int process_id;
bool is_initialized;
bool bind;
void initlialize(bool is_init, bool _bind, const char *_log_file = nullptr, const char *_data_dirs = nullptr, const int *_process_id = nullptr);

void initlialize(bool is_init, bool _bind, const char *_log_file = nullptr, const char *_data_dirs = nullptr,
const int *_process_id = nullptr);

public:
DLIOProfilerCore(ProfilerStage stage, ProfileType type, const char *log_file = nullptr, const char *data_dirs = nullptr, const int *process_id = nullptr);
DLIOProfilerCore(ProfilerStage stage, ProfileType type, const char *log_file = nullptr,
const char *data_dirs = nullptr, const int *process_id = nullptr);

inline bool is_active() {
return is_enabled;
}

TimeResolution get_time();
void log(const char* event_name, const char* category,
TimeResolution start_time, TimeResolution duration,
std::unordered_map<std::string, std::any> &metadata);

void log(const char *event_name, const char *category,
TimeResolution start_time, TimeResolution duration,
std::unordered_map<std::string, std::any> &metadata);

bool finalize();
};
Expand Down
12 changes: 9 additions & 3 deletions include/dlio_profiler/core/enumeration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

#ifndef DLIO_PROFILER_ENUMERATION_H
#define DLIO_PROFILER_ENUMERATION_H
enum WriterType : uint8_t { CHROME = 0};
enum ProfilerStage: uint8_t { PROFILER_INIT=0, PROFILER_FINI=1, PROFILER_OTHER=2};
enum ProfileType: uint8_t { PROFILER_PRELOAD=0, PROFILER_PY_APP=1, PROFILER_CPP_APP=2, PROFILER_C_APP=3};
enum WriterType : uint8_t {
CHROME = 0
};
enum ProfilerStage : uint8_t {
PROFILER_INIT = 0, PROFILER_FINI = 1, PROFILER_OTHER = 2
};
enum ProfileType : uint8_t {
PROFILER_PRELOAD = 0, PROFILER_PY_APP = 1, PROFILER_CPP_APP = 2, PROFILER_C_APP = 3
};
#endif //DLIO_PROFILER_ENUMERATION_H
10 changes: 6 additions & 4 deletions include/dlio_profiler/core/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#define DLIO_PROFILER_ERROR_H

struct ErrorCode {
const char* code;
const char* message;
const char *code;
const char *message;
};

// Main error codes
Expand All @@ -18,7 +18,9 @@ const ErrorCode FAILURE = {"1001", "Internal Failure"};
const ErrorCode UNKNOWN_PROFILER_TYPE = {"1002", "Code 1002: Unknown profiler type %d"};

// Invalid configurations
const ErrorCode UNDEFINED_DATA_DIR = {"2001", "Code 2001: Data dirs not defined. Please define env variable DLIO_PROFILER_DATA_DIR"};
const ErrorCode UNDEFINED_LOG_FILE = {"2002", "Code 2002: log file not defined. Please define env variable DLIO_PROFILER_LOG_FILE"};
const ErrorCode UNDEFINED_DATA_DIR = {"2001",
"Code 2001: Data dirs not defined. Please define env variable DLIO_PROFILER_DATA_DIR"};
const ErrorCode UNDEFINED_LOG_FILE = {"2002",
"Code 2002: log file not defined. Please define env variable DLIO_PROFILER_LOG_FILE"};

#endif //DLIO_PROFILER_ERROR_H
2 changes: 2 additions & 0 deletions include/dlio_profiler/core/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#ifndef DLIO_PROFILER_MACRO_H
#define DLIO_PROFILER_MACRO_H

#include <cpp-logger/logger.h>

#define DLIO_PROFILER_LOGGER cpplogger::Logger::Instance("DLIO_PROFILER")
#define DLIO_PROFILER_LOGINFO(format, ...) \
DLIO_PROFILER_LOGGER->log(cpplogger::LOG_INFO, format, __VA_ARGS__);
Expand Down
12 changes: 7 additions & 5 deletions include/dlio_profiler/core/singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#ifndef DLIO_PROFILER_SINGLETON_H
#define DLIO_PROFILER_SINGLETON_H

#include <iostream>
#include <memory>
#include <utility>
Expand All @@ -13,7 +14,7 @@
* @tparam T
*/
namespace dlio_profiler {
template <typename T>
template<typename T>
class Singleton {
public:
/**
Expand All @@ -24,7 +25,7 @@ namespace dlio_profiler {
* @tparam T
* @return instance of T
*/
template <typename... Args>
template<typename... Args>
static std::shared_ptr<T> get_instance(Args... args) {
if (instance == nullptr)
instance = std::shared_ptr<T>(new T(std::forward<Args>(args)...));
Expand All @@ -34,19 +35,20 @@ namespace dlio_profiler {
/**
* Operators
*/
Singleton& operator=(const Singleton) = delete; /* deleting = operatos*/
Singleton &operator=(const Singleton) = delete; /* deleting = operatos*/
/**
* Constructor
*/
public:
Singleton(const Singleton&) = delete; /* deleting copy constructor. */
Singleton(const Singleton &) = delete; /* deleting copy constructor. */

protected:
static std::shared_ptr<T> instance;

Singleton() {} /* hidden default constructor. */
};

template <typename T>
template<typename T>
std::shared_ptr<T> Singleton<T>::instance = nullptr;
} // namespace dlio_profiler
#endif //DLIO_PROFILER_SINGLETON_H
17 changes: 11 additions & 6 deletions include/dlio_profiler/dlio_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
#include <dlio_profiler/core/typedef.h>
#include <dlio_profiler/core/constants.h>

#ifdef __cplusplus
/**
* CPP Only
Expand All @@ -24,32 +25,36 @@
#include <string>

class DLIOProfiler {
const char* name;
const char *name;
TimeResolution start_time;
std::unordered_map<std::string, std::any> metadata;
std::shared_ptr<dlio_profiler::DLIOProfilerCore> dlio_profiler_core;
public:
DLIOProfiler(const char* _name):name(_name), metadata(){
DLIOProfiler(const char *_name) : name(_name), metadata() {
dlio_profiler_core = DLIO_PROFILER_MAIN_SINGLETON(ProfilerStage::PROFILER_OTHER, ProfileType::PROFILER_CPP_APP);
start_time = dlio_profiler_core->get_time();
}
inline void update(const char* key, int value) {

inline void update(const char *key, int value) {
if (dlio_profiler_core->is_active()) {
metadata.insert_or_assign(key, value);
}
}
inline void update(const char* key, const char* value) {

inline void update(const char *key, const char *value) {
if (dlio_profiler_core->is_active()) {
metadata.insert_or_assign(key, value);
}
}

~DLIOProfiler() {
if (dlio_profiler_core->is_active()) {
TimeResolution end_time = dlio_profiler_core->get_time();
dlio_profiler_core->log(name, CPP_LOG_CATEGORY, start_time, end_time - start_time, metadata);
}
}
};

#define DLIO_PROFILER_CPP_INIT(log_file, data_dirs, process_id) \
DLIO_PROFILER_MAIN_SINGLETON_INIT(ProfilerStage::PROFILER_INIT, ProfileType::PROFILER_CPP_APP, log_file, data_dirs, process_id);
#define DLIO_PROFILER_CPP_FINI() \
Expand All @@ -69,9 +74,9 @@ delete profiler_##name
extern "C" {
#endif
// C APIs
void initialize(const char * log_file, const char * data_dirs, int* process_id);
void initialize(const char *log_file, const char *data_dirs, int *process_id);
TimeResolution get_time();
void log_event(const char * name, const char * cat, TimeResolution start_time, TimeResolution duration);
void log_event(const char *name, const char *cat, TimeResolution start_time, TimeResolution duration);
void finalize();

#define DLIO_PROFILER_C_INIT(log_file, data_dirs, process_id) \
Expand Down
36 changes: 22 additions & 14 deletions src/dlio_profiler/brahma/posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define CATEGORY "POSIX"

std::shared_ptr<brahma::POSIXDLIOProfiler> brahma::POSIXDLIOProfiler::instance = nullptr;

int brahma::POSIXDLIOProfiler::open(const char *pathname, int flags, ...) {
BRAHMA_MAP_OR_FAIL(open);
DLIO_LOGGER_START(pathname);
Expand All @@ -28,6 +29,7 @@ int brahma::POSIXDLIOProfiler::open(const char *pathname, int flags, ...) {
if (trace) this->trace(ret);
return ret;
}

int brahma::POSIXDLIOProfiler::close(int fd) {
BRAHMA_MAP_OR_FAIL(close);
DLIO_LOGGER_START(fd);
Expand All @@ -38,6 +40,7 @@ int brahma::POSIXDLIOProfiler::close(int fd) {
if (trace) this->remove_trace(fd);
return ret;
}

ssize_t brahma::POSIXDLIOProfiler::write(int fd, const void *buf, size_t count) {
BRAHMA_MAP_OR_FAIL(write);
DLIO_LOGGER_START(fd);
Expand All @@ -48,6 +51,7 @@ ssize_t brahma::POSIXDLIOProfiler::write(int fd, const void *buf, size_t count)
DLIO_LOGGER_END();
return ret;
}

ssize_t brahma::POSIXDLIOProfiler::read(int fd, void *buf, size_t count) {
BRAHMA_MAP_OR_FAIL(read);
DLIO_LOGGER_START(fd);
Expand All @@ -58,6 +62,7 @@ ssize_t brahma::POSIXDLIOProfiler::read(int fd, void *buf, size_t count) {
DLIO_LOGGER_END();
return ret;
}

off_t brahma::POSIXDLIOProfiler::lseek(int fd, off_t offset, int whence) {
BRAHMA_MAP_OR_FAIL(lseek);
DLIO_LOGGER_START(fd);
Expand Down Expand Up @@ -93,7 +98,7 @@ int brahma::POSIXDLIOProfiler::open64(const char *path, int flags, ...) {
va_end(args);
DLIO_LOGGER_UPDATE(mode)
ret = __real_open64(path, flags, mode);
}else {
} else {
ret = __real_open64(path, flags);
}
DLIO_LOGGER_UPDATE(path)
Expand Down Expand Up @@ -211,7 +216,7 @@ void *brahma::POSIXDLIOProfiler::mmap(void *addr, size_t length, int prot, int f
DLIO_LOGGER_UPDATE(flags);
DLIO_LOGGER_UPDATE(offset);
DLIO_LOGGER_UPDATE(fd);
void* ret = __real_mmap(addr, length, prot, flags, fd, offset);
void *ret = __real_mmap(addr, length, prot, flags, fd, offset);
DLIO_LOGGER_END();
return ret;
}
Expand All @@ -223,7 +228,7 @@ void *brahma::POSIXDLIOProfiler::mmap64(void *addr, size_t length, int prot, int
DLIO_LOGGER_UPDATE(flags);
DLIO_LOGGER_UPDATE(offset);
DLIO_LOGGER_UPDATE(fd);
void* ret = __real_mmap64(addr, length, prot, flags, fd, offset);
void *ret = __real_mmap64(addr, length, prot, flags, fd, offset);
DLIO_LOGGER_END();
return ret;
}
Expand Down Expand Up @@ -435,18 +440,19 @@ int brahma::POSIXDLIOProfiler::utime(const char *filename, const utimbuf *buf) {
return ret;
}

DIR* brahma::POSIXDLIOProfiler::opendir(const char *name) {
DIR *brahma::POSIXDLIOProfiler::opendir(const char *name) {
BRAHMA_MAP_OR_FAIL(opendir);
DLIO_LOGGER_START(name);
DLIO_LOGGER_UPDATE(name);
DIR* ret = __real_opendir(name);
DIR *ret = __real_opendir(name);
DLIO_LOGGER_END();
return ret;
}

int brahma::POSIXDLIOProfiler::fcntl(int fd, int cmd, ...) {
BRAHMA_MAP_OR_FAIL(fcntl);
if(cmd==F_DUPFD || cmd==F_DUPFD_CLOEXEC || cmd==F_SETFD || cmd==F_SETFL || cmd==F_SETOWN) { // arg: int
if (cmd == F_DUPFD || cmd == F_DUPFD_CLOEXEC || cmd == F_SETFD || cmd == F_SETFL ||
cmd == F_SETOWN) { // arg: int
va_list arg;
va_start(arg, cmd);
int val = va_arg(arg, int);
Expand All @@ -457,14 +463,14 @@ int brahma::POSIXDLIOProfiler::fcntl(int fd, int cmd, ...) {
int ret = __real_fcntl(fd, cmd, val);
DLIO_LOGGER_END();
return ret;
} else if(cmd==F_GETFD || cmd==F_GETFL || cmd==F_GETOWN) {
} else if (cmd == F_GETFD || cmd == F_GETFL || cmd == F_GETOWN) {
DLIO_LOGGER_START(fd);
DLIO_LOGGER_UPDATE(fd);
DLIO_LOGGER_UPDATE(cmd);
int ret = __real_fcntl(fd, cmd);
DLIO_LOGGER_END();
return ret;
} else if(cmd==F_SETLK || cmd==F_SETLKW || cmd==F_GETLK) {
} else if (cmd == F_SETLK || cmd == F_SETLKW || cmd == F_GETLK) {
va_list arg;
va_start(arg, cmd);
struct flock *lk = va_arg(arg, struct flock*);
Expand Down Expand Up @@ -512,12 +518,14 @@ int brahma::POSIXDLIOProfiler::mkfifo(const char *pathname, mode_t mode) {
return ret;
}

mode_t brahma::POSIXDLIOProfiler::umask(mode_t mask) {
BRAHMA_MAP_OR_FAIL(umask);
DLIO_LOGGER_START(mask);
mode_t ret = __real_umask(mask);
DLIO_LOGGER_END();
return ret;
mode_t brahma::POSIXDLIOProfiler::umask(mode_t
mask) {
BRAHMA_MAP_OR_FAIL(umask);
DLIO_LOGGER_START(mask);
mode_t ret = __real_umask(mask);
DLIO_LOGGER_END();
return
ret;
}

int brahma::POSIXDLIOProfiler::access(const char *path, int amode) {
Expand Down
Loading

0 comments on commit bbc5797

Please sign in to comment.