abi_test.cpp

Go to the documentation of this file.
00001 
00011 #include "abi.h"
00012 #include "odb.h"
00013 #include "popt_options.h"
00014 #include "op_sample_file.h"
00015 #include "op_cpu_type.h"
00016 #include "op_config.h"
00017 
00018 #include <fstream>
00019 #include <iostream>
00020 
00021 #include <cstdlib>
00022 #include <cstring>
00023 
00024 using namespace std;
00025 
00026 namespace {
00027     string db_filename;
00028     string abi_filename;
00029 }
00030 
00031 
00032 popt::option options_array[] = {
00033     popt::option(db_filename, "db", 'd', "output db to file", "filename"),
00034     popt::option(abi_filename, "abi", 'a', "output abi to file", "filename")
00035 };
00036 
00037 
00038 int main(int argc, char const ** argv)
00039 {
00040     vector<string> rest;
00041     popt::parse_options(argc, argv, rest);
00042 
00043     if (abi_filename.empty() && db_filename.empty()) {
00044         cerr << "error: no file specified to work on" << endl;
00045         exit(1);
00046     }
00047 
00048 
00049     if (!abi_filename.empty()) {
00050         ofstream file(abi_filename.c_str());
00051         if (!file) {
00052             cerr << "error: cannot open " << abi_filename
00053                  << " for writing" << endl;
00054             exit(1);
00055         }
00056         file << abi();
00057     }
00058 
00059     if (!db_filename.empty()) {
00060         odb_t dest;
00061         int rc = odb_open(&dest, db_filename.c_str(), ODB_RDWR,
00062                           sizeof(struct opd_header));
00063 
00064         if (rc) {
00065             cerr << "odb_open() fail:\n"
00066                  << strerror(rc) << endl;
00067             exit(EXIT_FAILURE);
00068         }
00069 
00070         struct opd_header * header;
00071         header = static_cast<struct opd_header *>(odb_get_data(&dest));
00072         memset(header, '\0', sizeof(struct opd_header));
00073         header->version = OPD_VERSION;
00074         memcpy(header->magic, OPD_MAGIC, sizeof(header->magic));
00075         header->is_kernel = 1;
00076         /* ICACHE_FETCHES */
00077         header->ctr_event = 0x80;
00078         header->ctr_um = 0x0;
00079         header->cpu_type = CPU_ATHLON;
00080         header->ctr_count = 0xdeadbeef;
00081         header->cpu_speed = 0;
00082         header->mtime = 1034790063;
00083         header->cg_to_is_kernel = 1;
00084         header->anon_start = 0;
00085         header->cg_to_anon_start = 0;
00086     
00087         for (int i = 0; i < 3793; ++i) {
00088             int rc = odb_add_node(&dest, i, i);
00089             if (rc != EXIT_SUCCESS) {
00090                 cerr << strerror(rc) << endl;
00091                 exit(EXIT_FAILURE);
00092             }
00093         }
00094         odb_close(&dest);
00095     }
00096 }

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1