Home | History | Annotate | Download | only in libpp
      1 /**
      2  * @file filename_spec.cpp
      3  * Container holding a sample filename split into its components
      4  *
      5  * @remark Copyright 2003 OProfile authors
      6  * @remark Read the file COPYING
      7  *
      8  * @author Philippe Elie
      9  */
     10 
     11 #include <string>
     12 
     13 #include "filename_spec.h"
     14 #include "parse_filename.h"
     15 #include "generic_spec.h"
     16 #include "locate_images.h"
     17 
     18 
     19 using namespace std;
     20 
     21 
     22 filename_spec::filename_spec(string const & filename,
     23 			     extra_images const & extra)
     24 {
     25 	set_sample_filename(filename, extra);
     26 }
     27 
     28 
     29 filename_spec::filename_spec()
     30 	: image("*"), lib_image("*")
     31 {
     32 }
     33 
     34 
     35 bool filename_spec::match(filename_spec const & rhs,
     36                           string const & binary) const
     37 {
     38 	if (!tid.match(rhs.tid) || !cpu.match(rhs.cpu) ||
     39 	    !tgid.match(rhs.tgid) || count != rhs.count ||
     40 	    unitmask != rhs.unitmask || event != rhs.event) {
     41 		return false;
     42 	}
     43 
     44 	if (binary.empty())
     45 		return image == rhs.image && lib_image == rhs.lib_image;
     46 
     47 	// PP:3.3 if binary is not empty we must match either the
     48 	// lib_name if present or the image name
     49 	if (!rhs.lib_image.empty()) {
     50 		// FIXME: use fnmatch ?
     51 		return rhs.lib_image == binary;
     52 	}
     53 
     54 	// FIXME: use fnmatch ?
     55 	return rhs.image == binary;
     56 }
     57 
     58 
     59 void filename_spec::set_sample_filename(string const & filename,
     60 	extra_images const & extra)
     61 {
     62 	parsed_filename parsed = parse_filename(filename, extra);
     63 
     64 	image = parsed.image;
     65 	lib_image = parsed.lib_image;
     66 	cg_image = parsed.cg_image;
     67 	event = parsed.event;
     68 	count = op_lexical_cast<int>(parsed.count);
     69 	unitmask = op_lexical_cast<unsigned int>(parsed.unitmask);
     70 	tgid.set(parsed.tgid);
     71 	tid.set(parsed.tid);
     72 	cpu.set(parsed.cpu);
     73 }
     74 
     75 
     76 bool filename_spec::is_dependent() const
     77 {
     78 	if (cg_image.empty())
     79 		return image != lib_image;
     80 	return cg_image != image || cg_image != lib_image;
     81 }
     82