Created
September 6, 2019 17:26
-
-
Save lally/e2c79693abe39958029be6fd9e617eb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <atomic> | |
#include <cstdint> | |
#include <linux/perf_event.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <sys/shm.h> | |
#include <sys/types.h> | |
#include <syscall.h> | |
#include <time.h> | |
#include <unistd.h> | |
namespace ppt { | |
namespace Minimal { | |
class first; | |
extern "C" int _ppt_hmem_Minimal; | |
struct data_Minimal { | |
static first * ppt_buf; | |
static int ppt_bufsz; | |
static int ppt_offset; | |
static int ppt_counter_fd[3]; | |
}; | |
bool try_attach(); | |
class first; | |
int nextIndex(); | |
void save_counters(uint64_t*,uint64_t*,uint64_t*); | |
class first { | |
private: | |
int __ppt_seqno; | |
int __ppt_type; | |
public: | |
struct timespec duration_start; | |
struct timespec duration_end; | |
uint64_t events_0_start= 0; | |
uint64_t events_0_end= 0; | |
uint64_t events_1_start= 0; | |
uint64_t events_1_end= 0; | |
uint64_t events_2_start= 0; | |
uint64_t events_2_end= 0; | |
int a= 0; | |
int b= 0; | |
int c= 0; | |
private: | |
int __ppt_seqno_back; | |
public: | |
void save() { | |
if (!data_Minimal::ppt_buf && !_ppt_hmem_Minimal) { return; } | |
if (try_attach()) { | |
int index = nextIndex(); | |
__ppt_seqno = index; | |
__ppt_seqno_back = index; | |
__ppt_type = 1; | |
const int modidx = (data_Minimal::ppt_offset + index-1) % data_Minimal::ppt_bufsz; | |
data_Minimal::ppt_buf[modidx].__ppt_seqno = 0; | |
data_Minimal::ppt_buf[modidx].__ppt_seqno_back = 0; | |
std::atomic_thread_fence(std::memory_order_release); | |
data_Minimal::ppt_buf[modidx].__ppt_seqno = index; | |
std::atomic_thread_fence(std::memory_order_release); | |
memcpy(((uint8_t*)&data_Minimal::ppt_buf[modidx]) + sizeof(__ppt_seqno), ((uint8_t*)this) + sizeof(__ppt_seqno), sizeof(*this) - 2*sizeof(__ppt_seqno)); | |
std::atomic_thread_fence(std::memory_order_release); | |
data_Minimal::ppt_buf[modidx].__ppt_seqno_back = index; | |
std::atomic_thread_fence(std::memory_order_release); | |
} | |
} | |
void snapshot_duration_start() { | |
clock_gettime(CLOCK_REALTIME, &duration_start); | |
} | |
void snapshot_duration_end() { | |
clock_gettime(CLOCK_REALTIME, &duration_end); | |
} | |
void snapshot_events_start() { | |
save_counters(&events_0_start, &events_1_start, &events_2_start); | |
} | |
void snapshot_events_end() { | |
save_counters(&events_0_end, &events_1_end, &events_2_end); | |
} | |
}; | |
class second { | |
private: | |
int __ppt_seqno; | |
int __ppt_type; | |
public: | |
uint64_t foos_0_start= 0; | |
uint64_t foos_0_end= 0; | |
uint64_t foos_1_start= 0; | |
uint64_t foos_1_end= 0; | |
uint64_t foos_2_start= 0; | |
uint64_t foos_2_end= 0; | |
private: | |
uint8_t __ppt_endpad_44[44]; | |
int __ppt_seqno_back; | |
public: | |
void save() { reinterpret_cast<first*>(this)->save(); } | |
void snapshot_foos_start() { | |
save_counters(&foos_0_start, &foos_1_start, &foos_2_start); | |
} | |
void snapshot_foos_end() { | |
save_counters(&foos_0_end, &foos_1_end, &foos_2_end); | |
} | |
}; | |
}} // namespace ppt::Minimal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment