aboutsummaryrefslogtreecommitdiff
path: root/libpp/filename_spec.cpp
blob: 9ba74db257310d2aa82746b47b48cf4c846cce7e (plain)
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
/**
 * @file filename_spec.cpp
 * Container holding a sample filename split into its components
 *
 * @remark Copyright 2003 OProfile authors
 * @remark Read the file COPYING
 *
 * @author Philippe Elie
 */

#include <string>

#include "filename_spec.h"
#include "parse_filename.h"
#include "generic_spec.h"
#include "locate_images.h"


using namespace std;


filename_spec::filename_spec(string const & filename,
			     extra_images const & extra)
{
	set_sample_filename(filename, extra);
}


filename_spec::filename_spec()
	: image("*"), lib_image("*")
{
}


bool filename_spec::match(filename_spec const & rhs,
                          string const & binary) const
{
	if (!tid.match(rhs.tid) || !cpu.match(rhs.cpu) ||
	    !tgid.match(rhs.tgid) || count != rhs.count ||
	    unitmask != rhs.unitmask || event != rhs.event) {
		return false;
	}

	if (binary.empty())
		return image == rhs.image && lib_image == rhs.lib_image;

	// PP:3.3 if binary is not empty we must match either the
	// lib_name if present or the image name
	if (!rhs.lib_image.empty()) {
		// FIXME: use fnmatch ?
		return rhs.lib_image == binary;
	}

	// FIXME: use fnmatch ?
	return rhs.image == binary;
}


void filename_spec::set_sample_filename(string const & filename,
	extra_images const & extra)
{
	parsed_filename parsed = parse_filename(filename, extra);

	image = parsed.image;
	lib_image = parsed.lib_image;
	cg_image = parsed.cg_image;
	event = parsed.event;
	count = op_lexical_cast<int>(parsed.count);
	unitmask = op_lexical_cast<unsigned int>(parsed.unitmask);
	tgid.set(parsed.tgid);
	tid.set(parsed.tid);
	cpu.set(parsed.cpu);
}


bool filename_spec::is_dependent() const
{
	if (cg_image.empty())
		return image != lib_image;
	return cg_image != image || cg_image != lib_image;
}