timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::filepath Namespace Reference

Functions

int makedir (std::string _dir, int umask=0777)
 
std::string & replace (std::string &_path, char _c, const char *_v)
 
std::string & replace (std::string &_path, const char *_c, const char *_v)
 
std::string canonical (std::string _path)
 
template<typename... Args>
bool open (std::ofstream &_ofs, std::string _fpath, Args &&... _args)
 

Function Documentation

◆ canonical()

std::string tim::filepath::canonical ( std::string  _path)
inline

Definition at line 134 of file filepath.hpp.

135{
136 replace(_path, '\\', "/");
137 replace(_path, "//", "/");
138 return _path;
139}
std::string & replace(std::string &_path, const char *_c, const char *_v)
Definition: filepath.hpp:75

References replace().

Referenced by tim::utility::path::canonical(), and open().

◆ makedir()

int tim::filepath::makedir ( std::string  _dir,
int  umask = 0777 
)
inline

Definition at line 142 of file filepath.hpp.

143{
144#if defined(TIMEMORY_UNIX)
145 while(_dir.find("\\\\") != std::string::npos)
146 _dir.replace(_dir.find("\\\\"), 2, "/");
147 while(_dir.find('\\') != std::string::npos)
148 _dir.replace(_dir.find('\\'), 1, "/");
149
150 if(_dir.length() == 0)
151 return 0;
152
153 int ret = mkdir(_dir.c_str(), umask);
154 if(ret != 0)
155 {
156 int err = errno;
157 if(err != EEXIST)
158 {
159 std::stringstream _mdir{};
160 _mdir << "mkdir(" << _dir.c_str() << ", " << umask << ") returned: " << ret
161 << "\n";
162 std::stringstream _sdir{};
163 _sdir << "/bin/mkdir -p " << _dir;
164 ret = (launch_process(_sdir.str().c_str())) ? 0 : 1;
165 if(ret != 0)
166 {
167 std::cerr << _mdir.str() << _sdir.str() << " returned: " << ret
168 << std::endl;
169 }
170 return ret;
171 }
172 }
173#elif defined(TIMEMORY_WINDOWS)
174 consume_parameters(umask);
175 while(_dir.find('/') != std::string::npos)
176 _dir.replace(_dir.find('/'), 1, "\\");
177
178 if(_dir.length() == 0)
179 return 0;
180
181 int ret = _mkdir(_dir.c_str());
182 if(ret != 0)
183 {
184 int err = errno;
185 if(err != EEXIST)
186 {
187 std::stringstream _mdir{};
188 _mdir << "_mkdir(" << _dir.c_str() << ") returned: " << ret << "\n";
189 std::stringstream _sdir{};
190 _sdir << "mkdir " << _dir;
191 ret = (launch_process(_sdir.str().c_str())) ? 0 : 1;
192 if(ret != 0)
193 {
194 std::cerr << _mdir.str() << _sdir.str() << " returned: " << ret
195 << std::endl;
196 }
197 return ret;
198 }
199 }
200#endif
201 return 0;
202}
const string_t const string_t & _dir
Definition: definition.hpp:52
bool launch_process(const char *cmd, const std::string &extra="", std::ostream *os=nullptr)
void consume_parameters(ArgsT &&...)
Definition: types.hpp:285

References tim::plotting::_dir, tim::consume_parameters(), and tim::launch_process().

Referenced by tim::makedir(), and open().

◆ open()

template<typename... Args>
bool tim::filepath::open ( std::ofstream &  _ofs,
std::string  _fpath,
Args &&...  _args 
)
inline

Definition at line 207 of file filepath.hpp.

208{
209 auto _path = canonical(_fpath);
210 auto _base = canonical(_fpath);
211 auto _pos = _path.find_last_of('/');
212 if(_pos != std::string::npos)
213 {
214 _path = _path.substr(0, _pos);
215 _base = _base.substr(_pos + 1);
216 }
217
218 if(!_path.empty())
219 {
220 auto ret = makedir(osrepr(_path));
221 if(ret != 0)
222 _fpath = std::string{ "./" } + _base;
223 }
224
225 _ofs.open(osrepr(_fpath), std::forward<Args>(_args)...);
226 return (_ofs && _ofs.is_open() && _ofs.good());
227}
int makedir(std::string _dir, int umask=0777)
Definition: filepath.hpp:142
std::string canonical(std::string _path)
Definition: filepath.hpp:134
std::array< char *, 4 > _args
tim::mpl::apply< std::string > string
Definition: macros.hpp:53

References tim::_args, canonical(), and makedir().

Referenced by tim::operation::finalize::flamegraph< Type >::flamegraph(), tim::operation::finalize::ctest_notes_deleter::operator()(), tim::operation::finalize::print< Tp, true >::print_json(), tim::operation::finalize::print< Tp, true >::print_tree(), and tim::ert::serialize().

◆ replace() [1/2]

std::string & tim::filepath::replace ( std::string &  _path,
char  _c,
const char *  _v 
)
inline

Definition at line 66 of file filepath.hpp.

67{
68 auto _pos = std::string::npos;
69 while((_pos = _path.find(_c)) != std::string::npos)
70 _path.replace(_pos, 1, _v);
71 return _path;
72}

Referenced by canonical(), tim::operation::echo_measurement< Tp, true >::generate_name(), tim::operation::echo_measurement< Tp, true >::generate_prefix(), and tim::utility::path::osrepr().

◆ replace() [2/2]

std::string & tim::filepath::replace ( std::string &  _path,
const char *  _c,
const char *  _v 
)
inline

Definition at line 75 of file filepath.hpp.

76{
77 auto _pos = std::string::npos;
78 while((_pos = _path.find(_c)) != std::string::npos)
79 _path.replace(_pos, strlen(_c), _v);
80 return _path;
81}