Skip to content

Commit 4716563

Browse files
authored
Actually build the LDMS service (#538)
1 parent 209a2b3 commit 4716563

File tree

3 files changed

+35
-54
lines changed

3 files changed

+35
-54
lines changed

caliper-config.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#cmakedefine CALIPER_HAVE_ROCTRACER
2525
#cmakedefine CALIPER_HAVE_UMPIRE
2626
#cmakedefine CALIPER_HAVE_CRAYPAT
27+
#cmakedefine CALIPER_HAVE_LDMS
2728

2829
#cmakedefine CALIPER_REDUCED_CONSTEXPR_USAGE
2930

src/services/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ endif()
115115
if (CALIPER_HAVE_CRAYPAT)
116116
add_subdirectory(craypat)
117117
endif()
118+
if (CALIPER_HAVE_LDMS)
119+
add_subdirectory(ldms)
120+
endif()
118121
if (CALIPER_HAVE_MPI)
119122
include_directories(${MPI_CXX_INCLUDE_PATH})
120123
add_subdirectory(mpireport)

src/services/ldms/LdmsForwarder.cpp

+31-54
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ldms_t setup_connection(const char *xprt, const char *host,
9494
ts.tv_nsec = 0;
9595
}
9696

97-
ldms_g = ldms_xprt_new_with_auth(xprt, auth, NULL);
97+
ldms_g = ldms_xprt_new_with_auth(xprt, NULL, auth, NULL);
9898
if (!ldms_g) {
9999
printf("Error %d creating the '%s' transport\n",
100100
errno, xprt);
@@ -127,8 +127,8 @@ void caliper_ldms_connector_initialize()
127127
/* Check/set LDMS transport type */
128128
if (!env_ldms_xprt || !env_ldms_host || !env_ldms_port || !env_ldms_auth){
129129
Log(1).stream() << "Either the transport, host, port or authentication is not given. Setting to default.\n";
130-
131-
if (env_ldms_xprt == NULL)
130+
131+
if (env_ldms_xprt == NULL)
132132
env_ldms_xprt = "sock";
133133

134134
if (env_ldms_host == NULL)
@@ -139,7 +139,7 @@ void caliper_ldms_connector_initialize()
139139

140140
if (env_ldms_auth == NULL)
141141
env_ldms_auth = "munge";
142-
142+
143143
}
144144

145145
pthread_mutex_lock(&ln_lock);
@@ -158,28 +158,26 @@ void caliper_ldms_connector_initialize()
158158
return;
159159
}
160160

161-
std::ostream& write_ldms_record(std::ostream& os, int mpi_rank, RegionProfile& profile)
161+
void write_ldms_record(int mpi_rank, RegionProfile& profile)
162162
{
163-
164-
caliper_ldms_connector_initialize();
163+
caliper_ldms_connector_initialize();
165164

166165
std::map<std::string, double> region_times;
167166
double total_time = 0;
168-
169167

170168
int buffer_size = 4096;
171169
char* buffer = (char*) malloc (sizeof(char) * buffer_size);
172-
170+
173171
const char* env_ldms_jobid_str = getenv("SLURM_JOB_ID");
174172
const char* env_ldms_procid = getenv("SLURM_PROCID");
175173
const char* env_ldms_slurm_nodelist = getenv("SLURM_JOB_NODELIST");
176174
const char* env_ldms_caliper_verbose_str = getenv("CALIPER_LDMS_VERBOSE");
177175

178176
int env_ldms_jobid = env_ldms_jobid_str == NULL ? 0 : atoi( env_ldms_jobid_str );
179-
int env_ldms_caliper_verbose = env_ldms_caliper_verbose_str == NULL ? 0 : atoi( env_ldms_caliper_verbose_str );
177+
int env_ldms_caliper_verbose = env_ldms_caliper_verbose_str == NULL ? 0 : atoi( env_ldms_caliper_verbose_str );
180178

181179
std::tie(region_times, std::ignore, total_time) =
182-
profile.inclusive_path_profile();
180+
profile.inclusive_region_times();
183181

184182
double unix_ts = 1e-6 * std::chrono::duration_cast<std::chrono::microseconds>(
185183
std::chrono::system_clock::now().time_since_epoch()).count();
@@ -189,78 +187,63 @@ std::ostream& write_ldms_record(std::ostream& os, int mpi_rank, RegionProfile& p
189187
if (p.second < 0.05 * total_time)
190188
continue;
191189

192-
os << "{ \"timestamp\": " << std::fixed << unix_ts
193-
<< ", \"duration\": " << std::fixed << p.second;
194-
195-
util::write_esc_string(os << ", \"path\": \"", p.first) << "\"";
196-
197-
std::string path_msg = "" + p.first;
198-
std::string path = path_msg.c_str();
190+
// std::string path_msg = "" + p.first;
191+
const char* path = p.first.c_str();
199192

200193
if (mpi_rank >= 0) {
201-
os << ", \"rank\": " << mpi_rank;
202-
snprintf(buffer, buffer_size, "{ \"timestamp\": %f, \"jobid\" : %d, \"rank\" : %d, \"procid\" : %d, \"nodelist\" : %s, \"caliper-perf-data\", \"duration\": %f, \"path\": \"%s\"} \n", unix_ts, env_ldms_jobid, mpi_rank, env_ldms_procid, env_ldms_slurm_nodelist, p.second, path);
203-
} else {
204-
snprintf(buffer, buffer_size, "{ \"timestamp\": %f, \"jobid\" : %d, \"rank\": %d, \"procid\" : %d, \"nodelist\" : %s, \"caliper-perf-data\", \"duration\": %f, \"path\": \"%s\"} \n", unix_ts, env_ldms_jobid, 0, env_ldms_procid, env_ldms_slurm_nodelist, p.second, path);
205-
}
206-
os << "} \n";
207-
208-
if (env_ldms_caliper_verbose > 0)
209-
puts(buffer);
194+
snprintf(buffer, buffer_size, "{ \"timestamp\": %f, \"jobid\" : %d, \"rank\" : %d, \"procid\" : %s, \"nodelist\" : %s, \"caliper-perf-data\", \"duration\": %f, \"path\": \"%s\"} \n", unix_ts, env_ldms_jobid, mpi_rank, env_ldms_procid, env_ldms_slurm_nodelist, p.second, path);
195+
} else {
196+
snprintf(buffer, buffer_size, "{ \"timestamp\": %f, \"jobid\" : %d, \"rank\": %d, \"procid\" : %s, \"nodelist\" : %s, \"caliper-perf-data\", \"duration\": %f, \"path\": \"%s\"} \n", unix_ts, env_ldms_jobid, 0, env_ldms_procid, env_ldms_slurm_nodelist, p.second, path);
197+
}
210198

211-
int rc = ldmsd_stream_publish( ldms_cali, "caliper-perf-data", LDMSD_STREAM_JSON, buffer, strlen(buffer) + 1);
212-
if (rc)
213-
Log(0).stream() << "Error " << rc << " publishing data.\n";
199+
if (env_ldms_caliper_verbose > 0)
200+
puts(buffer);
214201

215-
else if (env_ldms_caliper_verbose > 0)
216-
Log(2).stream() << "Caliper Message published successfully\n";
217-
}
202+
int rc = ldmsd_stream_publish( ldms_cali, "caliper-perf-data", LDMSD_STREAM_JSON, buffer, strlen(buffer) + 1);
218203

219-
return os;
204+
if (rc)
205+
Log(0).stream() << "Error " << rc << " publishing data.\n";
206+
else if (env_ldms_caliper_verbose > 0)
207+
Log(2).stream() << "Caliper Message published successfully\n";
208+
}
220209
}
221210

