int main(int argc, char** argv) { char **compiler_args = NULL; char *compiler_name; int pid; struct timespec start, end; int stat; FILE *log; compiler_name = (char*)find_basename(argv[0]); copy_argv(argv, &compiler_args, 0); free(compiler_args[0]); compiler_args[0] = strdup(compiler_name); clock_gettime(CLOCK_MONOTONIC, &start); pid = fork(); setenv("PATH", "/usr/bin", 1); if (pid == 0) return execvp(compiler_name, compiler_args); waitpid(pid, &stat, 0); clock_gettime(CLOCK_MONOTONIC, &end); int i; long long int diff = 0; diff = (end.tv_sec*1000000000+end.tv_nsec) - (start.tv_sec*1000000000+start.tv_nsec); log = fopen("/tmp/profile.out", "a+"); fseek(log, 0, SEEK_END); for(i = 0;i<argc-1;i++) { fprintf(log, "%s ", argv[i]); } fprintf(log, "%s: ", argv[i]); fprintf(log, "%lld nsec\n", diff); fclose(log); }
static int find_command(int pid_argc, const char *const *pid_argv, const char *cmd) { const char *base, *stop_opt; base = pid_argv[0]; if (*base == '-') base++; /* skip indicator of login shells */ base = find_basename(base); if (!strcmp(base, cmd)) { /* * argv[0] matches the supplied command name. */ return 0; } else if (is_an_interpreter(base, &stop_opt)) { /* * argv[0] is an interpreter program of some kind. Look * along its command line for the program it's running, * and see if _that_ matches the command name. */ int i = 1; while (i < pid_argc && pid_argv[i][0] == '-') { /* * Skip interpreter options, unless they're things which * make the next non-option argument not a script name * (e.g. sh -c, perl -e). */ if (stop_opt && !strncmp(pid_argv[i], stop_opt, strlen(stop_opt))) return -1; /* no match */ i++; } if (i < pid_argc && !strcmp(find_basename(pid_argv[i]), cmd)) return i; } return -1; /* no match */ }
td_file * td_engine_get_file(td_engine *engine, const char *input_path, td_get_file_mode mode) { unsigned int hash; int slot; td_file *chain; td_file *f; int path_len; char path[1024]; const char *out_path; size_t input_path_len = strlen(input_path); if (input_path_len >= sizeof(path)) td_croak("path too long: %s", input_path); if (TD_COPY_STRING == mode) { if (isabspath(input_path)) { strcpy(path, input_path); } else { snprintf(path, sizeof path, "%s%s", cwd, input_path); } sanitize_path(path, sizeof(path), input_path_len); hash = (unsigned int) djb2_hash(path); out_path = path; } else { hash = (unsigned int) djb2_hash(input_path); out_path = input_path; } td_mutex_lock_or_die(engine->lock); slot = (int) (hash % engine->file_hash_size); chain = engine->file_hash[slot]; while (chain) { if (chain->hash == hash && 0 == strcmp(out_path, chain->path)) { td_mutex_unlock_or_die(engine->lock); return chain; } chain = chain->bucket_next; } ++engine->stats.file_count; f = td_page_alloc(&engine->alloc, sizeof(td_file)); memset(f, 0, sizeof(td_file)); f->path_len = path_len = (int) strlen(out_path); if (TD_COPY_STRING == mode) f->path = td_page_strdup(&engine->alloc, out_path, path_len); else f->path = out_path; f->hash = hash; f->name = find_basename(f->path, path_len); f->bucket_next = engine->file_hash[slot]; f->signer = engine->default_signer; f->stat_dirty = 1; f->signature_dirty = 1; f->frozen_relstring_index = ~(0u); engine->file_hash[slot] = f; td_mutex_unlock_or_die(engine->lock); return f; }