Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Profiler.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Profiler.cc (C) 2000-2026 */
9/* */
10/* Classes utilitaires. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/alina/Profiler.h"
15
16#include "arcane/utils/PlatformUtils.h"
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20
21namespace Arcane::Alina
22{
23Profiler global_alina_profiler;
24
25Profiler& Profiler::
26globalProfiler()
27{
28 return global_alina_profiler;
29}
30
31void Profiler::
32globalTic(const std::string& name)
33{
34 global_alina_profiler.tic(name);
35}
36
37Profiler::delta_type Profiler::
38globalToc(const std::string&)
39{
40 return global_alina_profiler.toc();
41}
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
47tic(const std::string& name)
48{
49 stack.back()->children[name].begin = Platform::getRealTime();
50 stack.push_back(&stack.back()->children[name]);
51}
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
56Profiler::delta_type Profiler::
57toc(const std::string&)
58{
59 profile_unit* top = stack.back();
60 stack.pop_back();
61
62 value_type current = Platform::getRealTime();
63 delta_type delta = current - top->begin;
64
65 top->length += delta;
66 root.length = current - root.begin;
67
68 return delta;
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74void Profiler::
75reset()
76{
77 stack.clear();
78 root.length = 0;
79 root.children.clear();
80
81 stack.push_back(&root);
82 root.begin = Platform::getRealTime();
83 ;
84}
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88void Profiler::
89init()
90{
91 stack.reserve(128);
92 stack.push_back(&root);
93 root.begin = Platform::getRealTime();
94}
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99void Profiler::
100print(std::ostream& out) const
101{
102 if (stack.back() != &root)
103 out << "Warning! Profile is incomplete." << std::endl;
104 ScopedStreamModifier ss(out);
105 root.print(out, name, 0, root.length, root.total_width(name, 0));
106}
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
111} // namespace Arcane::Alina
112
113/*---------------------------------------------------------------------------*/
114/*---------------------------------------------------------------------------*/
Profiler class.
Definition Profiler.h:50
static delta_type globalToc(const std::string &="")
Stops measurement.
Definition Profiler.cc:38
void tic(const std::string &name)
Starts measurement.
Definition Profiler.cc:47
delta_type toc(const std::string &="")
Stops measurement.
Definition Profiler.cc:57
ARCCORE_BASE_EXPORT Real getRealTime()
Temps Real utilisé en secondes.