Skip to main content

The DotManager Class Reference

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

Declaration

class DotManager { ... }

Included Headers

#include <src/dot.h>

Private Constructors Index

DotManager ()

Private Destructor Index

~DotManager ()

Public Member Functions Index

DotRunner *createRunner (const QCString &absDotName, const QCString &md5Hash)
DotFilePatcher *createFilePatcher (const QCString &fileName)
boolrun ()

Private Member Attributes Index

std::map< std::string, std::unique_ptr< DotRunner > >m_runners
std::map< std::string, DotFilePatcher >m_filePatchers
ThreadPoolm_workers

Public Static Functions Index

static DotManager *instance ()

Description

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

Definition at line 34 of file dot.h.

Private Constructors

DotManager()

DotManager::DotManager ()

Declaration at line 43 of file dot.h, definition at line 84 of file dot.cpp.

84DotManager::DotManager() : m_runners(), m_filePatchers(), m_workers(static_cast<size_t>(Config_getInt(DOT_NUM_THREADS)))
85{
86}

References Config_getInt, m_filePatchers, m_runners and m_workers.

Referenced by instance.

Private Destructor

~DotManager()

DotManager::~DotManager ()
virtual

Declaration at line 44 of file dot.h, definition at line 88 of file dot.cpp.

Public Member Functions

createFilePatcher()

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

Declaration at line 39 of file dot.h, 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}

References g_dotManagerMutex, m_filePatchers and QCString::str.

createRunner()

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

Declaration at line 38 of file dot.h, definition at line 92 of file dot.cpp.

92DotRunner* DotManager::createRunner(const QCString &absDotName, const QCString& md5Hash)
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 {} !\n", absDotName);
109 }
110 rv = runit->second.get();
111 }
112 assert(rv);
113 return rv;
114}

References err, g_dotManagerMutex, m_runners and QCString::str.

Referenced by DotGraph::prepareDotFile.

run()

bool DotManager::run ()

Declaration at line 40 of file dot.h, 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 {
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 {}/{}\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 {}/{}\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 {}/{}\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 {}/{}\n",i,numFilePatchers);
221 if (!fp.second.run()) return FALSE;
222 i++;
223 }
224 }
225 return TRUE;
226}

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

Referenced by generateOutput.

Private Member Attributes

m_filePatchers

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

Definition at line 48 of file dot.h.

48 std::map<std::string, DotFilePatcher> m_filePatchers;

Referenced by createFilePatcher, DotManager and run.

m_runners

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

Definition at line 47 of file dot.h.

47 std::map<std::string, std::unique_ptr<DotRunner> > m_runners;

Referenced by createRunner, DotManager and run.

m_workers

ThreadPool DotManager::m_workers

Definition at line 49 of file dot.h.

Referenced by DotManager and run.

Public Static Functions

instance()

DotManager * DotManager::instance ()
static

Declaration at line 37 of file dot.h, definition at line 78 of file dot.cpp.

79{
80 static DotManager theInstance;
81 return &theInstance;
82}

Reference DotManager.

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


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.