LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
art::MallocOptionSetter Class Reference

#include "MallocOpts.h"

Public Types

typedef MallocOpts::opt_type opt_type
 

Public Member Functions

 MallocOptionSetter ()
 
bool retrieveFromCpuType ()
 
bool retrieveFromEnv ()
 
void adjustMallocParams ()
 
bool hasErrors () const
 
std::string error_message () const
 
void set_mmap_max (opt_type mmap_max)
 
void set_trim_thr (opt_type trim_thr)
 
void set_top_pad (opt_type top_pad)
 
void set_mmap_thr (opt_type mmap_thr)
 
MallocOpts get () const
 

Private Attributes

bool changed_
 
MallocOpts values_
 
std::string error_message_
 

Detailed Description

Definition at line 63 of file MallocOpts.h.

Member Typedef Documentation

Constructor & Destructor Documentation

art::MallocOptionSetter::MallocOptionSetter ( )

Definition at line 135 of file MallocOpts.cc.

References adjustMallocParams(), error_message_, hasErrors(), retrieveFromCpuType(), and retrieveFromEnv().

135  : changed_(false)
136  {
139  if (hasErrors()) {
140  std::cerr << "ERROR: Reset of malloc options has fails:\n"
141  << error_message_ << "\n";
142  }
143  }
144  }
std::string error_message_
Definition: MallocOpts.h:117
bool hasErrors() const
Definition: MallocOpts.h:72

Member Function Documentation

void art::MallocOptionSetter::adjustMallocParams ( )

Definition at line 147 of file MallocOpts.cc.

References changed_, error_message_, art::MallocOpts::mmap_max_, art::MallocOpts::mmap_thr_, art::MallocOpts::top_pad_, art::MallocOpts::trim_thr_, and values_.

Referenced by MallocOptionSetter().

148  {
149  if (changed_ == false)
150  return; // only adjust if they changed
151  error_message_.clear();
152  changed_ = false;
153 
154 #ifdef M_MMAP_MAX
155  if (mallopt(M_MMAP_MAX, values_.mmap_max_) < 0)
156  error_message_ += "Could not set M_MMAP_MAX\n";
157 #endif
158 #ifdef M_TRIM_THRESHOLD
159  if (mallopt(M_TRIM_THRESHOLD, values_.trim_thr_) < 0)
160  error_message_ += "Could not set M_TRIM_THRESHOLD\n";
161 #endif
162 #ifdef M_TOP_PAD
163  if (mallopt(M_TOP_PAD, values_.top_pad_) < 0)
164  error_message_ += "ERROR: Could not set M_TOP_PAD\n";
165 #endif
166 #ifdef M_MMAP_THRESHOLD
167  if (mallopt(M_MMAP_THRESHOLD, values_.mmap_thr_) < 0)
168  error_message_ += "ERROR: Could not set M_MMAP_THRESHOLD\n";
169 #endif
170  }
opt_type mmap_max_
Definition: MallocOpts.h:43
opt_type top_pad_
Definition: MallocOpts.h:45
opt_type mmap_thr_
Definition: MallocOpts.h:46
std::string error_message_
Definition: MallocOpts.h:117
opt_type trim_thr_
Definition: MallocOpts.h:44
std::string art::MallocOptionSetter::error_message ( ) const
inline

Definition at line 77 of file MallocOpts.h.

78  {
79  return error_message_;
80  }
std::string error_message_
Definition: MallocOpts.h:117
MallocOpts art::MallocOptionSetter::get ( ) const
inline

Definition at line 108 of file MallocOpts.h.

109  {
110  return values_;
111  }
bool art::MallocOptionSetter::hasErrors ( ) const
inline

Definition at line 72 of file MallocOpts.h.

Referenced by MallocOptionSetter().

73  {
74  return !error_message_.empty();
75  }
std::string error_message_
Definition: MallocOpts.h:117
bool art::MallocOptionSetter::retrieveFromCpuType ( )

