14#include "arcane/impl/InternalInfosDumper.h"
16#include "arcane/utils/String.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/FatalErrorException.h"
19#include "arcane/utils/ITraceMng.h"
20#include "arcane/utils/ScopedPtr.h"
21#include "arcane/utils/ApplicationInfo.h"
22#include "arcane/utils/JSONWriter.h"
23#include "arcane/utils/FileContent.h"
26#include "arcane/core/IParallelMng.h"
27#include "arcane/core/Directory.h"
28#include "arcane/core/ServiceFinder2.h"
29#include "arcane/core/IApplication.h"
30#include "arcane/core/ICodeService.h"
31#include "arcane/core/SubDomainBuildInfo.h"
32#include "arcane/core/IServiceLoader.h"
33#include "arcane/core/IParallelSuperMng.h"
34#include "arcane/core/IMainFactory.h"
35#include "arcane/core/ISession.h"
36#include "arcane/core/ISubDomain.h"
37#include "arcane/core/ITimeLoopMng.h"
38#include "arcane/core/IVariableMng.h"
39#include "arcane/core/IXmlDocumentHolder.h"
40#include "arcane/core/XmlNodeList.h"
41#include "arcane/core/IModuleMng.h"
42#include "arcane/core/IModule.h"
43#include "arcane/core/VariableRef.h"
44#include "arcane/core/VariableCollection.h"
45#include "arcane/core/IIOMng.h"
46#include "arcane/core/ITimeLoop.h"
47#include "arcane/core/ICaseMng.h"
48#include "arcane/core/ICaseOptions.h"
49#include "arcane/core/IRessourceMng.h"
51#include "arcane/impl/TimeLoopReader.h"
70: m_application(application)
77Ref<ICodeService> InternalInfosDumper::
80 String code_name = platform::getEnvironmentVariable(
"STDENV_CODE_NAME");
82 ARCANE_FATAL(
"environment variable 'STDENV_CODE_NAME' is not defined");
84 IApplication* app = m_application;
85 ServiceFinder2T<ICodeService, IApplication> code_services_utils(app, app);
86 String full_code_name = code_name +
"Code";
87 Ref<ICodeService> code = code_services_utils.createReference(full_code_name);
92 if (code_name ==
"Arcane")
93 code = createArcaneCodeService(app);
96 ARCANE_FATAL(
"No code service named '{0}' found", full_code_name);
103void InternalInfosDumper::
106 ITraceMng* tr = m_application->traceMng();
107 IMainFactory* main_factory = m_application->mainFactory();
108 tr->info() <<
"Dumping internal infos to Arcane";
109 Ref<ICodeService> code_service = _getDefaultService();
110 ISession* session(code_service->createSession());
111 IParallelSuperMng* psm = m_application->parallelSuperMng();
112 Ref<IParallelMng> world_pm = psm->internalCreateWorldParallelMng(0);
113 SubDomainBuildInfo sdbi(world_pm, 0);
114 sdbi.setCaseFileName(String());
116 ISubDomain* sub_domain(session->createSubDomain(sdbi));
117 ScopedPtrT<IServiceLoader> service_loader(main_factory->createServiceLoader());
120 TimeLoopReader stl(m_application);
122 stl.registerTimeLoops(sub_domain);
125 service_loader->loadModules(sub_domain,
true);
128 UniqueArray<IServiceInfo*> service_infos;
130 std::set<IServiceInfo*> done_set;
131 for (ServiceFactory2Collection::Enumerator j(m_application->serviceFactories2()); ++j;) {
132 Internal::IServiceFactory2* sf2 = *j;
133 IServiceInfo* s = sf2->serviceInfo();
134 if (done_set.find(s) == done_set.end()) {
135 service_infos.add(s);
141 IModuleMng* module_mng = sub_domain->moduleMng();
142 IVariableMng* variable_mng = sub_domain->variableMng();
146 String us_name(
"name");
147 String us_ref(
"ref");
148 String us_datatype(
"datatype");
149 String us_dimension(
"dimension");
150 String us_kind(
"kind");
151 String us_root(
"root");
152 String us_modules(
"modules");
153 String us_module(
"module");
154 String us_services(
"services");
155 String us_service(
"service");
157 ScopedPtrT<IXmlDocumentHolder> doc_holder(m_application->ressourceMng()->createXmlDocument());
158 XmlNode doc_element = doc_holder->documentNode();
159 XmlNode root_element = doc_element.createAndAppendElement(us_root);
161 XmlNode modules = root_element.createAndAppendElement(us_modules);
163 for (ModuleCollection::Enumerator i(module_mng->modules()); ++i;) {
164 XmlNode module_element = modules.createAndAppendElement(us_module);
165 module_element.setAttrValue(us_name, String((*i)->name()));
166 var_ref_list.clear();
167 variable_mng->variables(var_ref_list, *i);
168 for (VariableRefList::Enumerator j(var_ref_list); ++j;) {
169 XmlNode variable_element = module_element.createAndAppendElement(
"variable-ref");
170 variable_element.setAttrValue(us_ref, String((*j)->name()));
174 XmlNode variables = root_element.createAndAppendElement(
"variables");
176 VariableCollection var_prv_list(variable_mng->variables());
177 for (VariableCollection::Enumerator j(var_prv_list); ++j;) {
179 String dim(String::fromNumber(var->dimension()));
180 XmlNode variable_element = variables.createAndAppendElement(
"variable");
181 variable_element.setAttrValue(us_name, var->name());
182 variable_element.setAttrValue(us_datatype,
dataTypeName(var->dataType()));
183 variable_element.setAttrValue(us_dimension, dim);
184 variable_element.setAttrValue(us_kind,
itemKindName(var->itemKind()));
188 ITimeLoopMng* tm = sub_domain->timeLoopMng();
190 tm->timeLoopsName(timeloop_name_list);
192 XmlNode timeloops = root_element.createAndAppendElement(
"timeloops");
193 for (StringCollection::Enumerator i(timeloop_name_list); ++i;) {
194 XmlNode timeloop_elem = timeloops.createAndAppendElement(
"timeloop");
195 timeloop_elem.setAttrValue(us_name, *i);
201 std::map<String, List<IServiceInfo*>> interfaces_to_service;
202 XmlNode services_elem = root_element.createAndAppendElement(us_services);
204 for (
int i = 0, n = service_infos.size(); i < n; ++i) {
205 IServiceInfo* service_info = service_infos[i];
206 XmlNode service_elem = services_elem.createAndAppendElement(us_service);
207 service_elem.setAttrValue(us_name, service_info->localName());
209 auto xml_file_base_name = service_info->caseOptionsFileName();
210 if (!xml_file_base_name.null()) {
211 service_elem.setAttrValue(
"file-base-name", xml_file_base_name);
214 for (StringCollection::Enumerator j(service_info->implementedInterfaces()); ++j;) {
215 XmlNode interface_elem = service_elem.createAndAppendElement(
"implement-class");
216 interface_elem.setAttrValue(us_name, *j);
217 interfaces_to_service[*j].add(service_info);
222 XmlNode classes_elem = services_elem.createAndAppendElement(
"services-class");
223 std::map<String, List<IServiceInfo*>>::const_iterator begin = interfaces_to_service.begin();
224 std::map<String, List<IServiceInfo*>>::const_iterator end = interfaces_to_service.end();
225 for (; begin != end; ++begin) {
226 XmlNode class_elem = classes_elem.createAndAppendElement(
"class");
227 class_elem.setAttrValue(us_name, begin->first);
228 for (List<IServiceInfo*>::Enumerator i(begin->second); ++i;) {
229 IServiceInfo* service_info = *i;
230 XmlNode service_elem = class_elem.createAndAppendElement(us_service);
231 service_elem.setAttrValue(us_name, service_info->localName());
233 auto xml_file_base_name = service_info->caseOptionsFileName();
234 if (!xml_file_base_name.null()) {
235 service_elem.setAttrValue(
"file-base-name", xml_file_base_name);
243 Directory shared_dir(m_application->applicationInfo().dataDir());
244 String filename = shared_dir.file(
"arcane_internal.xml");
245 cerr <<
"** FILE IS " << filename <<
'\n';
246 sub_domain->ioMng()->writeXmlFile(doc_holder.get(), filename);
252void InternalInfosDumper::
253dumpInternalAllInfos()
255 m_application->traceMng()->info() <<
"Dumping time loop information";
256 IMainFactory* main_factory = m_application->mainFactory();
259 ByteConstSpan config_bytes = m_application->configBuffer();
261 if (!config_doc.
get())
263 XmlNode elem = config_doc->documentNode().documentElement();
267 elem = elem.
child(
"Execution");
268 elem = elem.
child(
"BouclesTemps");
273 XmlNode doc_element = doc_holder->documentNode();
274 XmlNode root_element = doc_element.createAndAppendElement(
String(
"root"));
284 XmlNode elem2(root_element.createAndAppendElement(
"general"));
285 elem2.createAndAppendElement(
"codename",
String(app_info.
codeName()));
286 elem2.createAndAppendElement(
"codefullversion",
String(m_application->mainVersionStr()));
287 elem2.createAndAppendElement(
"codeversion",
String(m_application->majorAndMinorVersionStr()));
295 const String& timeloop_name = timeloop->
name();
300 session = code_service->createSession();
301 service_loader->loadSessionServices(session);
303 sdbi.setCaseFileName(
String());
318 XmlNode mng_element = root_element.createAndAppendElement(
"timeloop");
323 Directory shared_dir(m_application->applicationInfo().dataDir());
324 String filename = shared_dir.
file(
"arcane-caseinfos.xml");
325 cerr <<
"** FILE IS " << filename <<
'\n';
326 m_application->ioMng()->writeXmlFile(doc_holder.
get(), filename);
332void InternalInfosDumper::
340 json_writer.write(
"title", time_loop->
title());
341 json_writer.write(
"description", time_loop->
description());
345 json_writer.writeValue(*j);
349 String ustr_module(
"module");
350 String ustr_name(
"name");
351 String ustr_activated(
"activated");
352 String ustr_variable(
"variable");
353 String ustr_variable_ref(
"variable-ref");
354 String ustr_ref(
"ref");
355 String ustr_datatype(
"datatype");
356 String ustr_dimension(
"dimension");
357 String ustr_kind(
"kind");
358 String ustr_caseblock(
"caseblock");
359 String ustr_tagname(
"tagname");
365 JSONWriter::Array ja_modules(json_writer,
"modules");
367 JSONWriter::Object jo_module(json_writer);
368 json_writer.write(ustr_name, module->name());
369 json_writer.write(ustr_activated, module->used());
372 var_mng->variables(var_ref_list, module);
373 JSONWriter::Array ja_variables(json_writer,
"variables");
374 for (VariableRef* vr : var_ref_list)
375 json_writer.writeValue(vr->variable()->fullName());
381 VariableCollection var_prv_list = var_mng->variables();
382 JSONWriter::Array jo_variables(json_writer,
"variables");
383 for (VariableCollection::Enumerator j(var_prv_list); ++j;) {
385 JSONWriter::Object jo_variable(json_writer);
386 json_writer.write(ustr_name, var->fullName());
387 json_writer.write(ustr_datatype,
dataTypeName(var->dataType()));
388 json_writer.write(ustr_dimension, (Int64)var->dimension());
389 json_writer.write(ustr_kind,
itemKindName(var->itemKind()));
398 JSONWriter::Array ja_blocks(json_writer,
"caseblocks");
399 for (ICaseOptions* block : blocks) {
400 JSONWriter::Object jo_block(json_writer);
401 json_writer.write(ustr_tagname, block->rootTagName());
403 IModule* block_module = block->caseModule();
405 json_writer.write(ustr_module, block_module->name());
416void InternalInfosDumper::
421 IMainFactory* main_factory = m_application->mainFactory();
422 tr->
info() <<
"Generating Arcane Database";
424 ISession* session(code_service->createSession());
428 sdbi.setCaseFileName(
String());
433 ByteConstSpan config_bytes = m_application->configBuffer();
435 if (!config_doc.
get())
445 service_loader->loadModules(sub_domain,
true);
450 std::set<IServiceInfo*> done_set;
454 if (done_set.find(s) == done_set.end()) {
455 service_infos.
add(s);
466 String us_datatype(
"datatype");
467 String us_dimension(
"dimension");
470 String us_modules(
"modules");
471 String us_module(
"module");
472 String us_services(
"services");
473 String us_service(
"service");
476 XmlNode doc_element = doc_holder->documentNode();
477 XmlNode root_element = doc_element.createAndAppendElement(us_root);
479 JSONWriter json_writer(JSONWriter::FormatFlags::None);
480 json_writer.beginObject();
481 json_writer.write(
"version",
"1");
488 json_writer.write(us_name, module->name());
490 variable_mng->
variables(var_ref_list, module);
493 json_writer.writeValue((*j)->name());
502 for (VariableCollection::Enumerator j(var_prv_list); ++j;) {
506 json_writer.write(us_name, var->
name());
514 std::map<String, List<IServiceInfo*>> interfaces_to_service;
522 json_writer.write(us_name, service_info->localName());
523 json_writer.writeIfNotNull(
"file-base-name", service_info->caseOptionsFileName());
529 if (content_size > 0) {
530 Int64 block_size = 80;
531 Int64 nb_block = content_size / block_size;
532 if ((content_size % block_size) != 0)
536 for (
Integer k = 0; k < nb_block; ++k) {
537 auto z = content.
subSpan(index, block_size);
538 json_writer.writeValue(z);
545 JSONWriter::Array ja_implemented_interfaces(json_writer,
"implemented-interfaces");
547 interfaces_to_service[*j].add(service_info);
548 json_writer.writeValue(*j);
557 for (
const auto& x : interfaces_to_service) {
559 json_writer.write(us_name, x.first);
563 json_writer.write(us_name, service_info->
localName());
575 json_writer.write(
"codename", app_info.
codeName());
576 json_writer.write(
"codefullversion", m_application->mainVersionStr());
577 json_writer.write(
"codeversion", m_application->majorAndMinorVersionStr());
584 const String& timeloop_name = timeloop->
name();
587 json_writer.write(us_name, timeloop_name);
592 session = code_service->createSession();
593 service_loader->loadSessionServices(session);
595 sdbi.setCaseFileName(
String());
609 _dumpSubDomainInternalInfos(sd, json_writer);
614 json_writer.endObject();
618 Directory shared_dir(m_application->applicationInfo().dataDir());
619 String json_filename = shared_dir.
file(
"arcane_database.json");
620 cerr <<
"** FILE2 IS " << json_filename <<
'\n';
621 String buf(json_writer.getBuffer());
624 std::ofstream ofile(json_filename.
localstr());
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
File containing declarations concerning the message passing model.
const String & codeName() const
Returns the name of the calculation code linked to the application.
void add(ConstReferenceType val)
Adds element val to the end of the array.
EnumeratorT< ITimeLoop * > Enumerator
Class managing a directory.
String file(const String &file_name) const override
Returns the full path of the file file_name in the directory.
virtual IIOMng * ioMng()=0
Input/output manager.
virtual IParallelSuperMng * parallelSuperMng()=0
Supervisory parallelism manager.
virtual ITraceMng * traceMng() const =0
Trace manager.
virtual IXmlDocumentHolder * parseXmlBuffer(Span< const Byte > buffer, const String &name)=0
Reads and parses the XML file contained in the buffer buffer.
Factory for Arcane classes.
virtual IServiceLoader * createServiceLoader()=0
Creates an instance of the service loader.
Module manager interface.
virtual ModuleCollection modules() const =0
List of modules.
Abstract class of the parallelism supervisor.
virtual Ref< IParallelMng > internalCreateWorldParallelMng(Int32 local_rank)=0
Creates a parallelism manager for all allocated cores.
Interface for service or module information.
virtual String localName() const =0
Local part of the service name.
virtual const String & caseOptionsFileName() const =0
Name of the file containing the dataset (null if none).
Interface for a case execution session.
virtual ISubDomain * createSubDomain(const SubDomainBuildInfo &sdbi)=0
Creates a sub-domain with the parameters contained in sdbi.
Interface of the subdomain manager.
virtual IModuleMng * moduleMng()=0
Returns the module manager.
virtual void dumpInternalInfos(XmlNode &elem)=0
Dumps internal architecture information. The information is stored in an XML tree with root as the ro...
virtual ITimeLoopMng * timeLoopMng()=0
Returns the time loop manager.
virtual IVariableMng * variableMng()=0
Returns the variable manager.
virtual ICaseMng * caseMng()=0
Returns the dataset manager.
Interface for the time loop manager.
virtual ITimeLoop * usedTimeLoop() const =0
Returns the time loop used.
virtual void registerTimeLoop(ITimeLoop *time_loop)=0
Registration and selection of the time loop.
virtual void setUsedTimeLoop(const String &name)=0
Positions the time loop to be executed. Selects the time loop named name as the one to be executed....
Interface of a time loop.
virtual String title() const =0
Title of the time loop.
virtual String description() const =0
Description of the time loop.
virtual StringCollection userClasses() const =0
List of user classes associated with the time loop.
virtual String name() const =0
Name of the time loop.
virtual TraceMessage info()=0
Stream for an information message.
Variable manager interface.
virtual void variables(VariableRefCollection v, IModule *i)=0
Gets all variables of module i.
virtual eDataType dataType() const =0
Data type managed by the variable (Real, Integer, ...).
virtual eItemKind itemKind() const =0
Kind of mesh entities on which the variable is based.
virtual Integer dimension() const =0
Dimension of the variable.
virtual String name() const =0
Variable name.
virtual IServiceInfo * serviceInfo() const =0
Returns the IServiceInfo associated with this factory.
ListEnumeratorT< VariableRef * > Enumerator
T * get() const
Returns the object referenced by the instance.
Reference to an instance.
Encapsulation of an automatically destructing pointer.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
View of an array of elements of type T.
constexpr __host__ __device__ Span< T, DynExtent > subSpan(Int64 abegin, Int64 asize) const
Sub-view starting from element abegin and containing asize elements.
Unicode character string.
void writeBytes(std::ostream &o) const
Writes the string in UTF-8 format to the stream o.
const char * localstr() const
Returns the conversion of the instance into UTF-8 encoding.
Parameters necessary for building a subdomain.
Time loop loading functor.
TimeLoopCollection timeLoops() const
List of read time loops.
void readTimeLoops()
Performs the reading of available time loops.
void registerTimeLoops(ISubDomain *sd)
Registers the list of time loops in the manager sd.
1D data vector with value semantics (STL style).
XmlNode child(const String &name) const
Child node of this node with name name.
void setAttrValue(const String &name, const String &value)
Sets the attribute name to the value value.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
List< String > StringList
Unicode string list.
Collection< ICaseOptions * > CaseOptionsCollection
Collection of dataset options.
const char * itemKindName(eItemKind kind)
Entity kind name.
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.
List< VariableRef * > VariableRefList
Array of variable references.
const char * dataTypeName(eDataType type)
Data type name.