/** * Dump the broker heap so it can be viewed for debugging. * @param dest - stream destination to write the information to * @return completion code, success == 0 */ int Broker_dumpHeap(char* dest) { FILE* file = NULL; int rc = 0; if ((file = Log_destToFile(dest)) == NULL) rc = -1; else { Sockets* sockets = Socket_getSockets(); int ssize = sizeof(Sockets); int bssize = sizeof(BrokerStates); int mpsize = sizeof(MQTTProtocol); MQTTProtocol* mp = MQTTProtocol_getState(); fprintf(file, "=========== Start of heap dump ==========\n"); if (fwrite(&bssize, sizeof(bssize), 1, file) != 1) /* write size of Broker state Structure */ rc = -1; else if (fwrite(&BrokerState, bssize, 1, file) != 1) /* write Broker state Structure */ rc = -1; else if (fwrite(&config, sizeof(config), 1, file) != 1) rc = -1; else if (fwrite(&ssize, sizeof(ssize), 1, file) != 1) rc = -1; else if (fwrite(sockets, ssize, 1, file) != 1) rc = -1; else if (fwrite(&mpsize, sizeof(mpsize), 1, file) != 1) /* write size of MQTTProtocol state structure */ rc = -1; else if (fwrite(mp, mpsize, 1, file) != 1) /* write MQTTProtocol state structure */ rc = -1; else if (HeapDumpString(file, config) != 0) rc = -1; else if (HeapDumpString(file, BrokerState.version) != 0) rc = -1; else if (HeapDumpString(file, BrokerState.timestamp) != 0) rc = -1; else if (HeapDumpString(file, BrokerState.persistence_location) != 0) rc = -1; else rc = HeapDump(file); fprintf(file, "\n=========== End of heap dump ==========\n\n"); if (file != stdout && file != stderr) fclose(file); } return rc; }
/** * Dump the broker heap so it can be viewed for debugging. * @param dest - stream destination to write the information to * @return completion code, success == 0 */ int Broker_dumpHeap(char* dest) { FILE* file = NULL; int rc = 0; if ((file = Log_destToFile(dest)) == NULL) rc = -1; else { List* log = Log_getLogBuffer(); List* trace = Log_getTraceBuffer(); Sockets* sockets = Socket_getSockets(); int ssize = sizeof(Sockets); int bssize = sizeof(BrokerStates); fprintf(file, "=========== Start of heap dump ==========\n"); if (fwrite(&bssize, sizeof(bssize), 1, file) != 1) rc = -1; else if (fwrite(&BrokerState, bssize, 1, file) != 1) rc = -1; else if (fwrite(&log, sizeof(log), 1, file) != 1) rc = -1; else if (fwrite(&trace, sizeof(trace), 1, file) != 1) rc = -1; else if (fwrite(&config, sizeof(config), 1, file) != 1) rc = -1; else if (fwrite(&ssize, sizeof(ssize), 1, file) != 1) rc = -1; else if (fwrite(sockets, ssize, 1, file) != 1) rc = -1; else if (HeapDumpString(file, config) != 0) rc = -1; else if (HeapDumpString(file, BrokerState.version) != 0) rc = -1; else if (HeapDumpString(file, BrokerState.persistence_location) != 0) rc = -1; else rc = HeapDump(file); fprintf(file, "\n=========== End of heap dump ==========\n\n"); if (file != stdout && file != stderr) fclose(file); } return rc; }