populate.cpp

Go to the documentation of this file.
00001 
00015 #include "profile.h"
00016 #include "profile_container.h"
00017 #include "arrange_profiles.h"
00018 #include "op_bfd.h"
00019 #include "op_header.h"
00020 #include "populate.h"
00021 #include "populate_for_spu.h"
00022 
00023 #include "image_errors.h"
00024 
00025 #include <iostream>
00026 
00027 using namespace std;
00028 
00029 namespace {
00030 
00032 bool
00033 populate_from_files(profile_t & profile, op_bfd const & abfd,
00034                     list<profile_sample_files> const & files)
00035 {
00036     list<profile_sample_files>::const_iterator it = files.begin();
00037     list<profile_sample_files>::const_iterator const end = files.end();
00038 
00039     bool found = false;
00040     // we can't handle cg files here obviously
00041     for (; it != end; ++it) {
00042         // A bit ugly but we must accept silently empty sample filename
00043         // since we can create a profile_sample_files for cg file only
00044         // (i.e no sample to the binary)
00045         if (!it->sample_filename.empty()) {
00046             profile.add_sample_file(it->sample_filename);
00047             profile.set_offset(abfd);
00048             found = true;
00049         }
00050     }
00051 
00052     return found;
00053 }
00054 
00055 }  // anon namespace
00056 
00057 
00058 void
00059 populate_for_image(profile_container & samples, inverted_profile const & ip,
00060     string_filter const & symbol_filter, bool * has_debug_info)
00061 {
00062     if (is_spu_profile(ip)) {
00063         populate_for_spu_image(samples, ip, symbol_filter,
00064                        has_debug_info);
00065         return;
00066     }
00067 
00068     bool ok = ip.error == image_ok;
00069     op_bfd abfd(ip.image, symbol_filter,
00070             samples.extra_found_images, ok);
00071     if (!ok && ip.error == image_ok)
00072         ip.error = image_format_failure;
00073 
00074     if (ip.error == image_format_failure)
00075         report_image_error(ip, false, samples.extra_found_images);
00076 
00077     opd_header header;
00078 
00079     bool found = false;
00080     for (size_t i = 0; i < ip.groups.size(); ++i) {
00081         list<image_set>::const_iterator it
00082             = ip.groups[i].begin();
00083         list<image_set>::const_iterator const end
00084             = ip.groups[i].end();
00085 
00086         // we can only share a profile_t amongst each
00087         // image_set's files - this is because it->app_image
00088         // changes, and the .add() would mis-attribute
00089         // to the wrong app_image otherwise
00090         for (; it != end; ++it) {
00091             profile_t profile;
00092             if (populate_from_files(profile, abfd, it->files)) {
00093                 header = profile.get_header();
00094                 samples.add(profile, abfd, it->app_image, i);
00095                 found = true;
00096             }
00097         }
00098     }
00099 
00100     if (found == true && ip.error == image_ok) {
00101         image_error error;
00102         string filename =
00103             samples.extra_found_images.find_image_path(
00104                 ip.image, error, true);
00105         check_mtime(filename, header);
00106     }
00107 
00108     if (has_debug_info)
00109         *has_debug_info = abfd.has_debug_info();
00110 }

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1