Swarm-NG  1.1
logmanager.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2010 by Mario Juric and the Swarm-NG Development Team *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 3 of the License. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License *
14  * along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17  ************************************************************************/
18 
24 #include "logmanager.hpp"
25 
28 extern "C" void debug_hook()
29 {
30  std::cerr << "";
31 }
32 
33 namespace swarm {
34 namespace log {
35 
37 Pmanager& manager::default_log() {
38  static Pmanager default_manager(new manager());
39  static bool is_initialized = false;
40  if( !is_initialized ){
41  config cfg; cfg["log_writer"] = "null";
42  // default_manager->init(cfg);
43  default_manager->init(cfg,0,0);
44  is_initialized = true;
45  }
46  return default_manager;
47 }
48 
50 void manager::init(const config& cfg, int host_buffer_size, int device_buffer_size)
51 {
52  log_writer = writer::create(cfg);
53 
54  // log memory allocation
55  hlog.alloc(host_buffer_size);
56  pdlog = gpulog::alloc_device_log(device_buffer_size);
57 }
60 {
61  config cfg; cfg["log_writer"] = "null";
62  // swarm::log::manager::init(cfg);
64 }
65 
67 void manager::flush(int flags)
68 {
69  // TODO: Implement flushing of writer as well
70  assert(flags & memory);
71 
72  // TODO: Implement flush-only-if-near-capacity (observe the if_full flag)
73  if(!log_writer.get())
74  {
75  ERROR( "No output writer attached!\n" );
76  }
77 
78  // flush the CPU and GPU buffers
79  replay_printf(std::cerr, hlog);
80  log_writer->process(hlog.internal_buffer(), hlog.size());
81 
82  copy(hlog, pdlog, gpulog::LOG_DEVCLEAR);
83  replay_printf(std::cerr, hlog);
84  log_writer->process(hlog.internal_buffer(), hlog.size());
85 
86  hlog.clear();
87 }
88 
89 }
90 }