Doxygen
Loading...
Searching...
No Matches
DotManager Class Reference

Singleton that manages parallel dot invocations and patching files for embedding image maps. More...

#include <src/dot.h>

+ Collaboration diagram for DotManager:

Public Member Functions

DotRunnercreateRunner (const QCString &absDotName, const QCString &md5Hash)
 
DotFilePatchercreateFilePatcher (const QCString &fileName)
 
bool run ()
 

Static Public Member Functions

static DotManagerinstance ()
 

Private Member Functions

 DotManager ()
 
virtual ~DotManager ()
 

Private Attributes

std::map< std::string, std::unique_ptr< DotRunner > > m_runners
 
std::map< std::string, DotFilePatcherm_filePatchers
 
ThreadPool m_workers
 

Detailed Description

Singleton that manages parallel dot invocations and patching files for embedding image maps.

Definition at line 34 of file dot.h.

Constructor & Destructor Documentation

◆ DotManager()

DotManager::DotManager ( )
private

Definition at line 84 of file dot.cpp.

84 : m_runners(), m_filePatchers(), m_workers(static_cast<size_t>(Config_getInt(DOT_NUM_THREADS)))
85{
86}
std::map< std::string, DotFilePatcher > m_filePatchers
Definition dot.h:48
std::map< std::string, std::unique_ptr< DotRunner > > m_runners
Definition dot.h:47
ThreadPool m_workers
Definition dot.h:49
#define Config_getInt(name)
Definition config.h:34

References Config_getInt, m_filePatchers, m_runners, and m_workers.

Referenced by instance().

◆ ~DotManager()

DotManager::~DotManager ( )
privatevirtual

Definition at line 88 of file dot.cpp.

89{
90}

Member Function Documentation

◆ createFilePatcher()

DotFilePatcher * DotManager::createFilePatcher ( const QCString & fileName)

Definition at line 116 of file dot.cpp.

117{
118 std::lock_guard<std::mutex> lock(g_dotManagerMutex);
119 auto patcher = m_filePatchers.find(fileName.str());
120
121 if (patcher != m_filePatchers.end()) return &(patcher->second);
122
123 auto rv = m_filePatchers.emplace(fileName.str(), fileName);
124 assert(rv.second);
125 return &(rv.first->second);
126}
const std::string & str() const
Definition qcstring.h:537
static std::mutex g_dotManagerMutex
Definition dot.cpp:40

References g_dotManagerMutex, m_filePatchers, and QCString::str().

◆ createRunner()

DotRunner * DotManager::createRunner ( const QCString & absDotName,
const QCString & md5Hash )

Definition at line 92 of file dot.cpp.

93{
94 std::lock_guard<std::mutex> lock(g_dotManagerMutex);
95 DotRunner* rv = nullptr;
96 auto const runit = m_runners.find(absDotName.str());
97 if (runit == m_runners.end())
98 {
99 auto insobj = std::make_unique<DotRunner>(absDotName, md5Hash);
100 rv = insobj.get();
101 m_runners.emplace(absDotName.str(), std::move(insobj));
102 }
103 else
104 {
105 // we have a match
106 if (md5Hash != runit->second->getMd5Hash())
107 {
108 err("md5 hash does not match for two different runs of %s !\n", qPrint(absDotName));
109 }
110 rv = runit->second.get();
111 }
112 assert(rv);
113 return rv;
114}
#define err(fmt,...)
Definition message.h:84
const char * qPrint(const char *s)
Definition qcstring.h:672

References err, g_dotManagerMutex, m_runners, qPrint(), and QCString::str().

Referenced by DotGraph::prepareDotFile().

◆ instance()

DotManager * DotManager::instance ( )
static

Definition at line 78 of file dot.cpp.

79{
80 static DotManager theInstance;
81 return &theInstance;
82}
DotManager()
Definition dot.cpp:84

References DotManager().

Referenced by DotGraph::generateCode(), generateOutput(), DotGraph::prepareDotFile(), and DotLegendGraph::writeGraph().

◆ run()

bool DotManager::run ( )

Definition at line 128 of file dot.cpp.