Definition at line 112 of file MallocOpts.cc.

References changed_, and values_.

Referenced by MallocOptionSetter().

113  {
114  bool rc = true;
115 
116  switch (get_cpu_type()) {
117  case AMD_CPU: {
118  values_ = amd_opts;
119  changed_ = true;
120  break;
121  }
122  case INTEL_CPU: {
123  values_ = intel_opts;
124  changed_ = true;
125  break;
126  }
127  case UNKNOWN_CPU:
128  default:
129  rc = false;
130  }
131 
132  return rc;
133  }
bool art::MallocOptionSetter::retrieveFromEnv ( )

Definition at line 173 of file MallocOpts.cc.

References changed_, art::MallocOpts::mmap_max_, art::MallocOpts::mmap_thr_, art::MallocOpts::top_pad_, art::MallocOpts::trim_thr_, and values_.

Referenced by MallocOptionSetter().

174  {
175  const char* par = getenv("ART_MALLOC_RESET");
176  if (par == 0)
177  return false; // leave quickly here
178  std::string spar(par);
179  bool rc = false;
180 
181  // ART_MALLOC_RESET = "mmap_max trim_thres top_pad mmap_thres"
182 
183  if (spar.size() > 1) {
184  std::istringstream ist(spar);
187 
188  if (ist.bad()) {
189  std::cerr
190  << "bad malloc options in ART_MALLOC_RESET: " << spar << "\n"
191  << "format is: "
192  << "ART_MALLOC_RESET=\"mmap_max trim_thres top_pad mmap_thres\"\n";
193  } else {
194  std::cout << "MALLOC_OPTIONS> Reset options: "
195  << "ART_MALLOC_RESET=" << par << "\n";
196  }
197  rc = true;
198  changed_ = true;
199  }
200 
201  return rc;
202  }
opt_type mmap_max_
Definition: MallocOpts.h:43
opt_type top_pad_
Definition: MallocOpts.h:45
opt_type mmap_thr_
Definition: MallocOpts.h:46
opt_type trim_thr_
Definition: MallocOpts.h:44
void art::MallocOptionSetter::set_mmap_max ( opt_type  mmap_max)
inline

Definition at line 83 of file MallocOpts.h.

84  {
85  values_.mmap_max_ = mmap_max;
86  changed_ = true;
87  }
opt_type mmap_max_
Definition: MallocOpts.h:43
void art::MallocOptionSetter::set_mmap_thr ( opt_type  mmap_thr)
inline

Definition at line 101 of file MallocOpts.h.

102  {
103  values_.mmap_thr_ = mmap_thr;
104  changed_ = true;
105  }
opt_type mmap_thr_
Definition: MallocOpts.h:46
void art::MallocOptionSetter::set_top_pad ( opt_type  top_pad)
inline

Definition at line 95 of file MallocOpts.h.

96  {
97  values_.top_pad_ = top_pad;
98  changed_ = true;
99  }
opt_type top_pad_
Definition: MallocOpts.h:45
void art::MallocOptionSetter::set_trim_thr ( opt_type  trim_thr)
inline

Definition at line 89 of file MallocOpts.h.

90  {
91  values_.trim_thr_ = trim_thr;
92  changed_ = true;
93  }
opt_type trim_thr_
Definition: MallocOpts.h:44

Member Data Documentation

bool art::MallocOptionSetter::changed_
private

Definition at line 114 of file MallocOpts.h.

Referenced by adjustMallocParams(), retrieveFromCpuType(), and retrieveFromEnv().

std::string art::MallocOptionSetter::error_message_
private

Definition at line 117 of file MallocOpts.h.

Referenced by adjustMallocParams(), and MallocOptionSetter().

MallocOpts art::MallocOptionSetter::values_
private

Definition at line 115 of file MallocOpts.h.

Referenced by adjustMallocParams(), retrieveFromCpuType(), and retrieveFromEnv().


The documentation for this class was generated from the following files: