summaryrefslogtreecommitdiff
path: root/rts/Hpc.c
diff options
context:
space:
mode:
authorandy@galois.com <unknown>2007-06-12 07:46:55 +0000
committerandy@galois.com <unknown>2007-06-12 07:46:55 +0000
commitdf58c2a53d37caf4f3b4d0b60a0466461bba7d19 (patch)
tree42be5574992b8e06e3fb218dc1d3974e271f15af /rts/Hpc.c
parentd0ea71ec5000050ec22487029a9fcf6da76ee422 (diff)
downloadhaskell-df58c2a53d37caf4f3b4d0b60a0466461bba7d19.tar.gz
Adding new ffi calls into the Hpc rts subsystem
foreign import ccall unsafe hs_hpc_write :: CString -> IO () foreign import ccall unsafe hs_hpc_read :: CString -> IO () These write a Hpc description of the state of the world to a file, or read a description into the current Hpc tickbox subsystem.
Diffstat (limited to 'rts/Hpc.c')
-rw-r--r--rts/Hpc.c211
1 files changed, 117 insertions, 94 deletions
diff --git a/rts/Hpc.c b/rts/Hpc.c
index b183253147..8411e61448 100644
--- a/rts/Hpc.c
+++ b/rts/Hpc.c
@@ -73,9 +73,8 @@ static void failure(char *msg) {
exit(-1);
}
-static int init_open(char *filename)
-{
- tixFile = fopen(filename,"r");
+static int init_open(FILE *file) {
+ tixFile = file;
if (tixFile == 0) {
return 0;
}
@@ -121,76 +120,82 @@ static StgWord64 expectWord64(void) {
return tmp;
}
-static void hpc_init(void) {
+static void
+readTix(void) {
int i;
- Info *tmpModule;
+ Info *tmpModule;
- if (hpc_inited != 0) {
- return;
- }
- hpc_inited = 1;
-
- tixFilename = (char *) malloc(strlen(prog_name) + 6);
- sprintf(tixFilename, "%s.tix", prog_name);
-
- if (init_open(tixFilename)) {
- totalTixes = 0;
-
- ws();
+ totalTixes = 0;
+
+ ws();
+ expect('T');
+ expect('i');
+ expect('x');
+ ws();
+ expect('[');
+ ws();
+
+ while(tix_ch != ']') {
+ tmpModule = (Info *)calloc(1,sizeof(Info));
expect('T');
expect('i');
expect('x');
+ expect('M');
+ expect('o');
+ expect('d');
+ expect('u');
+ expect('l');
+ expect('e');
+ ws();
+ tmpModule -> modName = expectString();
+ ws();
+ tmpModule -> hashNo = (unsigned int)expectWord64();
+ ws();
+ tmpModule -> tickCount = (int)expectWord64();
+ tmpModule -> tixArr = (StgWord64 *)calloc(tmpModule->tickCount,sizeof(StgWord64));
+ tmpModule -> tickOffset = totalTixes;
+ totalTixes += tmpModule -> tickCount;
ws();
expect('[');
ws();
- while(tix_ch != ']') {
- tmpModule = (Info *)calloc(1,sizeof(Info));
- expect('T');
- expect('i');
- expect('x');
- expect('M');
- expect('o');
- expect('d');
- expect('u');
- expect('l');
- expect('e');
- ws();
- tmpModule -> modName = expectString();
- ws();
- tmpModule -> hashNo = (unsigned int)expectWord64();
- ws();
- tmpModule -> tickCount = (int)expectWord64();
- tmpModule -> tixArr = (StgWord64 *)calloc(tmpModule->tickCount,sizeof(StgWord64));
- tmpModule -> tickOffset = totalTixes;
- totalTixes += tmpModule -> tickCount;
- ws();
- expect('[');
- ws();
- for(i = 0;i < tmpModule->tickCount;i++) {
- tmpModule->tixArr[i] = expectWord64();
- ws();
- if (tix_ch == ',') {
- expect(',');
- ws();
- }
- }
- expect(']');
+ for(i = 0;i < tmpModule->tickCount;i++) {
+ tmpModule->tixArr[i] = expectWord64();
ws();
-
- if (!modules) {
- modules = tmpModule;
- } else {
- nextModule->next=tmpModule;
- }
- nextModule=tmpModule;
-
if (tix_ch == ',') {
expect(',');
ws();
}
}
expect(']');
- fclose(tixFile);
+ ws();
+
+ if (!modules) {
+ modules = tmpModule;
+ } else {
+ nextModule->next=tmpModule;
+ }
+ nextModule=tmpModule;
+
+ if (tix_ch == ',') {
+ expect(',');
+ ws();
+ }
+ }
+ expect(']');
+ fclose(tixFile);
+}
+
+static void hpc_init(void) {
+ if (hpc_inited != 0) {
+ return;
+ }
+ hpc_inited = 1;
+
+ tixFilename = (char *) malloc(strlen(prog_name) + 6);
+ sprintf(tixFilename, "%s.tix", prog_name);
+
+ if (init_open(fopen(tixFilename,"r"))) {
+ readTix();
}
}
@@ -526,24 +531,17 @@ startupHpc(void) {
}
-/* Called at the end of execution, to write out the Hpc *.tix file
- * for this exection. Safe to call, even if coverage is not used.
- */
-void
-exitHpc(void) {
+static void
+writeTix(FILE *f) {
Info *tmpModule;
int i, inner_comma, outer_comma;
- debugTrace(DEBUG_hpc,"exitHpc");
+ outer_comma = 0;
- if (hpc_inited == 0) {
+ if (f == 0) {
return;
}
- FILE *f = fopen(tixFilename,"w");
-
- outer_comma = 0;
-
fprintf(f,"Tix [");
tmpModule = modules;
for(;tmpModule != 0;tmpModule = tmpModule->next) {
@@ -580,34 +578,22 @@ exitHpc(void) {
}
fprintf(f,"]\n");
- /*
- tmpModule = modules;
- for(;tmpModule != 0;tmpModule = tmpModule->next) {
- if (!tmpModule->tixArr) {
- debugTrace(DEBUG_hpc,
- "warning: module %s did not register any hpc tick data\n",
- tmpModule->modName);
- }
-
- for(i = 0;i < tmpModule->tickCount;i++) {
- if (comma) {
- fprintf(f,",");
- } else {
- comma = 1;
- }
+ fclose(f);
+}
- if (tmpModule->tixArr) {
- fprintf(f,"%" PRIuWORD64,tmpModule->tixArr[i]);
- } else {
- fprintf(f,"0");
- }
+/* Called at the end of execution, to write out the Hpc *.tix file
+ * for this exection. Safe to call, even if coverage is not used.
+ */
+void
+exitHpc(void) {
+ debugTrace(DEBUG_hpc,"exitHpc");
- }
+ if (hpc_inited == 0) {
+ return;
}
-
- fprintf(f,"]\n");
- */
- fclose(f);
+
+ FILE *f = fopen(tixFilename,"w");
+ writeTix(f);
if (rixFile != NULL) {
hs_hpc_tick(RixFinishedOp,(StgThreadID)0);
@@ -619,3 +605,40 @@ exitHpc(void) {
}
+void hs_hpc_read(char *filename) {
+ Info *orig_modules = 0, *tmpModule, *tmpOrigModule;
+ int i;
+
+ orig_modules = modules;
+ modules = 0;
+ if (init_open(fopen(filename,"r"))) {
+ readTix();
+ // Now we copy across the arrays. O(n^2), but works
+ for(tmpModule = modules;
+ tmpModule != 0;
+ tmpModule = tmpModule->next) {
+
+ for(tmpOrigModule = orig_modules;
+ tmpOrigModule != 0;
+ tmpOrigModule = tmpOrigModule->next) {
+ if (!strcmp(tmpModule->modName,tmpOrigModule->modName)) {
+ assert(tmpModule->tixArr != 0);
+ assert(tmpOrigModule->tixArr != 0);
+ assert(tmpModule->tickCount == tmpOrigModule->tickCount);
+ for(i=0;i < tmpModule->tickCount;i++) {
+ tmpOrigModule->tixArr[i] = tmpModule->tixArr[i];
+ }
+ tmpModule->tixArr = tmpOrigModule->tixArr;
+ break;
+ }
+ }
+ }
+ }
+}
+
+void hs_hpc_write(char *filename) {
+ writeTix(fopen(filename,"w"));
+}
+
+
+