File: process_model.hh

package info (click to toggle)
lavaps 1.9-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 692 kB
  • ctags: 698
  • sloc: ansic: 2,390; cpp: 2,089; sh: 1,993; tcl: 542; makefile: 229; perl: 182
file content (111 lines) | stat: -rw-r--r-- 3,245 bytes parent folder | download
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* -*-	Mode:C++ -*- */

/*
 * process_model.hh
 * Copyright (C) 1999 by John Heidemann
 * $Id: process_model.hh,v 1.23 1999/09/06 18:16:16 johnh Exp $
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 *
 */


#ifndef lavaps_process_model_h
#define lavaps_process_model_h

#include <unistd.h>  // pid_t

#include "change_tracking.hh"
#include "process_view.hh"
#include "const_str.hh"

class process_model;
class process_view;

/*
 * process_model: a system-independent representation of the
 * interesting information about a process.
 */
class process_model {
	// most of these are to give access to the details
	// cleaner would be to have set/access functions for *each*
	// member variable.
	friend class process_view;

protected:
	process_model(const process_model& tb);
	process_model& operator=(const process_model& tb);

	// used for tracking process age via age()
	time_t last_run_time_,
		next_age_time_;
	int age_increment_;
	change_tracking<int> exponential_age_;

	process_view *pv_;

	// rest is the details:
	int pid_;   // required!
	int uid_;
	// should add tty?  only when we want to use it.
	const_str cmd_;   // program name (just the program, not the whole cmd line)
	change_tracking<int> cmd_hash_;   // hash of cmd name

	// int priority_;   // kernel adjusted prio
	int nice_;       // user-supplied nice value
	time_t start_time_;
	change_tracking<time_t> utime_;  // cumulative user time (in usec)
	change_tracking<time_t> stime_;  // cumulative system time

	// use KB below to avoid unsigned ugliness
	change_tracking<int> virtual_size_;      // total memory size in KB
	change_tracking<int> resident_;      // resident memory size in KB (could be partially shared)
	change_tracking<int> inmem_pct_;	// % of process in memory

	static int cmd_hashify(const char *cmd);

public:
	bool found_;   // found this scan

	process_model(int pid);
	~process_model();

	void init_view() { pv_ = new process_view(this); }
	void update_view() { pv_->update(); }

	int age() { return exponential_age_.last(); }
	void age(time_t now, bool reinit = false);

	void set_uid(int a) { uid_ = a; }
	void set_nice(int a) { nice_ = a; }
	void set_start_time(int a) { start_time_ = a; }
	void set_cmd(const char *c);

	void set_utime(int t) { utime_.tick_set(t); }
	void set_stime(int t) { stime_.tick_set(t); }
	void set_virtual_size(int s) { virtual_size_.tick_set(s); }
	void set_resident(int s) { resident_.tick_set(s); }
	// void set_inmem_pct(int s) { inmem_pct_.tick_set(s); }

	void check_inmem_pct();

	int pid() { return pid_; }

	void dump();

	process_view *view() { return pv_; }
};

#endif /* lavaps_process_model_h */