LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
StatusLogger.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#ifdef WIN32
7#define _WINSOCKAPI_
8#endif
9
10
11/***************************************************************************
12 * Copyright (C) 2004-2012 by CEA LIST *
13 * *
14 ***************************************************************************/
15#include "StatusLogger.h"
16#include "LinguisticMetaData.h"
18
25
26using namespace std;
28
29namespace Lima
30{
31
32namespace LinguisticProcessing
33{
34
36
39
40
44
45
48 Manager*)
49
50{
51 ostringstream os;
52 os << "/proc/";
53#ifndef WIN32
54 os << getpid();
55#endif
56 os << "/status";
57 m_statusFile=os.str();
58 std::string outputFile;
59 try
60 {
61 outputFile=unitConfiguration.getParamsValueAtKey("outputFile");
62 }
63 catch (NoSuchParam& )
64 {
65 outputFile=string("status.log");
66 }
67 m_out = std::unique_ptr< std::ofstream >(new ofstream(outputFile.c_str(), std::ofstream::binary));
68 try
69 {
70 deque<string> tolog=unitConfiguration.getListsValueAtKey("toLog");
71 m_toLog.insert(tolog.begin(),tolog.end());
72 }
73 catch (NoSuchList& )
74 {
75 m_toLog.insert(string("VmSize"));
76 }
77 m_predTime=TimeUtils::getCurrentTime();
78}
79
80
82 AnalysisContent& analysis) const
83{
85 uint64_t tmp=TimeUtils::getCurrentTime();
86 // log time
87 *m_out << TimeUtils::diffTime(m_predTime,tmp) << " ";
88 const_cast<StatusLogger*>(this)->m_predTime=tmp;
89
90 // log file and document name
91 auto metadata = std::dynamic_pointer_cast<LinguisticMetaData>(analysis.getData("LinguisticMetaData"));
92
93 try
94 {
95 const string& filename=metadata->getMetaData("FileName");
96 *m_out << filename << " ";
97 }
99 try
100 {
101 string doc=metadata->getMetaData("DocumentName");
102 *m_out << doc << " ";
103 }
105
106 ifstream statusIn(m_statusFile.c_str(),ios::in | std::ifstream::binary);
107 string line;
108 while (statusIn.good())
109 {
110 line = Lima::Common::Misc::readLine(statusIn);
111 size_t index=line.find(":");
112 string key=line.substr(0,index);
113 if (m_toLog.find(key)!=m_toLog.end())
114 {
115 *m_out << line << " ";
116 }
117 }
118
119 LimaStringText* originalText=static_cast<LimaStringText*>(analysis.getData("Text").get());
120 *m_out << "TextSize= " << originalText->size() << endl;
121 TimeUtils::logElapsedTime("StatusLogger");
122 return SUCCESS_ID;
123}
124
125}
126
127}
Defines a Factory to create Object of type Base.
#define STATUSLOGGER_CLASSID
Holds all data that pass through the ProcessUnits Analysis data are shared pointers,...
std::shared_ptr< AnalysisData > getData(const QString &id)
return AnalysisData by id
std::deque< std::string > & getListsValueAtKey(const std::string &key)
return a message when a 'param' was not found
Manage initialization of InitializableObjects using configuration module and parameters.
define the limaStringText resource which is the text in limaString formal
virtual void init(Common::XMLConfigurationFiles::GroupConfigurationStructure &unitConfiguration, Manager *manager) override
initialize with parameters from configuration file.
virtual LimaStatusCode process(AnalysisContent &analysis) const override
Process on data in analysisContent.
static uint64_t diffTime(const uint64_t &begin, const uint64_t &end)
return the difference between two times in microseconds
static void logElapsedTime(const std::string &mess, const std::string &taskCategory=std::string(""))
log the number of microseconds since last UpdateCurrentTime
static void updateCurrentTime(const std::string &taskCategory=std::string(""))
store current time for new elapsed time computation
static uint64_t getCurrentTime()
get the current time (real current time, not last time stored)
std::string readLine(std::istream &inputFile)
SimpleFactory< MediaProcessUnit, StatusLogger > statusLoggerFactory(STATUSLOGGER_CLASSID)
NAUTITIA.
LimaStatusCode
Definition LimaCommon.h:236
@ SUCCESS_ID
Definition LimaCommon.h:237
STL namespace.
launch exception related to the configuration file parsing