bes  Updated for version 3.20.13
DapUtils.cc
1 // This file is part of bes, A C++ back-end server implementation framework
2 // for the OPeNDAP Data Access Protocol.
3 
4 // Copyright (c) 2022 OPeNDAP
5 // Author: James Gallagher <jgallagher@opendap.org>
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Lesser General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 //
22 // Created by James Gallagher on 4/6/22.
23 //
24 
25 #include "config.h"
26 
27 #include <iostream>
28 
29 #include "BESUtil.h"
30 #include "BESLog.h"
31 
32 #include <libdap/DDS.h>
33 #include <libdap/DMR.h>
34 
35 using namespace libdap;
36 
37 namespace dap_utils {
38 
39 static void log_request_and_memory_size_helper(long req_size) {
40  auto mem_size = BESUtil::get_current_memory_usage(); // size in KB or 0. jhrg 4/6/22
41  if (mem_size) {
42  INFO_LOG("request size: " << req_size << "KB|&|memory used by process: " << mem_size << "KB" << endl);
43  }
44  else {
45  INFO_LOG("request size: " << req_size << "KB" << endl);
46  }
47 }
48 
57 void
58 log_request_and_memory_size(DDS *const *dds)
59 {
60  auto req_size = (long)(*dds)->get_request_size_kb(true);
61  log_request_and_memory_size_helper(req_size);
62 }
63 
72 void
73 log_request_and_memory_size(/*const*/ DMR &dmr)
74 {
75  // The request_size_kb() method is not marked const. Fix. jhrg 4/6/22
76  auto req_size = (long)dmr.request_size_kb(true);
77  log_request_and_memory_size_helper(req_size);
78 }
79 
80 } // namespace dap_utils
static long get_current_memory_usage() noexcept
Get the Resident Set Size in KB.
Definition: BESUtil.cc:86