1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #include "tensorflow/core/platform/tracing.h"
17
18 #include <stdlib.h>
19
20 #ifndef PLATFORM_WINDOWS
21 #include <unistd.h>
22 #endif
23
24 namespace tensorflow {
25 namespace tracing {
26 namespace {
TryGetEnv(const char * name,const char ** value)27 bool TryGetEnv(const char* name, const char** value) {
28 *value = getenv(name);
29 return *value != nullptr && (*value)[0] != '\0';
30 }
31 } // namespace
32
SetCurrentThreadName(const char *)33 void EventCollector::SetCurrentThreadName(const char*) {}
34
GetLogDir()35 const char* GetLogDir() {
36 const char* dir;
37 if (TryGetEnv("TEST_TMPDIR", &dir)) return dir;
38 if (TryGetEnv("TMP", &dir)) return dir;
39 if (TryGetEnv("TMPDIR", &dir)) return dir;
40 #ifndef PLATFORM_WINDOWS
41 dir = "/tmp";
42 if (access(dir, R_OK | W_OK | X_OK) == 0) return dir;
43 #endif
44 return "."; // Default to current directory.
45 }
46 } // namespace tracing
47 } // namespace tensorflow
48