129{
130 size_t numDotRuns = m_runners.size();
131 size_t numFilePatchers = m_filePatchers.size();
132 if (numDotRuns+numFilePatchers>1)
133 {
134 if (Config_getInt(DOT_NUM_THREADS)<=1)
135 {
136 msg("Generating dot graphs in single threaded mode...\n");
137 }
138 else
139 {
140 msg("Generating dot graphs using %d parallel threads...\n",Config_getInt(DOT_NUM_THREADS));
141 }
142 }
143 size_t i=1;
144
145 bool setPath=FALSE;
146 if (Config_getBool(GENERATE_HTML))
147 {
148 setDotFontPath(Config_getString(HTML_OUTPUT));
149 setPath=TRUE;
150 }
151 else if (Config_getBool(GENERATE_LATEX))
152 {
153 setDotFontPath(Config_getString(LATEX_OUTPUT));
154 setPath=TRUE;
155 }
156 else if (Config_getBool(GENERATE_RTF))
157 {
158 setDotFontPath(Config_getString(RTF_OUTPUT));
159 setPath=TRUE;
160 }
161 else if (Config_getBool(GENERATE_DOCBOOK))
162 {
163 setDotFontPath(Config_getString(DOCBOOK_OUTPUT));
164 setPath=TRUE;
165 }
166 // fill work queue with dot operations
167 size_t prev=1;
168 if (Config_getInt(DOT_NUM_THREADS)<=1) // no threads to work with
169 {
170 for (auto & dr : m_runners)
171 {
172 msg("Running dot for graph %zu/%zu\n",prev,numDotRuns);
173 dr.second->run();
174 prev++;
175 }
176 }
177 else // use multiple threads to run instances of dot in parallel
178 {
179 std::vector< std::future<void> > results;
180 for (auto & dr: m_runners)
181 {
182 DotRunner *runner = dr.second.get();
183 auto process = [runner]()
184 {
185 runner->run();
186 };
187 results.emplace_back(m_workers.queue(process));
188 }
189 for (auto &f : results)
190 {
191 f.get();
192 msg("Running dot for graph %zu/%zu\n",prev,numDotRuns);
193 prev++;
194 }
195 }
196 if (setPath)
197 {
199 }
200
201 // patch the output file and insert the maps and figures
202 i=1;
203 // since patching the svg files may involve patching the header of the SVG
204 // (for zoomable SVGs), and patching the .html files requires reading that
205 // header after the SVG is patched, we first process the .svg files and
206 // then the other files.
207 for (auto & fp : m_filePatchers)
208 {
209 if (fp.second.isSVGFile())
210 {
211 msg("Patching output file %zu/%zu\n",i,numFilePatchers);
212 if (!fp.second.run()) return FALSE;
213 i++;
214 }
215 }
216 for (auto& fp : m_filePatchers)
217 {
218 if (!fp.second.isSVGFile())
219 {
220 msg("Patching output file %zu/%zu\n",i,numFilePatchers);
221 if (!fp.second.run()) return FALSE;
222 i++;
223 }
224 }
225 return TRUE;
226}
bool run()
Runs dot for all jobs added.
#define Config_getBool(name)
Definition config.h:33
#define Config_getString(name)
Definition config.h:32
static void setDotFontPath(const QCString &path)
Definition dot.cpp:42
static void unsetDotFontPath()
Definition dot.cpp:63
void msg(const char *fmt,...)
Definition message.cpp:98
#define TRUE
Definition qcstring.h:37
#define FALSE
Definition qcstring.h:34

References Config_getBool, Config_getInt, Config_getString, FALSE, m_filePatchers, m_runners, m_workers, msg(), DotRunner::run(), setDotFontPath(), TRUE, and unsetDotFontPath().

Referenced by generateOutput().

Member Data Documentation

◆ m_filePatchers

std::map<std::string, DotFilePatcher> DotManager::m_filePatchers
private

Definition at line 48 of file dot.h.

Referenced by createFilePatcher(), DotManager(), and run().

◆ m_runners

std::map<std::string, std::unique_ptr<DotRunner> > DotManager::m_runners
private

Definition at line 47 of file dot.h.

Referenced by createRunner(), DotManager(), and run().

◆ m_workers

ThreadPool DotManager::m_workers
private

Definition at line 49 of file dot.h.

Referenced by DotManager(), and run().


The documentation for this class was generated from the following files: