19 #include <unordered_map>
22 #define OFFSET 20000000
27 #define USE_TREE_BASED_FOR_DATA_CENTRIC
35 PIN_ERROR(
"Pin tool to gather calling context on each instruction and associate each memory access to its data object (shadow memory technique).\n" + KNOB_BASE::StringKnobSummary() +
"\n");
76 fprintf(
gTraceFile,
"Unloading %s\n", IMG_Name(img).c_str());
77 printf(
"\n [CCTLIB client] Unloading....");
78 printf(
"\n [CCTLIB client] Total accesses: ");
80 printf(
"%d,%.3d,%.3d.\n\n",
CTR / 1000000, (
CTR % 1000000) / 1000,
CTR % 1000);
82 printf(
"%d,%.3d.\n\n",
CTR / 1000,
CTR % 1000);
87 uint32_t indexList[length], ind_tmp;
88 long counterList[length], temp;
89 float ratioList[length], ratio_temp;
92 fprintf(
gTraceFile,
"\n\nA total of %ld memeroy accesses.\n",
CTR);
99 indexList[ii] = iter->first;
100 tempData = iter->second;
101 counterList[ii] = tempData.
counter;
105 for (ii = 0; ii < length; ii++)
106 for (
int jj = 0; jj < ii; jj++) {
107 if (counterList[jj] < counterList[ii]) {
108 temp = counterList[jj];
109 counterList[jj] = counterList[ii];
110 counterList[ii] = temp;
111 ind_tmp = indexList[jj];
112 indexList[jj] = indexList[ii];
113 indexList[ii] = ind_tmp;
119 for (ii = 0; ii < min(60, length); ii++) {
120 uint32_t index = indexList[ii];
126 tempData = search->second;
131 sysIndex = (uint32_t)((index - chunk -
OFFSET) / 100);
136 uint64_t head = tempData.
data.beg_addr;
137 uint64_t tail = tempData.
data.end_addr;
138 int sizeInBytes = (int)tail - head;
141 fprintf(
gTraceFile,
"\n\n\nRank %d >>>> Dynamic Data %d chunk %d accessed %ld times, range:[%p,%p]\n",
142 ii, sysIndex, chunk, tempData.
counter, head, tail);
144 fprintf(
gTraceFile,
"\n\n\nRank %d >>>> Static Data %d: \"%s\", accessed %ld times, range:[%p,%p]\n",
145 ii, sysIndex, GetStringPool() + tempData.
data.symName, tempData.
counter, head, tail);
147 if (sizeInBytes > 1 << 20)
148 fprintf(
gTraceFile,
"size = %.3f MB.\n", (
float)(sizeInBytes) / (
float)(1 << 20));
149 else if (sizeInBytes > 1 << 10)
150 fprintf(
gTraceFile,
"size = %.3f KB.\n", (
float)(sizeInBytes) / (
float)(1 << 10));
152 fprintf(
gTraceFile,
"size = %d B.\n", sizeInBytes);
157 long* window_arr = search1->second;
159 fprintf(
gTraceFile,
"distribtion among windows: \n");
162 fprintf(
gTraceFile,
"|%ld\t", window_arr[jj]);
172 int* th_arr = search2->second;
173 fprintf(
gTraceFile,
"accessed by threads: \n");
174 for (jj = 0; jj < 32; jj++) {
196 char* envPath = getenv(
"CCTLIB_CLIENT_OUTPUT_FILE");
200 snprintf(name,
sizeof(name),
"%s", envPath);
203 gethostname(name + strlen(name),
MAX_FILE_PATH - strlen(name));
204 pid_t pid = getpid();
205 sprintf(name + strlen(name),
"%d", pid);
206 cerr <<
"\n [CCTLIB client] Creating log file at:" << name <<
"\n\n";
211 for (
int i = 0; i < argc; i++) {
226 uint32_t
getIndex(uint64_t beg, uint64_t end,
void* addr, uint32_t sysIndex, THREADID threadId) {
227 int size = (int)((end - beg) / 1024);
228 int offset = (int)(((
long)addr - beg) / 1024);
230 int chunk = floor(offset / (
ChunkSize / 1024)) + 1;
233 printf(
"\n [CCTLIB client] !!too large array!! Results of window distribution may be iffy.\n\n");
241 uint32_t localIndex = (sysIndex * 100 +
OFFSET + chunk);
250 uint32_t sysIndex =
data.symName;
253 int size =
data.end_addr -
data.beg_addr;
254 if (size < (800 * (1 << 10)))
262 __sync_fetch_and_add(&(search->second).counter, 1);
277 long* window_arr = search1->second;
278 __sync_fetch_and_add(&(window_arr[
window]), 1);
293 int* th_arr = search2->second;
295 __sync_fetch_and_add(&(th_arr[threadId]), 1);
298 int* th_arr =
new int[32];
299 for (
int ii = 0; ii < 32; ii++)
310 __sync_fetch_and_add(&
CTR, 1);
320 switch (d.objectType) {
337 INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)
SimpleCCTQuery, IARG_THREAD_ID, IARG_UINT32, slot, IARG_END);
341 if (INS_IsControlFlow(ins) || INS_IsRet(ins)) {
346 if (INS_IsStackRead(ins) || INS_IsStackWrite(ins))
349 if (INS_IsMemoryRead(ins) || INS_IsMemoryWrite(ins)) {
351 UINT32 memOperands = INS_MemoryOperandCount(ins);
354 for (UINT32 memOp = 0; memOp < memOperands; memOp++) {
355 INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)
MemAnalysisRoutine, IARG_MEMORYOP_EA, memOp, IARG_THREAD_ID, IARG_END);
360 int main(
int argc,
char* argv[]) {
362 if (PIN_Init(argc, argv))
unordered_map< uint32_t, int * > DataThreadMap
int main(int argc, char *argv[])
uint32_t getIndex(uint64_t beg, uint64_t end, void *addr, uint32_t sysIndex, THREADID threadId)
void ClientInit(int argc, char *argv[])
VOID MemAnalysisRoutine(void *addr, THREADID threadId)
unordered_map< uint32_t, long * > DataWindowMap
VOID SimpleCCTQuery(THREADID id, const uint32_t slot)
void updateDataList(void *addr, DataHandle_t data, THREADID threadId)
VOID ImageUnload(IMG img, VOID *v)
unordered_map< uint32_t, DataObj > DataObjectMap
VOID InstrumentInsCallback(INS ins, VOID *v, const uint32_t slot)
#define INTERESTING_INS_ALL
DataHandle_t GetDataObjectHandle(VOID *address, const THREADID threadId)
int PinCCTLibInit(IsInterestingInsFptr isInterestingIns, FILE *logFile, CCTLibInstrumentInsCallback userCallback, VOID *userCallbackArg, BOOL doDataCentric=false)
VOID PrintFullCallingContext(const ContextHandle_t ctxtHandle)
struct DataHandle_t { uint8_t objectType DataHandle_t
ContextHandle_t GetContextHandle(const THREADID id, const uint32_t slot)