# HG changeset patch # User Adam Chlipala # Date 1227201390 18000 # Node ID 8875ff2e85dc8d8bafd16a2038f3f33c99af74a6 # Parent 7ef4b2911b096856a6f3abaa267a1d1ef7371d49 Profiling support diff -r 7ef4b2911b09 -r 8875ff2e85dc Makefile.in --- a/Makefile.in Thu Nov 20 11:34:36 2008 -0500 +++ b/Makefile.in Thu Nov 20 12:16:30 2008 -0500 @@ -21,10 +21,10 @@ rm -rf .cm src/.cm clib/urweb.o: src/c/urweb.c - gcc -O3 -I include -c src/c/urweb.c -o clib/urweb.o + gcc -O3 -I include -c src/c/urweb.c -o clib/urweb.o $(CFLAGS) clib/driver.o: src/c/driver.c - gcc -O3 -I include -c src/c/driver.c -o clib/driver.o + gcc -O3 -I include -c src/c/driver.c -o clib/driver.o $(CFLAGS) src/urweb.cm: src/prefix.cm src/sources cat src/prefix.cm src/sources \ diff -r 7ef4b2911b09 -r 8875ff2e85dc src/c/driver.c --- a/src/c/driver.c Thu Nov 20 11:34:36 2008 -0500 +++ b/src/c/driver.c Thu Nov 20 12:16:30 2008 -0500 @@ -1,10 +1,12 @@ #include #include +#include #include #include #include #include +#include #include @@ -297,6 +299,11 @@ printf("Usage: %s [-p ] [-t ]\n", cmd); } +static void sigint(int signum) { + printf("Exiting....\n"); + exit(0); +} + int main(int argc, char *argv[]) { // The skeleton for this function comes from Beej's sockets tutorial. int sockfd; // listen on sock_fd @@ -304,7 +311,9 @@ struct sockaddr_in their_addr; // connector's address information int sin_size, yes = 1; int uw_port = 8080, nthreads = 1, i, *names, opt; - + + signal(SIGINT, sigint); + while ((opt = getopt(argc, argv, "hp:t:")) != -1) { switch (opt) { case '?': diff -r 7ef4b2911b09 -r 8875ff2e85dc src/compiler.sig --- a/src/compiler.sig Thu Nov 20 11:34:36 2008 -0500 +++ b/src/compiler.sig Thu Nov 20 12:16:30 2008 -0500 @@ -35,10 +35,11 @@ sources : string list, exe : string, sql : string option, - debug : bool + debug : bool, + profile : bool } val compile : string -> unit - val compileC : {cname : string, oname : string, ename : string, libs : string} -> unit + val compileC : {cname : string, oname : string, ename : string, libs : string, profile : bool} -> unit type ('src, 'dst) phase type ('src, 'dst) transform diff -r 7ef4b2911b09 -r 8875ff2e85dc src/compiler.sml --- a/src/compiler.sml Thu Nov 20 11:34:36 2008 -0500 +++ b/src/compiler.sml Thu Nov 20 12:16:30 2008 -0500 @@ -41,7 +41,8 @@ sources : string list, exe : string, sql : string option, - debug : bool + debug : bool, + profile : bool } type ('src, 'dst) phase = { @@ -199,7 +200,7 @@ handle LrParser.ParseError => [], print = SourcePrint.p_file} -fun p_job {prefix, database, exe, sql, sources, debug} = +fun p_job {prefix, database, exe, sql, sources, debug, profile} = let open Print.PD open Print @@ -208,6 +209,10 @@ box [string "DEBUG", newline] else box [], + if profile then + box [string "PROFILE", newline] + else + box [], case database of NONE => string "No database." | SOME db => string ("Database: " ^ db), @@ -260,19 +265,20 @@ readSources acc end - fun finish (prefix, database, exe, sql, debug, sources) = + fun finish (prefix, database, exe, sql, debug, profile, sources) = {prefix = Option.getOpt (prefix, "/"), database = database, exe = Option.getOpt (exe, OS.Path.joinBaseExt {base = OS.Path.base filename, ext = SOME "exe"}), sql = sql, debug = debug, + profile = profile, sources = sources} - fun read (prefix, database, exe, sql, debug) = + fun read (prefix, database, exe, sql, debug, profile) = case TextIO.inputLine inf of - NONE => finish (prefix, database, exe, sql, debug, []) - | SOME "\n" => finish (prefix, database, exe, sql, debug, readSources []) + NONE => finish (prefix, database, exe, sql, debug, profile, []) + | SOME "\n" => finish (prefix, database, exe, sql, debug, profile, readSources []) | SOME line => let val (cmd, arg) = Substring.splitl (fn x => not (Char.isSpace x)) (Substring.full line) @@ -284,28 +290,29 @@ (case prefix of NONE => () | SOME _ => ErrorMsg.error "Duplicate 'prefix' directive"; - read (SOME arg, database, exe, sql, debug)) + read (SOME arg, database, exe, sql, debug, profile)) | "database" => (case database of NONE => () | SOME _ => ErrorMsg.error "Duplicate 'database' directive"; - read (prefix, SOME arg, exe, sql, debug)) + read (prefix, SOME arg, exe, sql, debug, profile)) | "exe" => (case exe of NONE => () | SOME _ => ErrorMsg.error "Duplicate 'exe' directive"; - read (prefix, database, SOME (relify arg), sql, debug)) + read (prefix, database, SOME (relify arg), sql, debug, profile)) | "sql" => (case sql of NONE => () | SOME _ => ErrorMsg.error "Duplicate 'sql' directive"; - read (prefix, database, exe, SOME (relify arg), debug)) - | "debug" => read (prefix, database, exe, sql, true) + read (prefix, database, exe, SOME (relify arg), debug, profile)) + | "debug" => read (prefix, database, exe, sql, true, profile) + | "profile" => read (prefix, database, exe, sql, debug, true) | _ => (ErrorMsg.error ("Unrecognized command '" ^ cmd ^ "'"); - read (prefix, database, exe, sql, debug)) + read (prefix, database, exe, sql, debug, profile)) end - val job = read (NONE, NONE, NONE, NONE, false) + val job = read (NONE, NONE, NONE, NONE, false, false) in TextIO.closeIn inf; Monoize.urlPrefix := #prefix job; @@ -544,13 +551,19 @@ val toSqlify = transform sqlify "sqlify" o toMono_opt2 -fun compileC {cname, oname, ename, libs} = +fun compileC {cname, oname, ename, libs, profile} = let val urweb_o = clibFile "urweb.o" val driver_o = clibFile "driver.o" val compile = "gcc " ^ Config.gccArgs ^ " -Wstrict-prototypes -Werror -O3 -I include -c " ^ cname ^ " -o " ^ oname val link = "gcc -Werror -O3 -lm -pthread " ^ libs ^ " " ^ urweb_o ^ " " ^ oname ^ " " ^ driver_o ^ " -o " ^ ename + + val (compile, link) = + if profile then + (compile ^ " -pg", link ^ " -pg") + else + (compile, link) in if not (OS.Process.isSuccess (OS.Process.system compile)) then print "C compilation failed\n" @@ -615,7 +628,7 @@ TextIO.closeOut outf end; - compileC {cname = cname, oname = oname, ename = ename, libs = libs}; + compileC {cname = cname, oname = oname, ename = ename, libs = libs, profile = #profile job}; cleanup () end diff -r 7ef4b2911b09 -r 8875ff2e85dc src/demo.sml --- a/src/demo.sml Thu Nov 20 11:34:36 2008 -0500 +++ b/src/demo.sml Thu Nov 20 12:16:30 2008 -0500 @@ -92,7 +92,8 @@ file = "demo.exe"}, sql = SOME (OS.Path.joinDirFile {dir = dirname, file = "demo.sql"}), - debug = false + debug = false, + profile = false } val parse = Compiler.run (Compiler.transform Compiler.parseUrp "Demo parseUrp")