FileLoggingStrategy.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore::core::services::profiler
19  * @author Manfred Kroehnert ( manfred dot kroehnert at dot kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "FileLoggingStrategy.h"
26 
27 #include <fstream>
28 #include <sstream>
29 
30 namespace
31 {
32  const std::string SEPARATOR = "|";
33 }
34 
35 void
37  uint64_t timestamp,
38  const std::string& executableName,
39  const std::string& timestampUnit,
40  const std::string& eventName,
41  const std::string& parentName,
42  const std::string& functionName)
43 {
44  std::ostringstream logstring;
45  logstring << processId << SEPARATOR << timestamp << SEPARATOR << timestampUnit << SEPARATOR
46  << eventName << SEPARATOR << parentName << SEPARATOR << functionName << SEPARATOR;
47 
48  mutex.lock();
49  eventList.push_back(logstring.str());
50  mutex.unlock();
51 }
52 
53 void
54 armarx::Profiler::FileLoggingStrategy::writeFile()
55 {
56  std::ofstream outputFile((id + ".trace").c_str());
57  writeHeader(outputFile);
58 
59  for (std::string logline : eventList)
60  {
61  outputFile << logline << std::endl;
62  }
63 
64  outputFile.close();
65 }
66 
67 void
68 armarx::Profiler::FileLoggingStrategy::writeHeader(std::ostream& outputStream)
69 {
70  outputStream << "ProcessID" << SEPARATOR << "Timestamp" << SEPARATOR << "TimestampUnit"
71  << SEPARATOR << "EventType" << SEPARATOR << "Parent" << SEPARATOR << "Function"
72  << SEPARATOR << std::endl;
73 }
74 
76 {
77 }
78 
80 {
81  writeFile();
82 }
armarx::Profiler::FileLoggingStrategy::~FileLoggingStrategy
~FileLoggingStrategy() override
Definition: FileLoggingStrategy.cpp:79
armarx::Profiler::FileLoggingStrategy::FileLoggingStrategy
FileLoggingStrategy()
Definition: FileLoggingStrategy.cpp:75
armarx::Profiler::FileLoggingStrategy::logEvent
void logEvent(pid_t processId, uint64_t timestamp, const std::string &executableName, const std::string &timestampUnit, const std::string &eventName, const std::string &parentName, const std::string &functionName) override
Definition: FileLoggingStrategy.cpp:36
FileLoggingStrategy.h