[0d0e60]: libpp / profile.cpp  Maximize  Restore  History

Download this file

147 lines (110 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* @file profile.cpp
* Encapsulation for samples files over all profile classes
* belonging to the same binary image
*
* @remark Copyright 2002 OProfile authors
* @remark Read the file COPYING
*
* @author Philippe Elie
* @author John Levon
*/
#include <unistd.h>
#include <iostream>
#include <string>
#include <sstream>
#include <cerrno>
#include "op_exception.h"
#include "op_header.h"
#include "op_config.h"
#include "op_sample_file.h"
#include "profile.h"
using namespace std;
profile_t::profile_t()
: start_offset(0)
{
}
// static member
unsigned int profile_t::sample_count(string const & filename)
{
samples_odb_t samples_db;
open_sample_file(filename, samples_db);
unsigned int count = 0;
odb_node_nr_t node_nr, pos;
odb_node_t * node = odb_get_iterator(&samples_db, &node_nr);
for (pos = 0; pos < node_nr; ++pos) {
if (node[pos].key)
count += node[pos].value;
}
odb_close(&samples_db);
return count;
}
//static member
void profile_t::open_sample_file(string const & filename, samples_odb_t & db)
{
int rc = odb_open(&db, filename.c_str(), ODB_RDONLY,
sizeof(struct opd_header));
if (rc)
throw op_fatal_error(filename + ": " + strerror(rc));
opd_header const & head = *static_cast<opd_header *>(db.base_memory);
if (head.version != OPD_VERSION) {
ostringstream os;
os << "oprofpp: samples files version mismatch, are you "
<< "running a daemon and post-profile tools with version "
<< "mismatch ?\n";
throw op_fatal_error(os.str());
}
}
void profile_t::add_sample_file(string const & filename, u32 offset)
{
samples_odb_t samples_db;
open_sample_file(filename, samples_db);
opd_header const & head = *static_cast<opd_header *>(samples_db.base_memory);
// if we already read a sample file header pointer is non null
if (file_header.get()) {
op_check_header(head, *file_header, filename);
}
file_header.reset(new opd_header(head));
odb_node_nr_t node_nr, pos;
odb_node_t * node = odb_get_iterator(&samples_db, &node_nr);
for (pos = 0; pos < node_nr; ++pos) {
if (node[pos].key) {
ordered_samples_t::iterator it =
ordered_samples.find(node[pos].key);
if (it != ordered_samples.end()) {
it->second += node[pos].value;
} else {
ordered_samples_t::value_type
val(node[pos].key, node[pos].value);
ordered_samples.insert(val);
}
}
}
odb_close(&samples_db);
if (!get_header().is_kernel)
return;
start_offset = offset;
}
profile_t::iterator_pair
profile_t::samples_range(odb_key_t start, odb_key_t end) const
{
// if the image contains no symbol the vma range is [0 - filesize]
// in this case we can't substract start_offset else we will underflow
// and the iterator range will be empty.
if (start)
start -= start_offset;
end -= start_offset;
ordered_samples_t::const_iterator first =
ordered_samples.lower_bound(start);
ordered_samples_t::const_iterator last =
ordered_samples.lower_bound(end);
return make_pair(const_iterator(first, start_offset),
const_iterator(last, start_offset));
}
profile_t::iterator_pair profile_t::samples_range() const
{
ordered_samples_t::const_iterator first = ordered_samples.begin();
ordered_samples_t::const_iterator last = ordered_samples.end();
return make_pair(const_iterator(first, start_offset),
const_iterator(last, start_offset));
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks