Skip to content

Commit

Permalink
All internal loggers use "jana" logger_name
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed Sep 15, 2024
1 parent 4eaf52d commit 88279e9
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 44 deletions.
5 changes: 5 additions & 0 deletions src/libraries/JANA/CLI/JSignalHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ void register_handlers(JApplication* app) {
assert (app != nullptr);
g_app = app;
g_logger = &default_cout_logger;
*g_logger = app->GetJParameterManager()->GetLogger("jana");
// Note that this updates the static default_cout_logger to match the user-provided jana:loglevel.
// It would be nice to do this in a less unexpected place, and hopefully that will naturally
// emerge from future refactorings.

g_app->GetJParameterManager()->SetDefaultParameter("jana:status_fname", g_path_to_named_pipe,
"Filename of named pipe for retrieving instantaneous status info");
create_named_pipe(g_path_to_named_pipe);
Expand Down
14 changes: 8 additions & 6 deletions src/libraries/JANA/Calibrations/JCalibrationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include <JANA/Calibrations/JCalibrationFile.h>
#include <JANA/Calibrations/JCalibrationGenerator.h>

#include <JANA/Services/JServiceLocator.h>
#include <JANA/JService.h>

#include <algorithm>
#include "JANA/Services/JParameterManager.h"
#include "JLargeCalibration.h"

class JCalibrationManager : public JService {
Expand All @@ -21,24 +22,25 @@ class JCalibrationManager : public JService {
pthread_mutex_t m_resource_manager_mutex;

std::shared_ptr<JParameterManager> m_params;
JLogger m_logger;

std::string m_url = "file://./";
std::string m_context = "default";

public:
void acquire_services(JServiceLocator *service_locator) {

// Configure our logger
JCalibrationManager() {
SetPrefix("jana");
}

m_params = service_locator->get<JParameterManager>();
m_logger = m_params->GetLogger("JCalibrationManager");
void acquire_services(JServiceLocator* sl) {

// Url and context may be passed in either as environment variables
// or configuration parameters. Default values are used if neither is available.

if (getenv("JANA_CALIB_URL") != nullptr) m_url = getenv("JANA_CALIB_URL");
if (getenv("JANA_CALIB_CONTEXT") != nullptr) m_context = getenv("JANA_CALIB_CONTEXT");

m_params = sl->get<JParameterManager>();
m_params->SetDefaultParameter("JANA:CALIB_URL", m_url, "URL used to access calibration constants");
m_params->SetDefaultParameter("JANA:CALIB_CONTEXT", m_context,
"Calibration context to pass on to concrete JCalibration derived class");
Expand Down
24 changes: 10 additions & 14 deletions src/libraries/JANA/Engine/JArrowProcessingController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ using secs = std::chrono::duration<double>;
void JArrowProcessingController::acquire_services(JServiceLocator * sl) {

auto params = sl->get<JParameterManager>();
m_logger = params->GetLogger("JArrowProcessingController");
m_worker_logger = params->GetLogger("JWorker");
m_scheduler_logger = params->GetLogger("JScheduler");

m_topology = sl->get<JTopologyBuilder>();

params->SetDefaultParameter("jana:timeout", m_timeout_s, "Max time (in seconds) JANA will wait for a thread to update its heartbeat before hard-exiting. 0 to disable timeout completely.");
Expand All @@ -31,8 +27,8 @@ void JArrowProcessingController::acquire_services(JServiceLocator * sl) {
void JArrowProcessingController::initialize() {

m_scheduler = new JScheduler(m_topology);
m_scheduler->logger = m_scheduler_logger;
LOG_INFO(m_logger) << m_topology->mapping << LOG_END;
m_scheduler->logger = GetLogger();
LOG_INFO(GetLogger()) << m_topology->mapping << LOG_END;

m_scheduler->initialize_topology();

Expand All @@ -48,7 +44,7 @@ void JArrowProcessingController::initialize() {
///
/// @param [in] nthreads The number of worker threads to start
void JArrowProcessingController::run(size_t nthreads) {
LOG_INFO(m_logger) << "run(): Launching " << nthreads << " workers" << LOG_END;
LOG_INFO(GetLogger()) << "run(): Launching " << nthreads << " workers" << LOG_END;
// run_topology needs to happen _before_ threads are started so that threads don't quit due to lack of assignments
m_scheduler->run_topology(nthreads);

Expand All @@ -59,7 +55,7 @@ void JArrowProcessingController::run(size_t nthreads) {
size_t next_cpu_id = m_topology->mapping.get_cpu_id(next_worker_id);
size_t next_loc_id = m_topology->mapping.get_loc_id(next_worker_id);
auto worker = new JWorker(this, m_scheduler, next_worker_id, next_cpu_id, next_loc_id, pin_to_cpu);
worker->logger = m_worker_logger;
worker->logger = GetLogger();
m_workers.push_back(worker);
next_worker_id++;
}
Expand All @@ -73,14 +69,14 @@ void JArrowProcessingController::run(size_t nthreads) {

void JArrowProcessingController::scale(size_t nthreads) {

LOG_INFO(m_logger) << "scale(): Stopping all running workers" << LOG_END;
LOG_INFO(GetLogger()) << "scale(): Stopping all running workers" << LOG_END;
m_scheduler->request_topology_pause();
for (JWorker* worker : m_workers) {
worker->wait_for_stop();
}
m_scheduler->achieve_topology_pause();

LOG_INFO(m_logger) << "scale(): All workers are stopped" << LOG_END;
LOG_INFO(GetLogger()) << "scale(): All workers are stopped" << LOG_END;
bool pin_to_cpu = (m_topology->mapping.get_affinity() != JProcessorMapping::AffinityStrategy::None);
size_t next_worker_id = m_workers.size();

Expand All @@ -90,12 +86,12 @@ void JArrowProcessingController::scale(size_t nthreads) {
size_t next_loc_id = m_topology->mapping.get_loc_id(next_worker_id);

auto worker = new JWorker(this, m_scheduler, next_worker_id, next_cpu_id, next_loc_id, pin_to_cpu);
worker->logger = m_worker_logger;
worker->logger = GetLogger();
m_workers.push_back(worker);
next_worker_id++;
}

LOG_INFO(m_logger) << "scale(): Restarting " << nthreads << " workers" << LOG_END;
LOG_INFO(GetLogger()) << "scale(): Restarting " << nthreads << " workers" << LOG_END;
// topology->run needs to happen _before_ threads are started so that threads don't quit due to lack of assignments
m_scheduler->run_topology(nthreads);

Expand Down Expand Up @@ -232,12 +228,12 @@ JArrowMetrics::Status JArrowProcessingController::execute_arrow(int arrow_index)

void JArrowProcessingController::print_report() {
auto metrics = measure_performance();
LOG_INFO(m_logger) << "Running" << *metrics << LOG_END;
LOG_INFO(GetLogger()) << "Running" << *metrics << LOG_END;
}

void JArrowProcessingController::print_final_report() {
auto metrics = measure_performance();
LOG_INFO(m_logger) << "Final Report" << *metrics << LOG_END;
LOG_INFO(GetLogger()) << "Final Report" << *metrics << LOG_END;
}

std::unique_ptr<const JPerfSummary> JArrowProcessingController::measure_performance() {
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/JANA/Engine/JArrowProcessingController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
#include <JANA/Topology/JTopologyBuilder.h>
#include <JANA/Engine/JWorker.h>
#include <JANA/Engine/JPerfSummary.h>
#include <JANA/JService.h>

#include <vector>

class JArrowProcessingController : public JService {
public:

JArrowProcessingController() {
SetPrefix("jana");
}
~JArrowProcessingController() override;
void acquire_services(JServiceLocator *) override;

Expand Down Expand Up @@ -53,9 +57,5 @@ class JArrowProcessingController : public JService {
JScheduler* m_scheduler = nullptr;

std::vector<JWorker*> m_workers;
JLogger m_logger;
JLogger m_worker_logger;
JLogger m_scheduler_logger;

};

2 changes: 1 addition & 1 deletion src/libraries/JANA/JApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void JApplication::Initialize() {
auto topology_builder = m_service_locator->get<JTopologyBuilder>();

// Set logger on JApplication itself
m_logger = m_params->GetLogger("JApplication");
m_logger = m_params->GetLogger("jana");
m_logger.show_classname = false;

// Set up wiring
Expand Down
4 changes: 3 additions & 1 deletion src/libraries/JANA/Services/JComponentManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <JANA/JEventUnfolder.h>
#include <JANA/Utils/JAutoActivator.h>

JComponentManager::JComponentManager() {}
JComponentManager::JComponentManager() {
SetPrefix("jana");
}

JComponentManager::~JComponentManager() {

Expand Down
7 changes: 1 addition & 6 deletions src/libraries/JANA/Services/JParameterManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ using namespace std;

/// @brief Default constructor
JParameterManager::JParameterManager() {
// Set the logger temporarily
m_logger = GetLogger("JParameterManager");

// Short-circuit JParameterManager::DoInit()
// Otherwise there is a cycle when initializing JParameterManager and JLoggingService
this->m_status = Status::Initialized;
SetLoggerName("jana");
}

/// @brief Copy constructor
Expand Down
4 changes: 3 additions & 1 deletion src/libraries/JANA/Services/JPluginLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class JPluginLoader : public JService {

public:

JPluginLoader() = default;
JPluginLoader() {
SetPrefix("jana");
}
~JPluginLoader() override = default;
void Init() override;

Expand Down
13 changes: 7 additions & 6 deletions src/libraries/JANA/Topology/JTopologyBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
using Event = std::shared_ptr<JEvent>;
using EventQueue = JMailbox<Event*>;

JTopologyBuilder::JTopologyBuilder() {
SetPrefix("jana");
}

JTopologyBuilder::~JTopologyBuilder() {
for (auto arrow : arrows) {
delete arrow;
Expand Down Expand Up @@ -105,12 +109,12 @@ void JTopologyBuilder::create_topology() {
}
int id=0;
for (auto* queue : queues) {
queue->set_logger(m_queue_logger);
queue->set_logger(GetLogger());
queue->set_id(id);
id += 1;
}
for (auto* arrow : arrows) {
arrow->set_logger(m_arrow_logger);
arrow->set_logger(GetLogger());
}
}

Expand Down Expand Up @@ -153,9 +157,6 @@ void JTopologyBuilder::acquire_services(JServiceLocator *sl) {
m_params->SetDefaultParameter("jana:locality", m_locality,
"Constrain memory locality. 0=No constraint. 1=Events stay on the same socket. 2=Events stay on the same NUMA domain. 3=Events stay on same core. 4=Events stay on same cpu/hyperthread.")
->SetIsAdvanced(true);

m_arrow_logger = m_params->GetLogger("JArrow");
m_queue_logger = m_params->GetLogger("JQueue");
};


Expand Down Expand Up @@ -214,7 +215,7 @@ void JTopologyBuilder::attach_lower_level(JEventLevel current_level, JUnfoldArro
auto* proc_arrow = new JEventProcessorArrow(ss.str()+"Tap", q1, q2, nullptr);
arrows.push_back(proc_arrow);
proc_arrow->set_chunksize(m_event_processor_chunksize);
proc_arrow->set_logger(m_arrow_logger);
proc_arrow->set_logger(GetLogger());
if (found_sink) {
proc_arrow->set_is_sink(false);
}
Expand Down
6 changes: 1 addition & 5 deletions src/libraries/JANA/Topology/JTopologyBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,9 @@ class JTopologyBuilder : public JService {
JPerfMetrics metrics;
JProcessorMapping mapping;

JLogger m_arrow_logger;
JLogger m_queue_logger;

public:

JTopologyBuilder() = default;

JTopologyBuilder();
~JTopologyBuilder() override;

void acquire_services(JServiceLocator *sl) override;
Expand Down

0 comments on commit 88279e9

Please sign in to comment.