2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "ProfileTarget.h"
40 __USE_CORTEX_NAMESPACE
42 // -------------------------------------------------------- //
44 // -------------------------------------------------------- //
46 ProfileTarget::~ProfileTarget() {}
47 ProfileTarget::ProfileTarget() {}
49 // -------------------------------------------------------- //
51 // -------------------------------------------------------- //
53 void ProfileTarget::clear() {
54 m_blockEntryMap
.clear();
57 // [e.moon 14oct99] moved prototype out of header
58 bool operator<(const ProfileTarget::block_entry
& a
, const ProfileTarget::block_entry
& b
);
60 bool operator<(const ProfileTarget::block_entry
& a
, const ProfileTarget::block_entry
& b
) {
61 return b
.elapsed
< a
.elapsed
;
64 class fnDumpEntry
{ public:
67 fnDumpEntry(uint32 _n
) : nameLength(_n
) {
68 maxPad
.SetTo(' ', nameLength
);
70 " BLOCK%s COUNT ELAPSED AVERAGE\n"
71 " ----------------------------------------------------------------------------\n",
74 void operator()(ProfileTarget::block_entry
& entry
) const {
76 namePad
.SetTo(' ', nameLength
-strlen(entry
.name
));
78 " %s:%s %8ld %8Ld %.4f\n",
83 (float)entry
.elapsed
/entry
.count
);
88 void ProfileTarget::dump() const {
89 fprintf(stderr
, "\nProfileTarget::dump()\n\n");
91 list
<block_entry
> sorted
;
92 uint32 nameLength
= 0;
94 for(block_entry_map::const_iterator it
= m_blockEntryMap
.begin();
95 it
!= m_blockEntryMap
.end();
97 if((*it
).first
.Length() > nameLength
)
98 nameLength
= (*it
).first
.Length();
99 sorted
.push_back(block_entry());
100 sorted
.back() = (*it
).second
;
101 sorted
.back().name
= (*it
).first
.String();
105 for_each(sorted
.begin(), sorted
.end(), fnDumpEntry(nameLength
));
108 // -------------------------------------------------------- //
109 // profile-source operations
110 // -------------------------------------------------------- //
112 inline void ProfileTarget::addBlockEntry(
113 const char* blockName
, bigtime_t elapsed
) {
115 block_entry
& e
= m_blockEntryMap
[blockName
];
117 e
.elapsed
+= elapsed
;
120 // END -- ProfileTarget.cpp --