This is an archive of the discontinued LLVM Phabricator instance.

[PGO] Delay directory creation until write time
ClosedPublic

Authored by davidxl on Feb 14 2017, 12:41 PM.

Details

Summary

Some process starts as root but drops the privileges later. Profile runtime currently eagerly creates profile file directory on program start up. This can cause problems later when profiling APIs (such as set filename, cleanup dir etc) are used to do profile dumping when the process privilege is dropped -- the directory can not be cleaned up before/after profile dumping.

In this patch, the dir creation is delayed until profile writing time when merge mode is on. No other external behavior changes should be expected.

Diff Detail

Repository
rL LLVM

Event Timeline

davidxl created this revision.Feb 14 2017, 12:41 PM
vsk edited edge metadata.EditedFeb 14 2017, 12:51 PM

Makes sense, I was thinking of something like this for a test;

// RUN: %clang_profgen -o %t %s
// RUN: env LLVM_PROFILE_FILE="%t.d/%m.profraw"
// RUN: %run %t %t.d

#include <unistd.h>

int main(int argc, char **argv) {
  if (access(argv[1], F_OK) == 0)
    return 1; // %t.d should not exist yet.
  return errno == ENOENT;
}

Edit: you'd probably have to make sure %t.d doesn't exist before running the test.

xur edited edge metadata.Feb 14 2017, 1:04 PM

why limit to merge mode?
non-merge mode also exhibits the problem mentioned.

davidxl updated this revision to Diff 88427.Feb 14 2017, 1:26 PM

Added test case suggested by Vedant.

vsk accepted this revision.Feb 14 2017, 1:28 PM

Thanks, LGTM.

This revision is now accepted and ready to land.Feb 14 2017, 1:28 PM
xur accepted this revision.Feb 14 2017, 1:40 PM

LGTM too.

This revision was automatically updated to reflect the committed changes.