Пример #1
0
// Simulate
static void bench_pending(void) {
  // These parameters give us 262140 items to track
  const size_t tree_depth = 7;
  const size_t num_files_per_dir = 8;
  const size_t num_dirs_per_dir = 4;
  w_string_t *root_name = w_string_new("/some/path");
  struct pending_list list;
  const size_t alloc_size = 280000;
  struct timeval start, end;

  list.pending = calloc(alloc_size, sizeof(struct watchman_pending_fs));
  list.avail = list.pending;
  list.end = list.pending + alloc_size;

  // Build a list ordered from the root (top) down to the leaves.
  build_list(&list, root_name, tree_depth, num_files_per_dir, num_dirs_per_dir);
  diag("built list with %u items", list.avail - list.pending);

  // Benchmark insertion in top-down order.
  {
    struct watchman_pending_collection coll;
    struct watchman_pending_fs *item;
    size_t drained = 0;

    w_pending_coll_init(&coll);

    gettimeofday(&start, NULL);
    for (item = list.pending; item < list.avail; item++) {
      w_pending_coll_add(&coll, item->path, item->now, item->flags);
    }
    drained = process_items(&coll);

    gettimeofday(&end, NULL);
    diag("took %.3fs to insert %u items into pending coll",
         w_timeval_diff(start, end), drained);
  }

  // and now in reverse order; this is from the leaves of the filesystem
  // tree up to the root, or bottom-up.  This simulates the workload of
  // a recursive delete of a filesystem tree.
  {
    struct watchman_pending_collection coll;
    struct watchman_pending_fs *item;
    size_t drained = 0;

    w_pending_coll_init(&coll);

    gettimeofday(&start, NULL);
    for (item = list.avail - 1; item >= list.pending; item--) {
      w_pending_coll_add(&coll, item->path, item->now, item->flags);
    }

    drained = process_items(&coll);

    gettimeofday(&end, NULL);
    diag("took %.3fs to reverse insert %u items into pending coll",
         w_timeval_diff(start, end), drained);
  }
}
Пример #2
0
bool w_perf_finish(w_perf_t *perf) {
  gettimeofday(&perf->time_end, NULL);
  w_timeval_sub(perf->time_end, perf->time_begin, &perf->duration);
#ifdef HAVE_SYS_RESOURCE_H
  getrusage(RUSAGE_SELF, &perf->usage_end);

  // Compute the delta for the usage
  w_timeval_sub(perf->usage_end.ru_utime, perf->usage_begin.ru_utime,
                &perf->usage.ru_utime);
  w_timeval_sub(perf->usage_end.ru_stime, perf->usage_begin.ru_stime,
                &perf->usage.ru_stime);

#define DIFFU(n) perf->usage.n = perf->usage_end.n - perf->usage_begin.n
  DIFFU(ru_maxrss);
  DIFFU(ru_ixrss);
  DIFFU(ru_idrss);
  DIFFU(ru_minflt);
  DIFFU(ru_majflt);
  DIFFU(ru_nswap);
  DIFFU(ru_inblock);
  DIFFU(ru_oublock);
  DIFFU(ru_msgsnd);
  DIFFU(ru_msgrcv);
  DIFFU(ru_nsignals);
  DIFFU(ru_nvcsw);
  DIFFU(ru_nivcsw);
#undef DIFFU
#endif

  if (!perf->will_log) {
    if (perf->wall_time_elapsed_thresh == 0) {
      json_t *thresh = cfg_get_json(NULL, "perf_sampling_thresh");
      if (thresh) {
        if (json_is_number(thresh)) {
          perf->wall_time_elapsed_thresh = json_number_value(thresh);
        } else {
          json_unpack(thresh, "{s:f}", perf->description,
                    &perf->wall_time_elapsed_thresh);
        }
      }
    }

    if (perf->wall_time_elapsed_thresh > 0 &&
        w_timeval_diff(perf->time_begin, perf->time_end) >
            perf->wall_time_elapsed_thresh) {
      perf->will_log = true;
    }
  }

  return perf->will_log;
}
Пример #3
0
bool watchman_perf_sample::finish() {
  gettimeofday(&time_end, nullptr);
  w_timeval_sub(time_end, time_begin, &duration);
#ifdef HAVE_SYS_RESOURCE_H
  getrusage(RUSAGE_SELF, &usage_end);

  // Compute the delta for the usage
  w_timeval_sub(usage_end.ru_utime, usage_begin.ru_utime, &usage.ru_utime);
  w_timeval_sub(usage_end.ru_stime, usage_begin.ru_stime, &usage.ru_stime);

#define DIFFU(n) usage.n = usage_end.n - usage_begin.n
  DIFFU(ru_maxrss);
  DIFFU(ru_ixrss);
  DIFFU(ru_idrss);
  DIFFU(ru_minflt);
  DIFFU(ru_majflt);
  DIFFU(ru_nswap);
  DIFFU(ru_inblock);
  DIFFU(ru_oublock);
  DIFFU(ru_msgsnd);
  DIFFU(ru_msgrcv);
  DIFFU(ru_nsignals);
  DIFFU(ru_nvcsw);
  DIFFU(ru_nivcsw);
#undef DIFFU
#endif

  if (!will_log) {
    if (wall_time_elapsed_thresh == 0) {
      auto thresh = cfg_get_json("perf_sampling_thresh");
      if (thresh) {
        if (json_is_number(thresh)) {
          wall_time_elapsed_thresh = json_number_value(thresh);
        } else {
          json_unpack(thresh, "{s:f}", description, &wall_time_elapsed_thresh);
        }
      }
    }

    if (wall_time_elapsed_thresh > 0 &&
        w_timeval_diff(time_begin, time_end) > wall_time_elapsed_thresh) {
      will_log = true;
    }
  }

  return will_log;
}
Пример #4
0
void bench_list(const char* label, const char* prefix) {
  struct watchman_ignore state;
  size_t i, n;
  struct timeval start, end;

  init_state(&state);
  auto strings = build_list_with_prefix(prefix, kWordLimit);

  gettimeofday(&start, NULL);
  for (n = 0; n < 100; n++) {
    for (i = 0; i < kWordLimit; i++) {
      state.isIgnored(strings[i].data(), strings[i].size());
    }
  }
  gettimeofday(&end, NULL);

  diag("%s: took %.3fs", label, w_timeval_diff(start, end));
}