aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/stream_executor/lib/process_state.cc
blob: c20493b263673ffbf8ba332bcc21a3019134c7dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "tensorflow/stream_executor/lib/process_state.h"

#include <unistd.h>

#include <memory>

namespace perftools {
namespace gputools {
namespace port {

string Hostname() {
  char hostname[1024];
  gethostname(hostname, sizeof hostname);
  hostname[sizeof hostname - 1] = 0;
  return hostname;
}

bool GetCurrentDirectory(string* dir) {
  size_t len = 128;
  std::unique_ptr<char[]> a(new char[len]);
  for (;;) {
    char* p = getcwd(a.get(), len);
    if (p != NULL) {
      *dir = p;
      return true;
    } else if (errno == ERANGE) {
      len += len;
      a.reset(new char[len]);
    } else {
      return false;
    }
  }
}

}  // namespace port
}  // namespace gputools
}  // namespace perftools