222211
class LdmsForwarder
223212
{
224213
RegionProfile profile;
225-
OutputStream stream;
226-
227-
std::string filename;
228214

229215
void snapshot(Caliper* c, Channel*) {
230216
Entry e = c->get(c->get_attribute("mpi.rank"));
231217
int rank = e.empty() ? -1 : e.value().to_int();
232218

233-
write_ldms_record(*stream.stream(), rank, profile) << "\n";
219+
write_ldms_record(rank, profile);
234220

235221
profile.clear(); // reset profile - skip to create a cumulative profile
236222
}
237223

238224
void post_init(Caliper* c, Channel* channel) {
239-
std::vector<Entry> rec;
240-
stream.set_filename(filename.c_str(), *c, rec);
241225
profile.start();
242226
}
243227

244-
LdmsForwarder(const char* fname)
245-
: filename { fname }
228+
LdmsForwarder()
246229
{ }
247230

248231
public:
249-
232+
250233
static const char* s_spec;
251234

252235
static void create(Caliper* c, Channel* channel) {
253-
ConfigSet cfg =
236+
ConfigSet cfg =
254237
services::init_config_from_spec(channel->config(), s_spec);
255238

256-
LdmsForwarder* instance = new LdmsForwarder(cfg.get("filename").to_string().c_str());
239+
LdmsForwarder* instance = new LdmsForwarder();
257240

258241
channel->events().post_init_evt.connect(
259242
[instance](Caliper* c, Channel* channel){
260243
instance->post_init(c, channel);
261244
});
262245
channel->events().snapshot.connect(
263-
[instance](Caliper* c, Channel* channel, int scope, SnapshotView, SnapshotBuilder&){
246+
[instance](Caliper* c, Channel* channel, SnapshotView, SnapshotBuilder&){
264247
instance->snapshot(c, channel);
265248
});
266249
channel->events().finish_evt.connect(
@@ -271,21 +254,15 @@ class LdmsForwarder
271254
Log(1).stream() << channel->name() << "Initialized LDMS forwarder\n";
272255
}
273256

274-
257+
275258
};
276259

277260
const char* LdmsForwarder::s_spec = R"json(
278-
{
261+
{
279262
"name" : "ldms",
280263
"description" : "Forward Caliper regions to LDMS (prototype)",
281264
"config" :
282265
[
283-
{
284-
"name" : "filename",
285-
"description" : "Output file name, or stdout/stderr",
286-
"type" : "string",
287-
"value" : "stdout"
288-
}
289266
]
290267
}
291268
)json";

0 commit comments

Comments
 (0)