Skip to content

Commit

Permalink
refs none, fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tengfei1010 committed Jan 16, 2018
1 parent 4c6391a commit 087cf37
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 1,048,618 deletions.
2 changes: 1 addition & 1 deletion lib/AprofHook/AprofHookPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void AprofHook::SetupHooks() {

Function *Func = &*FI;

if (Func->hasInternalLinkage()) {
if (Func->getSection() == ".text.startup") {
continue;
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/AProfHooks/include/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void log_set_level(int level);

void log_set_quiet(int enable);

void log_init(FILE *fp, int level, int enable);

void log_log(int level, const char *file, int line, const char *fmt, ...);

}
Expand Down
63 changes: 23 additions & 40 deletions runtime/AProfHooks/src/aproflib.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stack>
#include <vector>
#include <unordered_map>

#include "aproflib.h"
Expand All @@ -7,22 +7,16 @@
using namespace std;

unsigned long count = 0;
std::stack<ShadowStackElement *> shadow_stack;
std::vector<ShadowStackElement *> shadow_stack;
std::unordered_map<unsigned long, unsigned long> ts_map;


void logger_init() {
int aprof_init() {
const char *FILENAME = "aprof_logger.txt";
int LEVEL = 4; // "TRACE" < "DEBUG" < "INFO" < "WARN" < "ERROR" < "FATAL"
int QUIET = 1;
FILE *fp = fopen(FILENAME, "w");
log_set_level(LEVEL);
log_set_fp(fp);
log_set_quiet(QUIET);
}

int aprof_init() {
logger_init();
log_init(fp, LEVEL, QUIET);
}

void aprof_write(void *memory_addr, unsigned int length) {
Expand All @@ -40,7 +34,7 @@ void aprof_write(void *memory_addr, unsigned int length) {
void aprof_read(void *memory_addr, unsigned int length) {
unsigned long i;
unsigned long start_addr = (unsigned long) memory_addr;
ShadowStackElement *topEle = shadow_stack.top();
ShadowStackElement *topEle = shadow_stack.back();

for (i = start_addr; i < (start_addr + length); i++) {

Expand All @@ -52,27 +46,16 @@ void aprof_read(void *memory_addr, unsigned int length) {
log_trace("aprof_read: (ts[i]) %ld < (S[top].ts) %ld",
ts_map[i], topEle->ts);

std::stack<ShadowStackElement *> tempStack;
while (!shadow_stack.empty()) {

topEle = shadow_stack.top();
if (topEle->ts <= ts_map[i]) {

topEle->rms--;
break;

} else {

tempStack.push(topEle);
shadow_stack.pop();
if (ts_map[i] != 0) {
auto rit = shadow_stack.rbegin();
for (; rit != shadow_stack.rend(); ++rit) {
topEle = *rit;
if (topEle->ts <= ts_map[i]) {
topEle->rms--;
break;
}
}
}

while (!tempStack.empty()) {
shadow_stack.push(tempStack.top());
tempStack.pop();
}

}

ts_map[i] = count;
Expand All @@ -82,7 +65,7 @@ void aprof_read(void *memory_addr, unsigned int length) {


void aprof_increment_rms() {
ShadowStackElement *topElement = shadow_stack.top();
ShadowStackElement *topElement = shadow_stack.back();
if (topElement) {
topElement->rms++;
}
Expand All @@ -97,27 +80,27 @@ void aprof_call_before(int funcId, unsigned long numCost) {
newEle->rms = 0;
// newEle->cost update in aprof_return
newEle->cost = numCost;
shadow_stack.push(newEle);
shadow_stack.push_back(newEle);
log_trace("aprof_call_before: push new element %d", funcId);

}


void aprof_return(unsigned long numCost) {

ShadowStackElement *topElement = shadow_stack.top();
ShadowStackElement *topElement = shadow_stack.back();
topElement->cost = numCost - topElement->cost;

// log_fatal(" ID %d ; RMS %ld ; Cost %ld ;",
// topElement->funcId,
// topElement->rms,
// topElement->cost
// );
log_fatal(" ID %d ; RMS %ld ; Cost %ld ;",
topElement->funcId,
topElement->rms,
topElement->cost
);

shadow_stack.pop();
shadow_stack.pop_back();

if (shadow_stack.size() >= 2) {
ShadowStackElement *secondEle = shadow_stack.top();
ShadowStackElement *secondEle = shadow_stack.back();
secondEle->rms += topElement->rms;
log_trace("aprof_return: top element rms is %d", secondEle->rms);
}
Expand Down
6 changes: 6 additions & 0 deletions runtime/AProfHooks/src/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ void log_set_quiet(int enable) {
L.quiet = enable ? 1 : 0;
}

void log_init(FILE *fp, int level, int enable) {
L.fp = fp;
L.level = level;
L.quiet = enable ? 1 : 0;
}


void log_log(int level, const char *file, int line, const char *fmt, ...) {
if (level < L.level) {
Expand Down
Binary file modified scripts/apache34464/a.out
Binary file not shown.
Binary file modified scripts/bin-PLDI2015/fib/a.out
Binary file not shown.
Loading

0 comments on commit 087cf37

Please sign in to comment.