Changeset 8441 for trunk/psLib/src/sys/psTrace.c
- Timestamp:
- Aug 21, 2006, 12:11:39 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psTrace.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psTrace.c
r8416 r8441 9 9 * @author GLG, MHPCC 10 10 * 11 * @version $Revision: 1. 69$ $Name: not supported by cvs2svn $12 * @date $Date: 2006-08- 18 02:24:13$11 * @version $Revision: 1.70 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2006-08-21 22:11:39 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 38 38 *****************************************************************************/ 39 39 40 41 // NOTE: We want to avoid using the psString functions, or any function that calls the PS memory management,42 // since there seems to be a problem with memory fragmentation. Since psTrace can get called a LOT, it43 // manifests this problem. To get around this, we will use variable length char arrays, instead of the44 // psString functions. This can be revised once the PS memory management system is fixed.45 #define USE_PS_MEMORY 046 47 48 40 #ifndef PS_NO_TRACE 49 41 … … 61 53 #include "psLogMsg.h" 62 54 55 #define MAX_HOSTNAME_LENGTH 256 56 #define MAX_HEADER_LENGTH 256 63 57 64 58 … … 414 408 // If the component name has no leading dot, then supply it. 415 409 if (name[0] != '.') { 416 #if USE_PS_MEMORY417 psString compName = (char *) psAlloc(10 + strlen(name));418 strcpy(compName, ".");419 compName = strcat(compName, name);420 #else421 422 410 char compName[strlen(name) + 2]; 423 411 compName[0] = '.'; 424 412 strcpy(&compName[1], name); 425 #endif426 413 427 414 traceLevel = doGetTraceLevel(compName); 428 #if USE_PS_MEMORY429 430 psFree(compName);431 #endif432 433 415 } else { 434 416 // Search the component root tree, determine the trace level. … … 520 502 va_list ap) 521 503 { 522 // char *fmt = NULL; 523 // va_list ap; 524 static psS32 first = 1; // Flag for calling gethostname() 525 static char hostname[256 + 1]; 526 char clevel = 0; // letter-name for level 527 psS32 i = 0; 528 char head[256 + 2]; // the added two are for the ending | and \0 529 char *head_ptr = head; // where we've got to in head 530 psS32 maxLength = 256; 531 time_t clock = time(NULL); // The current time. 532 struct tm *utc = gmtime(&clock); // The current gm time. 504 PS_ASSERT_PTR_NON_NULL(comp, ); 505 PS_ASSERT_PTR_NON_NULL(format, ); 533 506 534 507 // XXX EAM : fd < 1 does not print messages 535 if (traceFD < 1) 508 if (traceFD < 1) { 536 509 return; 537 538 if (NULL == comp) { 539 psError(PS_ERR_BAD_PARAMETER_NULL, true, 540 _("Function %s called on a NULL trace level tree."), 541 __func__); 542 return; 543 } 544 510 } 511 512 static bool first = true; // First time we've been called? 513 static char hostname[MAX_HOSTNAME_LENGTH + 1]; // Host name 545 514 if (first) { 546 first = 0;515 first = false; 547 516 gethostname(hostname, 256); 548 517 } 549 518 550 if (level == PS_LOG_ABORT) { 519 char clevel = 0; // letter-name for level 520 switch (level) { 521 case PS_LOG_ABORT: 551 522 clevel = 'A'; 552 } else if (level == PS_LOG_ERROR) { 523 break; 524 case PS_LOG_ERROR: 553 525 clevel = 'E'; 554 } else if (level == PS_LOG_WARN) { 526 break; 527 case PS_LOG_WARN: 555 528 clevel = 'W'; 556 } else if (level == PS_LOG_INFO) { 529 break; 530 case PS_LOG_INFO: 557 531 clevel = 'I'; 558 } else if (level >= 4) { 559 clevel = level + '0'; 560 } else { 561 psTrace("psLib.sys", 2, "Invalid logMsg level: %d (%s)\n", level, format); 562 level = (level < 0) ? 0 : 9; 563 clevel = level + '0'; 532 break; 533 default: 534 if (level >= 4) { 535 clevel = level + '0'; 536 } else { 537 psTrace("psLib.sys", 2, "Invalid logMsg level: %d (%s)\n", level, format); 538 level = (level < 0) ? 0 : 9; 539 clevel = level + '0'; 540 } 564 541 } 565 542 … … 567 544 // of it's associatedcomponent. 568 545 if (level <= psTraceGetLevel(comp)) { 569 // va_start(ap, format); 546 int maxLength = MAX_HEADER_LENGTH; // Maximum length of header string 547 char head[maxLength + 2]; // the added two are for the ending | and \0 548 char *head_ptr = head; // where we've got to in head 570 549 571 550 // Create the various log fields... 572 551 if (traceTime) { 552 time_t clock = time(NULL); // The current time. 553 struct tm *utc = gmtime(&clock); // The current gm time. 573 554 maxLength -= snprintf(head_ptr, maxLength, "%4d:%02d:%02d %02d:%02d:%02dZ", 574 555 utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday, … … 607 588 *head_ptr = '\0'; 608 589 609 write (traceFD, head, strlen(head));590 write(traceFD, head, strlen(head)); 610 591 611 592 if (traceMsg) { 612 593 char line[1024]; 613 594 614 // The following functions get the variable list of parameters with615 // which this function was called, and print them to the standard616 // output.617 // fmt = va_arg(ap, char *);618 619 595 // We indent each message one space for each level of the message. 620 for (i = 0; i < level; i++) {596 for (int i = 0; i < level; i++) { 621 597 write (traceFD, " ", 1); 622 598 } … … 630 606 } 631 607 632 633 } 634 608 // XXX: what is fd-appropriate equivalent of fflush? 609 } 635 610 } 636 611 … … 665 640 666 641 // XXX file & lineo are currently unused 667 va_list ap; 668 va_start(ap, format); 669 // format = va_arg(ap, char *); 670 671 #if USE_PS_MEMORY 672 673 psString fullFacil = NULL; 674 psStringAppend(&fullFacil, "%s.%s", facil, func); 675 #else 676 642 643 // Append the function name to the facility 677 644 size_t facilLength = strlen(facil); // Length of facility name 678 645 size_t funcLength = strlen(func); // Length of function name … … 681 648 fullFacil[facilLength] = '.'; 682 649 strcpy(&fullFacil[facilLength + 1], func); 683 #endif 684 650 651 va_list ap; 652 va_start(ap, format); 685 653 psTraceV(fullFacil, level, format, ap); 686 #if USE_PS_MEMORY687 688 psFree(fullFacil);689 #endif690 691 654 va_end(ap); 692 // fflush(traceFP);693 // XXX EAM : what is fd-appropriate equivalent?694 655 } 695 656
Note:
See TracChangeset
for help on using the changeset viewer.
