cpp-common
Classes | Macros | Functions | Variables
common.hh File Reference

Common macros, constexpr and function definitions. More...

#include "nvsl/constants.hh"
#include "nvsl/envvars.hh"
#include <chrono>
#include <fcntl.h>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <string>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#include <fnmatch.h>
Include dependency graph for common.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DBGH
 

Macros

#define NVSL_NODISCARD   [[nodiscard]]
 
#define NVSL_UNUSED   __attribute__((unused))
 
#define NVSL_EXPORT   __attribute__((visibility("default")))
 
#define NVSL_NOINLINE   __attribute__((noinline))
 
#define NVSL_BEGIN_IGNORE_WPEDANTIC
 
#define NVSL_END_IGNORE_WPEDANTIC   _Pragma("GCC diagnostic pop")
 
#define NVSL_LINE_NAME(prefix)   NVSL_JOIN(prefix, __LINE__)
 
#define NVSL_JOIN(symbol1, symbol2)   NVSL_DO_JOIN(symbol1, symbol2)
 
#define NVSL_DO_JOIN(symbol1, symbol2)   symbol1##symbol2
 
#define NVSL_GUARD(mtx)   std::lock_guard<std::mutex> NVSL_LINE_NAME(nvsl_macro_lock_guard)((mtx))
 Wrapper for std::lock_guard.
 
#define NVSL_GUARD_PTR(mtx)   std::lock_guard<std::mutex> NVSL_LINE_NAME(nvsl_macro_lock_guard)((*mtx))
 Wrapper for ptr to std::lock_guard.
 
#define DBG   (std::cerr)
 
#define DBGF(l)   (DBGH(l) << std::string(__FUNCTION__) << "() called." << std::endl);
 
#define DBGW
 
#define DBGE
 

Functions

bool nvsl::wildcard (const std::string &pat, const std::string &str)
 Match a pattern using wildcar.
 
std::string nvsl_cur_time_str ()
 
template<typename T >
const DBGHoperator<< (const DBGH &dbgh, const T &obj)
 
const DBGHoperator<< (const DBGH &s, std::ostream &(*f)(std::ostream &))
 
const DBGHoperator<< (const DBGH &s, std::ostream &(*f)(std::ios &))
 
const DBGHoperator<< (const DBGH &s, std::ostream &(*f)(std::ios_base &))
 
constexpr void * nvsl::align_cl (auto *ptr)
 Align ptr to the next cache line (64 bytes)
 
constexpr void * nvsl::align_4kb (auto *ptr)
 Align a ptr to 4KiB page boundary.
 
constexpr void * nvsl::align_2mb (auto *ptr)
 Align a ptr to 2MiB page boundary.
 
constexpr auto nvsl::round_bytes (auto bytes, auto mult) -> decltype(bytes)
 Rounds bytes to the multiple of mult greater than it.
 
auto nvsl::page_num (auto ptr) -> decltype(ptr)
 Get page number from virtual memory address.
 
 nvsl::result<< std::hex;size_t cur_byte=0;std::stringstream val;while(cur_byte< bytes) { result<< "0x"<< std::hex<< std::setfill( '0')<< std::setw(8)<<((uint64_t)(buf+cur_byte) >> 4)<< 4<< " ";for(size_t i=0;i< 16;i++) { const size_t idx=cur_byte+i;if(i % 4==0 &&i !=0) { result<< " ";} uint32_t elem=static_cast< uint8_t > (buf[idx])
 
result<< std::hex<< std::setfill( '0')<< std::setw(2)<< std::uppercase<< elem;if(buf[idx] >=' ' and buf[idx]<='~') { val<< buf[idx];} else { val<< ".";} } cur_byte+=16;if(cur_byte< bytes) { result<< " "<< val.str()<< std::endl;std::stringstream().swap(val);} } return result.str();} inline bool is_pid_running(pid_t pid) { while(waitpid(-1, 0, WNOHANG) > 0) { } if(0==kill(pid, 0)) return 1;return 0;} template< typename A, typename B, typename C > uint64_t nvsl::rebase_ptr (A old_base, B new_base, C ptr)
 
std::string nvsl::ns_to_hr (size_t ns_total)
 
template<typename T >
std::string nvsl::to_latex (const std::string &name, T val, const std::string &suffix, size_t div_factor=1)
 
std::string nvsl::ns_to_latex (size_t ns, const std::string &name, time_unit unit=time_unit::any_unit)
 
std::string nvsl::uint64_to_base64 (uint64_t val)
 
uint64_t nvsl::base64_to_uint64 (std::string val)
 

Variables

std::ofstream log_st
 
static std::string size_t nvsl::bytes
 

Detailed Description

Common macros, constexpr and function definitions.

Date
December 25, 2020

Definition in file common.hh.

Macro Definition Documentation

◆ DBGE

#define DBGE
Value:
(DBG << "[\x1B[31m" << std::setw(20) << std::string(__FUNCTION__) << "()" \
<< "\x1B[0m" \
<< "]\x1B[95m ERROR: \x1B[0m")

Definition at line 227 of file common.hh.

◆ DBGW

#define DBGW
Value:
(DBG << "[\x1B[1m" << std::setw(20) << std::string(__FUNCTION__) << "()" \
<< "\x1B[0m" \
<< "]\x1B[95m WARNING: \x1B[0m")

Definition at line 217 of file common.hh.

◆ NVSL_BEGIN_IGNORE_WPEDANTIC

#define NVSL_BEGIN_IGNORE_WPEDANTIC
Value:
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wpedantic\"")

Definition at line 34 of file common.hh.

Variable Documentation

◆ bytes

std::string size_t nvsl::bytes
Initial value:
{
std::stringstream result

Definition at line 334 of file common.hh.