repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / cortex / support / ProfileTarget.cpp
blob665ab570e17547daea2dd906734c89d60fd8471a
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
32 // ProfileTarget.cpp
34 #include "ProfileTarget.h"
35 #include <cstdio>
36 #include <cstring>
37 #include <list>
38 #include <algorithm>
40 __USE_CORTEX_NAMESPACE
42 // -------------------------------------------------------- //
43 // ctor/dtor
44 // -------------------------------------------------------- //
46 ProfileTarget::~ProfileTarget() {}
47 ProfileTarget::ProfileTarget() {}
49 // -------------------------------------------------------- //
50 // user operations
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:
65 uint32 nameLength;
66 BString maxPad;
67 fnDumpEntry(uint32 _n) : nameLength(_n) {
68 maxPad.SetTo(' ', nameLength);
69 fprintf(stderr,
70 " BLOCK%s COUNT ELAPSED AVERAGE\n"
71 " ----------------------------------------------------------------------------\n",
72 maxPad.String());
74 void operator()(ProfileTarget::block_entry& entry) const {
75 BString namePad;
76 namePad.SetTo(' ', nameLength-strlen(entry.name));
77 fprintf(stderr,
78 " %s:%s %8ld %8Ld %.4f\n",
79 entry.name,
80 namePad.String(),
81 entry.count,
82 entry.elapsed,
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();
96 it++) {
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();
104 sorted.sort();
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];
116 e.count++;
117 e.elapsed += elapsed;
120 // END -- ProfileTarget.cpp --