Panda3D
Loading...
Searching...
No Matches
bufferResidencyTracker.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file bufferResidencyTracker.cxx
10 * @author drose
11 * @date 2006-03-16
12 */
13
15#include "bufferContext.h"
16#include "clockObject.h"
17#include "indent.h"
18
19PStatCollector BufferResidencyTracker::_gmem_collector("Graphics memory");
20
21/**
22 *
23 */
24BufferResidencyTracker::
25BufferResidencyTracker(const std::string &pgo_name, const std::string &type_name) :
26 _pgo_collector(_gmem_collector, pgo_name),
27 _active_resident_collector(PStatCollector(_pgo_collector, "Active"), type_name),
28 _active_nonresident_collector(PStatCollector(_pgo_collector, "Thrashing"), type_name),
29 _inactive_resident_collector(PStatCollector(_pgo_collector, "Inactive"), type_name),
30 _inactive_nonresident_collector(PStatCollector(_pgo_collector, "Nonresident"), type_name),
31 _active_frame(0)
32{
33}
34
35/**
36 *
37 */
38BufferResidencyTracker::
39~BufferResidencyTracker() {
40 _inactive_nonresident_collector.set_level(0);
41 _active_nonresident_collector.set_level(0);
42 _inactive_resident_collector.set_level(0);
43 _active_resident_collector.set_level(0);
44}
45
46/**
47 * To be called at the beginning of a frame, this initializes the
48 * active/inactive status.
49 */
51begin_frame(Thread *current_thread) {
52 int this_frame = ClockObject::get_global_clock()->get_frame_count(current_thread);
53 if (_active_frame != this_frame) {
54 _active_frame = this_frame;
55
56 // Move all of the previously "active" objects into "inactive". They'll
57 // get re-added to "active" as they get rendered.
58 move_inactive(_chains[S_inactive_nonresident],
59 _chains[S_active_nonresident]);
60 move_inactive(_chains[S_inactive_resident],
61 _chains[S_active_resident]);
62 }
63}
64
65/**
66 * To be called at the end of a frame, this updates the PStatCollectors
67 * appropriately.
68 */
70end_frame(Thread *current_thread) {
71 _inactive_nonresident_collector.set_level(_chains[S_inactive_nonresident].get_total_size());
72 _active_nonresident_collector.set_level(_chains[S_active_nonresident].get_total_size());
73 _inactive_resident_collector.set_level(_chains[S_inactive_resident].get_total_size());
74 _active_resident_collector.set_level(_chains[S_active_resident].get_total_size());
75}
76
77/**
78 * Resets the pstats levels to their appropriate values, possibly in the
79 * middle of a frame.
80 */
82set_levels() {
83 _inactive_nonresident_collector.set_level(_chains[S_inactive_nonresident].get_total_size());
84 _active_nonresident_collector.set_level(_chains[S_active_nonresident].get_total_size());
85 _inactive_resident_collector.set_level(_chains[S_inactive_resident].get_total_size());
86 _active_resident_collector.set_level(_chains[S_active_resident].get_total_size());
87}
88
89/**
90 *
91 */
92void BufferResidencyTracker::
93write(std::ostream &out, int indent_level) const {
94 if (_chains[S_inactive_nonresident].get_count() != 0) {
95 indent(out, indent_level) << "Inactive nonresident:\n";
96 _chains[S_inactive_nonresident].write(out, indent_level + 2);
97 }
98
99 if (_chains[S_active_nonresident].get_count() != 0) {
100 indent(out, indent_level) << "Active nonresident:\n";
101 _chains[S_active_nonresident].write(out, indent_level + 2);
102 }
103
104 if (_chains[S_inactive_resident].get_count() != 0) {
105 indent(out, indent_level) << "Inactive resident:\n";
106 _chains[S_inactive_resident].write(out, indent_level + 2);
107 }
108
109 if (_chains[S_active_resident].get_count() != 0) {
110 indent(out, indent_level) << "Active resident:\n";
111 _chains[S_active_resident].write(out, indent_level + 2);
112 }
113}
114
115/**
116 * Moves all of the "active" objects into "inactive".
117 */
118void BufferResidencyTracker::
119move_inactive(BufferContextChain &inactive, BufferContextChain &active) {
120 BufferContext *node = active.get_first();
121 while (node != nullptr) {
122 nassertv((node->_residency_state & S_active) != 0);
123 node->_residency_state &= ~S_active;
124 node = node->get_next();
125 }
126
127 inactive.take_from(active);
128}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class maintains a linked list of BufferContexts that might be allocated on the graphics card in ...
BufferContext * get_first()
Returns the first BufferContext object stored in the tracker.
void take_from(BufferContextChain &other)
Moves all of the BufferContexts from the other tracker onto this one.
This is a base class for those kinds of SavedContexts that occupy an easily-measured (and substantial...
BufferContext * get_next() const
This can be used along with BufferContextChain::get_first() to walk through the list of objects store...
void end_frame(Thread *current_thread)
To be called at the end of a frame, this updates the PStatCollectors appropriately.
void begin_frame(Thread *current_thread)
To be called at the beginning of a frame, this initializes the active/inactive status.
void set_levels()
Resets the pstats levels to their appropriate values, possibly in the middle of a frame.
get_frame_count
Returns the number of times tick() has been called since the ClockObject was created,...
Definition clockObject.h:94
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
A lightweight class that represents a single element that may be timed and/or counted via stats.
A thread; that is, a lightweight process.
Definition thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.