Version: 9.15.0
YacsTrace.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #include <iostream>
21 #include <sstream>
22 #include "YacsTrace.hxx"
23 #include <cstdlib>
24 
25 #include <chrono>
26 #include <iomanip>
27 #include <ctime>
28 
29 #ifdef WIN32
30 #include <process.h>
31 #define getpid _getpid
32 #else
33 #include <unistd.h>
34 #endif
35 
36 namespace YACS {
37  int traceLevel = 0;
38 }
39 
40 void YACS::AppendTimeClock(std::ostream& os)
41 {
42  auto now = std::chrono::system_clock::now();
43  auto duration = now.time_since_epoch();
44  auto timestamp = std::chrono::system_clock::to_time_t(now);
45  std::tm *local_time = std::localtime(&timestamp);
46  auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
47  os << std::setfill('0') << std::setw(2) << local_time->tm_hour << ":"
48  << std::setw(2) << local_time->tm_min << ":"
49  << std::setw(2) << local_time->tm_sec << "." << std::setw(3) << millis % 1000 << " - ";
50 }
51 
53 {
54  if(getenv ("YACSDEBUGGER"))
55  {
56  std::stringstream exec;
57  exec << "$YACSDEBUGGER " << getpid() << "&";
58  std::cerr << exec.str() << std::endl;
59  system(exec.str().c_str());
60  while(1);
61  }
62 }
void AttachDebugger()
Definition: YacsTrace.cxx:52
void AppendTimeClock(std::ostream &os)
Definition: YacsTrace.cxx:40
int traceLevel
Definition: YacsTrace.cxx:37