~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to oprofile/org.eclipse.linuxtools.oprofile.core/src/org/eclipse/linuxtools/internal/oprofile/core/model/OpModelSession.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2008, 2009 Red Hat, Inc.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *    Kent Sebastian <ksebasti@redhat.com> - initial API and implementation 
 
10
 *******************************************************************************/ 
 
11
 
 
12
package org.eclipse.linuxtools.internal.oprofile.core.model;
 
13
 
 
14
import org.eclipse.linuxtools.internal.oprofile.core.Oprofile;
 
15
 
 
16
 
 
17
/**
 
18
 * This class represents oprofile sessions. Sessions contain an image
 
19
 * of the profiled binary.
 
20
 */
 
21
public class OpModelSession {
 
22
        private static final String DEFAULT_SESSION_STRING = "current"; //$NON-NLS-1$
 
23
 
 
24
        private OpModelEvent parentEvent;
 
25
        private OpModelImage image;
 
26
        private String name;
 
27
        private String printTabs = "";          //for nice output //$NON-NLS-1$
 
28
 
 
29
        public OpModelSession(OpModelEvent event, String name) {
 
30
                parentEvent = event;
 
31
                this.name = name;
 
32
                image = null;
 
33
        }
 
34
        
 
35
        public OpModelImage getImage() {
 
36
                return image;
 
37
        }
 
38
 
 
39
        public OpModelEvent getEvent() {
 
40
                return parentEvent;
 
41
        }
 
42
        
 
43
        public String getName() {
 
44
                return name;
 
45
        }
 
46
        
 
47
        public int getCount() {
 
48
                if (image == null) {
 
49
                        return 0;
 
50
                } else {
 
51
                        return image.getCount();
 
52
                }
 
53
        }
 
54
        
 
55
        public boolean isDefaultSession() {
 
56
                return name.equals(DEFAULT_SESSION_STRING); 
 
57
        }
 
58
        
 
59
        public void refreshModel() {
 
60
                //populate this session with samples
 
61
                image = getNewImage();
 
62
        }
 
63
        
 
64
        protected OpModelImage getNewImage() {
 
65
                return Oprofile.getModelData(parentEvent.getName(), name);
 
66
        }
 
67
 
 
68
        public String toString(String tabs) {
 
69
                printTabs = tabs;
 
70
                String s = toString();
 
71
                printTabs = ""; //$NON-NLS-1$
 
72
                return s;
 
73
        }
 
74
 
 
75
        @Override
 
76
        public String toString() {
 
77
                String s = name + "\n"; //$NON-NLS-1$
 
78
                if (image != null) {
 
79
                        s += printTabs + "Image: "; //$NON-NLS-1$
 
80
                        s += image.toString(printTabs + "\t"); //$NON-NLS-1$
 
81
                }
 
82
                return s;
 
83
                
 
84
        }
 
85
}