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 <sstream>
28 #include <fstream>
29 
30 namespace
31 {
32  const std::string SEPARATOR = "|";
33 }
34 
35 void armarx::Profiler::FileLoggingStrategy::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)
36 {
37  std::ostringstream logstring;
38  logstring << processId << SEPARATOR
39  << timestamp << SEPARATOR
40  << timestampUnit << SEPARATOR
41  << eventName << SEPARATOR
42  << parentName << SEPARATOR
43  << functionName << SEPARATOR;
44 
45  mutex.lock();
46  eventList.push_back(logstring.str());
47  mutex.unlock();
48 }
49 
50 
51 void armarx::Profiler::FileLoggingStrategy::writeFile()
52 {
53  std::ofstream outputFile((id + ".trace").c_str());
54  writeHeader(outputFile);
55 
56  for (std::string logline : eventList)
57  {
58  outputFile << logline << std::endl;
59  }
60 
61  outputFile.close();
62 }
63 
64 
65 void armarx::Profiler::FileLoggingStrategy::writeHeader(std::ostream& outputStream)
66 {
67  outputStream
68  << "ProcessID" << SEPARATOR
69  << "Timestamp" << SEPARATOR
70  << "TimestampUnit" << SEPARATOR
71  << "EventType" << SEPARATOR
72  << "Parent" << SEPARATOR
73  << "Function" << SEPARATOR << std::endl;
74 }
75 
76 
77 
79 {
80 }
81 
83 {
84  writeFile();
85 }
armarx::Profiler::FileLoggingStrategy::~FileLoggingStrategy
~FileLoggingStrategy() override
Definition: FileLoggingStrategy.cpp:82
armarx::Profiler::FileLoggingStrategy::FileLoggingStrategy
FileLoggingStrategy()
Definition: FileLoggingStrategy.cpp:78
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:35
FileLoggingStrategy.h