Changeset 3330 for trunk/packages/vizservers/pymolproxy
- Timestamp:
- Feb 24, 2013 1:11:18 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/pymolproxy/pymolproxy2.c
r3177 r3330 113 113 114 114 #define IO_TIMEOUT (30000) 115 #define KEEPSTATS 1 115 #define STATSDIR "/var/tmp/visservers" 116 #define STATSFILE STATSDIR "/" "pymol_log.tcl" 117 #define LOCKFILE STATSDIR "/" "LCK..pymol" 116 118 #define CVT2SECS(x) ((double)(x).tv_sec) + ((double)(x).tv_usec * 1.0e-6) 117 119 118 120 typedef struct { 119 121 pid_t pid; /* Child process. */ 120 size_t n Frames; /* # of frames sent to client. */121 size_t n Bytes; /* # of bytes for all frames. */122 size_t n Commands; /* # of commands executed */122 size_t numFrames; /* # of frames sent to client. */ 123 size_t numBytes; /* # of bytes for all frames. */ 124 size_t numCommands; /* # of commands executed */ 123 125 double cmdTime; /* Elapsed time spend executing 124 126 * commands. */ … … 138 140 * the pymol server to the least. */ 139 141 int id; 140 ssize_t n Written; /* Number of bytes of image data142 ssize_t numWritten; /* Number of bytes of image data 141 143 * already delivered.*/ 142 144 size_t bytesLeft; /* Number of bytes of image data left … … 270 272 271 273 static int 272 Send Cmd(PymolProxy *proxyPtr, const char *format, ...)274 SendToPymol(PymolProxy *proxyPtr, const char *format, ...) 273 275 { 274 276 va_list ap; 275 277 char buffer[BUFSIZ]; 276 278 int result; 277 ssize_t n Written;279 ssize_t numWritten; 278 280 size_t length; 279 281 … … 295 297 /* Write the command out to the server. */ 296 298 length = strlen(buffer); 297 n Written = write(proxyPtr->sin, buffer, length);298 if (n Written != length) {299 numWritten = write(proxyPtr->sin, buffer, length); 300 if (numWritten != length) { 299 301 ERROR("short write to pymol (wrote=%d, should have been %d): %s", 300 nWritten, length, strerror(errno)); 301 } 302 numWritten, length, strerror(errno)); 303 } 304 proxyPtr->status = result; 302 305 return proxyPtr->status; 303 306 } … … 543 546 } 544 547 548 static int 549 GetFileLock() 550 { 551 int numTries; 552 553 for (numTries = 0; numTries < 10; numTries++) { 554 int f; 555 556 f = open(LOCKFILE, O_TRUNC | O_CREAT | O_EXCL | O_WRONLY, 0600); 557 if (f >= 0) { 558 char buf[200]; 559 ssize_t numWritten; 560 size_t numBytes; 561 562 sprintf(buf, "%d\n", getpid()); 563 numBytes = strlen(buf); 564 numWritten = write(f, buf, numBytes); 565 if (numWritten != (ssize_t)numBytes) { 566 ERROR("Wrote short lock file"); 567 } 568 close(f); 569 return 0; 570 } 571 sleep(1); /* Wait for lock to release. */ 572 } 573 ERROR("Failed to open lock file"); 574 return -1; 575 } 576 577 static void 578 ReleaseFileLock() 579 { 580 unlink(LOCKFILE); 581 } 582 583 static int 584 WriteToStatsFile(const char *s, size_t length) 585 { 586 int f; 587 588 if (access(STATSDIR, X_OK) != 0) { 589 mkdir(STATSDIR, 0770); 590 } 591 if (GetFileLock() < 0) { 592 return -1; 593 } 594 f = open(STATSFILE, O_APPEND | O_CREAT | O_WRONLY, 0600); 595 ReleaseFileLock(); 596 if (f < 0) { 597 return -1; 598 } 599 if (write(f, s, length) != (ssize_t)length) { 600 close(f); 601 return -1; 602 } 603 close(f); 604 return 0; 605 } 606 607 static int 608 ServerStats(int code) 609 { 610 double start, finish; 611 char buf[BUFSIZ]; 612 Tcl_DString ds; 613 int result; 614 615 { 616 struct timeval tv; 617 618 /* Get ending time. */ 619 gettimeofday(&tv, NULL); 620 finish = CVT2SECS(tv); 621 tv = stats.start; 622 start = CVT2SECS(tv); 623 } 624 /* 625 * Session information: 626 * - Name of render server 627 * - Process ID 628 * - Hostname where server is running 629 * - Start date of session 630 * - Start date of session in seconds 631 * - Number of frames returned 632 * - Number of bytes total returned (in frames) 633 * - Number of commands received 634 * - Total elapsed time of all commands 635 * - Total elapsed time of session 636 * - Exit code of vizserver 637 * - User time 638 * - System time 639 * - User time of children 640 * - System time of children 641 */ 642 643 Tcl_DStringInit(&ds); 644 645 Tcl_DStringAppendElement(&ds, "render_stop"); 646 /* renderer */ 647 Tcl_DStringAppendElement(&ds, "renderer"); 648 Tcl_DStringAppendElement(&ds, "pymol"); 649 /* pid */ 650 Tcl_DStringAppendElement(&ds, "pid"); 651 sprintf(buf, "%d", getpid()); 652 Tcl_DStringAppendElement(&ds, buf); 653 /* host */ 654 Tcl_DStringAppendElement(&ds, "host"); 655 gethostname(buf, BUFSIZ-1); 656 buf[BUFSIZ-1] = '\0'; 657 Tcl_DStringAppendElement(&ds, buf); 658 /* date */ 659 Tcl_DStringAppendElement(&ds, "date"); 660 strcpy(buf, ctime(&stats.start.tv_sec)); 661 buf[strlen(buf) - 1] = '\0'; 662 Tcl_DStringAppendElement(&ds, buf); 663 /* date_secs */ 664 Tcl_DStringAppendElement(&ds, "date_secs"); 665 sprintf(buf, "%ld", stats.start.tv_sec); 666 Tcl_DStringAppendElement(&ds, buf); 667 /* num_frames */ 668 Tcl_DStringAppendElement(&ds, "num_frames"); 669 sprintf(buf, "%lu", (unsigned long int)stats.numFrames); 670 Tcl_DStringAppendElement(&ds, buf); 671 /* frame_bytes */ 672 Tcl_DStringAppendElement(&ds, "frame_bytes"); 673 sprintf(buf, "%lu", (unsigned long int)stats.numBytes); 674 Tcl_DStringAppendElement(&ds, buf); 675 /* num_commands */ 676 Tcl_DStringAppendElement(&ds, "num_commands"); 677 sprintf(buf, "%lu", (unsigned long int)stats.numCommands); 678 Tcl_DStringAppendElement(&ds, buf); 679 /* cmd_time */ 680 Tcl_DStringAppendElement(&ds, "cmd_time"); 681 sprintf(buf, "%g", stats.cmdTime); 682 Tcl_DStringAppendElement(&ds, buf); 683 /* session_time */ 684 Tcl_DStringAppendElement(&ds, "session_time"); 685 sprintf(buf, "%g", finish - start); 686 Tcl_DStringAppendElement(&ds, buf); 687 /* status */ 688 Tcl_DStringAppendElement(&ds, "status"); 689 sprintf(buf, "%d", code); 690 Tcl_DStringAppendElement(&ds, buf); 691 { 692 long clocksPerSec = sysconf(_SC_CLK_TCK); 693 double clockRes = 1.0 / clocksPerSec; 694 struct tms tms; 695 696 memset(&tms, 0, sizeof(tms)); 697 times(&tms); 698 /* utime */ 699 Tcl_DStringAppendElement(&ds, "utime"); 700 sprintf(buf, "%g", tms.tms_utime * clockRes); 701 Tcl_DStringAppendElement(&ds, buf); 702 /* stime */ 703 Tcl_DStringAppendElement(&ds, "stime"); 704 sprintf(buf, "%g", tms.tms_stime * clockRes); 705 Tcl_DStringAppendElement(&ds, buf); 706 /* cutime */ 707 Tcl_DStringAppendElement(&ds, "cutime"); 708 sprintf(buf, "%g", tms.tms_cutime * clockRes); 709 Tcl_DStringAppendElement(&ds, buf); 710 /* cstime */ 711 Tcl_DStringAppendElement(&ds, "cstime"); 712 sprintf(buf, "%g", tms.tms_cstime * clockRes); 713 Tcl_DStringAppendElement(&ds, buf); 714 } 715 Tcl_DStringAppend(&ds, "\n", -1); 716 result = WriteToStatsFile(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds)); 717 Tcl_DStringFree(&ds); 718 return result; 719 } 720 545 721 546 722 static int … … 579 755 } 580 756 if (bool) { 581 Send Cmd(p, "show cartoon,%s\n", model);757 SendToPymol(p, "show cartoon,%s\n", model); 582 758 } else { 583 Send Cmd(p, "hide cartoon,%s\n", model);759 SendToPymol(p, "hide cartoon,%s\n", model); 584 760 } 585 761 return p->status; … … 619 795 p->flags |= FORCE_UPDATE; 620 796 } 621 Send Cmd(p, "set cartoon_trace,%d,%s\n", bool, model);797 SendToPymol(p, "set cartoon_trace,%d,%s\n", bool, model); 622 798 return p->status; 623 799 } … … 649 825 p->flags |= FORCE_UPDATE; 650 826 } 651 Send Cmd(p, "disable %s\n", model);827 SendToPymol(p, "disable %s\n", model); 652 828 return p->status; 653 829 } … … 681 857 p->flags |= FORCE_UPDATE; 682 858 } 683 Send Cmd(p, "enable %s\n", model);859 SendToPymol(p, "enable %s\n", model); 684 860 return p->status; 685 861 } … … 714 890 /* Does not invalidate cache? */ 715 891 716 Send Cmd(p,"frame %d\n", frame);892 SendToPymol(p,"frame %d\n", frame); 717 893 return p->status; 718 894 } 719 895 896 /* 897 * ClientInfoCmd -- 898 * 899 * info "hub" value "session" value "date" value name value name value 900 * 901 */ 902 static int 903 ClientInfoCmd(ClientData clientData, Tcl_Interp *interp, int argc, 904 const char *argv[]) 905 { 906 Tcl_DString ds; 907 int result; 908 int i; 909 char buf[BUFSIZ]; 910 911 Tcl_DStringInit(&ds); 912 Tcl_DStringAppendElement(&ds, "render_start"); 913 /* renderer */ 914 Tcl_DStringAppendElement(&ds, "renderer"); 915 Tcl_DStringAppendElement(&ds, "nanovis"); 916 /* pid */ 917 Tcl_DStringAppendElement(&ds, "pid"); 918 sprintf(buf, "%d", getpid()); 919 Tcl_DStringAppendElement(&ds, buf); 920 /* host */ 921 Tcl_DStringAppendElement(&ds, "host"); 922 gethostname(buf, BUFSIZ-1); 923 buf[BUFSIZ-1] = '\0'; 924 Tcl_DStringAppendElement(&ds, buf); 925 /* date */ 926 Tcl_DStringAppendElement(&ds, "date"); 927 strcpy(buf, ctime(&stats.start.tv_sec)); 928 buf[strlen(buf) - 1] = '\0'; 929 Tcl_DStringAppendElement(&ds, buf); 930 /* date_secs */ 931 Tcl_DStringAppendElement(&ds, "date_secs"); 932 sprintf(buf, "%ld", stats.start.tv_sec); 933 Tcl_DStringAppendElement(&ds, buf); 934 /* Client arguments. */ 935 for (i = 1; i < argc; i++) { 936 Tcl_DStringAppendElement(&ds, argv[i]); 937 } 938 Tcl_DStringAppend(&ds, "\n", 1); 939 result = WriteToStatsFile(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds)); 940 Tcl_DStringFree(&ds); 941 return result; 942 } 720 943 721 944 static int … … 756 979 p->flags |= FORCE_UPDATE; 757 980 } 758 Send Cmd(p, "set label_color,white,%s\nset label_size,%d,%s\n",981 SendToPymol(p, "set label_color,white,%s\nset label_size,%d,%s\n", 759 982 model, size, model); 760 983 if (bool) { 761 Send Cmd(p, "label %s,\"%%s%%s\" %% (ID,name)\n", model);984 SendToPymol(p, "label %s,\"%%s%%s\" %% (ID,name)\n", model); 762 985 } else { 763 Send Cmd(p, "label %s\n", model);986 SendToPymol(p, "label %s\n", model); 764 987 } 765 988 return p->status; … … 809 1032 if (argc < 4) { 810 1033 Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], 811 " <data>|follows <model> <state> ?<n Bytes>?\"",1034 " <data>|follows <model> <state> ?<numBytes>?\"", 812 1035 (char *)NULL); 813 1036 return TCL_ERROR; … … 825 1048 if (argc != 5) { 826 1049 Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0], 827 " follows <model> <state> <n Bytes>\"", (char *)NULL);1050 " follows <model> <state> <numBytes>\"", (char *)NULL); 828 1051 return TCL_ERROR; 829 1052 } … … 865 1088 { 866 1089 int f; 867 ssize_t n Written;1090 ssize_t numWritten; 868 1091 char fileName[200]; 869 1092 … … 876 1099 goto error; 877 1100 } 878 n Written = write(f, string, numBytes);879 if (numBytes != n Written) {1101 numWritten = write(f, string, numBytes); 1102 if (numBytes != numWritten) { 880 1103 Tcl_AppendResult(interp, "can't write PDB data to \"", 881 1104 fileName, "\": ", Tcl_PosixError(interp), (char *)NULL); … … 884 1107 } 885 1108 close(f); 886 SendCmd(p, "loadandremovepdbfile %s,%s,%d\n", fileName, name, state); 1109 SendToPymol(p, "loadandremovepdbfile %s,%s,%d\n", fileName, name, 1110 state); 887 1111 p->status = TCL_OK; 888 1112 } … … 922 1146 p->flags |= FORCE_UPDATE; 923 1147 } 924 Send Cmd(p, "set orthoscopic=%d\n", bool);1148 SendToPymol(p, "set orthoscopic=%d\n", bool); 925 1149 return p->status; 926 1150 } … … 985 1209 986 1210 /* Force pymol to update the current scene. */ 987 Send Cmd(p, "refresh\n");1211 SendToPymol(p, "refresh\n"); 988 1212 /* This is a hack. We're encoding the filename to pass extra information 989 1213 * to the MyPNGWrite routine inside of pymol. Ideally these would be … … 993 1217 * The extra information is contained in the token we get from the 994 1218 * molvisviewer client, the frame number, and rock offset. */ 995 Send Cmd(p, "png -:%d:%d:%d\n", p->cacheId, p->frame, p->rockOffset);1219 SendToPymol(p, "png -:%d:%d:%d\n", p->cacheId, p->frame, p->rockOffset); 996 1220 return p->status; 997 1221 } … … 1006 1230 1007 1231 /* Force pymol to update the current scene. */ 1008 Send Cmd(p, "refresh\n");1232 SendToPymol(p, "refresh\n"); 1009 1233 /* This is a hack. We're encoding the filename to pass extra information 1010 1234 * to the MyPNGWrite routine inside of pymol. Ideally these would be … … 1014 1238 * The extra information is contained in the token we get from the 1015 1239 * molvisviewer client, the frame number, and rock offset. */ 1016 Send Cmd(p, "png -:%d:%d:%d,format=1\n", p->cacheId, p->frame,1240 SendToPymol(p, "png -:%d:%d:%d,format=1\n", p->cacheId, p->frame, 1017 1241 p->rockOffset); 1018 1242 p->flags &= ~(UPDATE_PENDING|FORCE_UPDATE); … … 1046 1270 /* Force pymol to update the current scene. */ 1047 1271 if (strcmp(bgcolor, "none") == 0) { 1048 Send Cmd(p, "set ray_opaque_background,off\n");1049 Send Cmd(p, "refresh\n", bgcolor);1272 SendToPymol(p, "set ray_opaque_background,off\n"); 1273 SendToPymol(p, "refresh\n", bgcolor); 1050 1274 } else { 1051 Send Cmd(p, "set ray_opaque_background,on\n");1052 Send Cmd(p, "bg_color %s\nrefresh\n", bgcolor);1275 SendToPymol(p, "set ray_opaque_background,on\n"); 1276 SendToPymol(p, "bg_color %s\nrefresh\n", bgcolor); 1053 1277 } 1054 1278 /* This is a hack. We're encoding the filename to pass extra information … … 1060 1284 * molvisviewer client, the frame number, and rock offset. 1061 1285 */ 1062 Send Cmd(p, "png -:%s:0:0,width=%d,height=%d,ray=1,dpi=300\n",1286 SendToPymol(p, "png -:%s:0:0,width=%d,height=%d,ray=1,dpi=300\n", 1063 1287 token, width, height); 1064 Send Cmd(p, "bg_color black\n");1288 SendToPymol(p, "bg_color black\n"); 1065 1289 return p->status; 1066 1290 } … … 1093 1317 p->flags |= FORCE_UPDATE; 1094 1318 } 1095 Send Cmd(p,"%s\n", cmd);1319 SendToPymol(p,"%s\n", cmd); 1096 1320 return p->status; 1097 1321 } … … 1120 1344 p->flags |= FORCE_UPDATE; 1121 1345 } 1122 Send Cmd(p, "reset\nzoom complete=1\n");1346 SendToPymol(p, "reset\nzoom complete=1\n"); 1123 1347 return p->status; 1124 1348 } … … 1152 1376 p->flags |= FORCE_UPDATE; 1153 1377 } 1154 Send Cmd(p,"turn y, %f\n", y - p->rockOffset);1378 SendToPymol(p,"turn y, %f\n", y - p->rockOffset); 1155 1379 p->rockOffset = y; 1156 1380 return p->status; … … 1197 1421 } 1198 1422 if (strcmp(rep, "ballnstick") == 0) { /* Ball 'n Stick */ 1199 Send Cmd(p,1423 SendToPymol(p, 1200 1424 "set stick_color,white,%s\n" 1201 1425 "show sticks,%s\n" … … 1205 1429 model, model, model, model, model); 1206 1430 } else if (strcmp(rep, "spheres") == 0) { /* spheres */ 1207 Send Cmd(p,1431 SendToPymol(p, 1208 1432 "hide sticks,%s\n" 1209 1433 "show spheres,%s\n" … … 1214 1438 model, model, model, model, model, model); 1215 1439 } else if (strcmp(rep, "none") == 0) { /* nothing */ 1216 Send Cmd(p,1440 SendToPymol(p, 1217 1441 "hide sticks,%s\n", 1218 1442 "hide spheres,%s\n" … … 1221 1445 model, model, model, model); 1222 1446 } else if (strcmp(rep, "sticks") == 0) { /* sticks */ 1223 Send Cmd(p,1447 SendToPymol(p, 1224 1448 "set stick_color,white,%s\n" 1225 1449 "show sticks,%s\n" … … 1229 1453 model, model, model, model, model); 1230 1454 } else if (strcmp(rep, "lines") == 0) { /* lines */ 1231 Send Cmd(p,1455 SendToPymol(p, 1232 1456 "hide sticks,%s\n" 1233 1457 "hide spheres,%s\n" … … 1236 1460 model, model, model, model); 1237 1461 } else if (strcmp(rep, "cartoon") == 0) { /* cartoon */ 1238 Send Cmd(p,1462 SendToPymol(p, 1239 1463 "hide sticks,%s\n" 1240 1464 "hide spheres,%s\n" … … 1392 1616 p->sphereScale = scale; 1393 1617 } else { 1394 Send Cmd(p, "set sphere_scale,%f,%s\n", scale, model);1618 SendToPymol(p, "set sphere_scale,%f,%s\n", scale, model); 1395 1619 } 1396 1620 return p->status; … … 1434 1658 p->stickRadius = scale; 1435 1659 } else { 1436 Send Cmd(p, "set stick_radius,%f,%s\n", scale, model);1660 SendToPymol(p, "set stick_radius,%f,%s\n", scale, model); 1437 1661 } 1438 1662 return p->status; … … 1473 1697 p->flags |= FORCE_UPDATE; 1474 1698 } 1475 Send Cmd(p,1699 SendToPymol(p, 1476 1700 "set sphere_transparency,%g,%s\n" 1477 1701 "set stick_transparency,%g,%s\n" … … 1522 1746 p->flags |= FORCE_UPDATE; 1523 1747 } 1524 Send Cmd(p, "vmouse %d,%d,%d,%d,%d\n", arg1, arg2, arg3, arg4, arg5);1748 SendToPymol(p, "vmouse %d,%d,%d,%d,%d\n", arg1, arg2, arg3, arg4, arg5); 1525 1749 return p->status; 1526 1750 } … … 1601 1825 1602 1826 stats.cmdTime += finish - start; 1603 stats.n Commands++;1827 stats.numCommands++; 1604 1828 Tcl_DStringSetLength(dsPtr, 0); 1605 1829 return result; … … 1610 1834 { 1611 1835 if (p->flags & VIEWPORT_PENDING) { 1612 Send Cmd(p, "viewport %d,%d\n", p->width, p->height);1613 Send Cmd(p, "refresh\n");1836 SendToPymol(p, "viewport %d,%d\n", p->width, p->height); 1837 SendToPymol(p, "refresh\n"); 1614 1838 p->flags &= ~VIEWPORT_PENDING; 1615 1839 } … … 1620 1844 { 1621 1845 if (p->flags & ZOOM_PENDING) { 1622 Send Cmd(p, "move z,%f\n", p->zoom);1846 SendToPymol(p, "move z,%f\n", p->zoom); 1623 1847 p->flags &= ~ZOOM_PENDING; 1624 1848 } … … 1629 1853 { 1630 1854 if (p->flags & PAN_PENDING) { 1631 Send Cmd(p, "move x,%f\nmove y,%f\n", p->xPan, p->yPan);1855 SendToPymol(p, "move x,%f\nmove y,%f\n", p->xPan, p->yPan); 1632 1856 p->flags &= ~PAN_PENDING; 1633 1857 } … … 1640 1864 /* Every pymol command line generates a new rendering. Execute all 1641 1865 * three turns as a single command line. */ 1642 Send Cmd(p,"turn x,%f\nturn y,%f\nturn z,%f\n", p->xAngle, p->yAngle,1866 SendToPymol(p,"turn x,%f\nturn y,%f\nturn z,%f\n", p->xAngle, p->yAngle, 1643 1867 p->zAngle); 1644 1868 p->xAngle = p->yAngle = p->zAngle = 0.0f; … … 1651 1875 { 1652 1876 if (p->flags & ATOM_SCALE_PENDING) { 1653 Send Cmd(p, "set sphere_scale,%f,all\n", p->sphereScale);1877 SendToPymol(p, "set sphere_scale,%f,all\n", p->sphereScale); 1654 1878 p->flags &= ~ATOM_SCALE_PENDING; 1655 1879 } … … 1660 1884 { 1661 1885 if (p->flags & STICK_RADIUS_PENDING) { 1662 Send Cmd(p, "set stick_radius,%f,all\n", p->stickRadius);1886 SendToPymol(p, "set stick_radius,%f,all\n", p->stickRadius); 1663 1887 p->flags &= ~STICK_RADIUS_PENDING; 1664 1888 } … … 1715 1939 } 1716 1940 listPtr->headPtr = imgPtr; 1717 imgPtr->n Written = 0;1941 imgPtr->numWritten = 0; 1718 1942 return imgPtr; 1719 1943 } … … 1749 1973 #endif 1750 1974 for (bytesLeft = imgPtr->bytesLeft; bytesLeft > 0; /*empty*/) { 1751 ssize_t n Written;1975 ssize_t numWritten; 1752 1976 #if WRITE_DEBUG 1753 1977 DEBUG("image %d: bytesLeft=%d", imgPtr->id, bytesLeft); 1754 1978 #endif 1755 n Written = write(fd, imgPtr->data + imgPtr->nWritten, bytesLeft);1979 numWritten = write(fd, imgPtr->data + imgPtr->numWritten, bytesLeft); 1756 1980 #if WRITE_DEBUG 1757 DEBUG("image %d: wrote %d bytes.", imgPtr->id, n Written);1758 #endif 1759 if (n Written < 0) {1981 DEBUG("image %d: wrote %d bytes.", imgPtr->id, numWritten); 1982 #endif 1983 if (numWritten < 0) { 1760 1984 ERROR("Error writing fd=%d, %s", fd, strerror(errno)); 1761 1985 #if WRITE_DEBUG … … 1764 1988 return; 1765 1989 } 1766 bytesLeft -= n Written;1990 bytesLeft -= numWritten; 1767 1991 if (bytesLeft > 0) { 1768 1992 #if WRITE_DEBUG … … 1771 1995 #endif 1772 1996 /* Wrote a short buffer, means we would block. */ 1773 imgPtr->n Written += nWritten;1997 imgPtr->numWritten += numWritten; 1774 1998 imgPtr->bytesLeft = bytesLeft; 1775 1999 #if WRITE_DEBUG … … 1778 2002 return; 1779 2003 } 1780 imgPtr->n Written += nWritten;2004 imgPtr->numWritten += numWritten; 1781 2005 } 1782 2006 /* Check if image is on the head. */ … … 1793 2017 } 1794 2018 1795 #if KEEPSTATS1796 1797 static int1798 WriteStats(const char *who, int code)1799 {1800 double start, finish;1801 pid_t pid;1802 char buf[BUFSIZ];1803 Tcl_DString ds;1804 1805 {1806 struct timeval tv;1807 1808 /* Get ending time. */1809 gettimeofday(&tv, NULL);1810 finish = CVT2SECS(tv);1811 tv = stats.start;1812 start = CVT2SECS(tv);1813 }1814 /*1815 * Session information:1816 * 1. Start date of session in seconds.1817 * 2. Process ID1818 * 3. Number of frames returned.1819 * 4. Number of bytes total returned (in frames).1820 * 5. Total elapsed time of all commands.1821 * 6. Total elapsed time of session.1822 * 7. Exit code of pymol server.1823 * 8. User time.1824 * 9. System time.1825 * 10. Maximum resident size.1826 */1827 pid = getpid();1828 Tcl_DStringInit(&ds);1829 1830 sprintf(buf, "<session server=\"%s\" ", who);1831 Tcl_DStringAppend(&ds, buf, -1);1832 1833 strcpy(buf, ctime(&stats.start.tv_sec));1834 1835 buf[strlen(buf) - 1] = '\0';1836 Tcl_DStringAppend(&ds, "date=\"", -1);1837 Tcl_DStringAppend(&ds, buf, -1);1838 Tcl_DStringAppend(&ds, "\" ", -1);1839 1840 sprintf(buf, "date_secs=\"%ld\" ", stats.start.tv_sec);1841 Tcl_DStringAppend(&ds, buf, -1);1842 1843 sprintf(buf, "pid=\"%d\" ", pid);1844 Tcl_DStringAppend(&ds, buf, -1);1845 sprintf(buf, "num_frames=\"%lu\" ", (unsigned long int)stats.nFrames);1846 Tcl_DStringAppend(&ds, buf, -1);1847 sprintf(buf, "frame_bytes=\"%lu\" ", (unsigned long int)stats.nBytes);1848 Tcl_DStringAppend(&ds, buf, -1);1849 sprintf(buf, "num_commands=\"%lu\" ", (unsigned long int)stats.nCommands);1850 Tcl_DStringAppend(&ds, buf, -1);1851 sprintf(buf, "cmd_time=\"%g\" ", stats.cmdTime);1852 Tcl_DStringAppend(&ds, buf, -1);1853 sprintf(buf, "session_time=\"%g\" ", finish - start);1854 Tcl_DStringAppend(&ds, buf, -1);1855 sprintf(buf, "status=\"%d\" ", code);1856 Tcl_DStringAppend(&ds, buf, -1);1857 {1858 long clocksPerSec = sysconf(_SC_CLK_TCK);1859 double clockRes = 1.0 / clocksPerSec;1860 struct tms tms;1861 1862 memset(&tms, 0, sizeof(tms));1863 times(&tms);1864 sprintf(buf, "utime=\"%g\" ", tms.tms_utime * clockRes);1865 Tcl_DStringAppend(&ds, buf, -1);1866 sprintf(buf, "stime=\"%g\" ", tms.tms_stime * clockRes);1867 Tcl_DStringAppend(&ds, buf, -1);1868 sprintf(buf, "cutime=\"%g\" ", tms.tms_cutime * clockRes);1869 Tcl_DStringAppend(&ds, buf, -1);1870 sprintf(buf, "cstime=\"%g\" ", tms.tms_cstime * clockRes);1871 Tcl_DStringAppend(&ds, buf, -1);1872 }1873 Tcl_DStringAppend(&ds, "/>\n", -1);1874 1875 {1876 int f;1877 ssize_t length;1878 int result;1879 1880 #define STATSDIR "/var/tmp/visservers"1881 #define STATSFILE STATSDIR "/" "data.xml"1882 if (access(STATSDIR, X_OK) != 0) {1883 mkdir(STATSDIR, 0770);1884 }1885 length = Tcl_DStringLength(&ds);1886 f = open(STATSFILE, O_APPEND | O_CREAT | O_WRONLY, 0600);1887 result = FALSE;1888 if (f < 0) {1889 goto error;1890 }1891 if (write(f, Tcl_DStringValue(&ds), length) != length) {1892 goto error;1893 }1894 result = TRUE;1895 error:1896 if (f >= 0) {1897 close(f);1898 }1899 Tcl_DStringFree(&ds);1900 return result;1901 }1902 }1903 #endif1904 2019 1905 2020 static void … … 1919 2034 { "cartoon", CartoonCmd }, 1920 2035 { "cartoontrace", CartoonTraceCmd }, 2036 { "clientinfo", ClientInfoCmd }, 1921 2037 { "disable", DisableCmd }, 1922 2038 { "enable", EnableCmd }, … … 2062 2178 2063 2179 Tcl_DeleteInterp(p->interp); 2064 #if KEEPSTATS 2065 WriteStats("pymolproxy", 0); 2066 #endif 2180 ServerStats(0); 2067 2181 2068 2182 #if DEBUG … … 2134 2248 status = GetLine(&p->client, &numBytes, &line); 2135 2249 if (status != BUFFER_OK) { 2136 ERROR("can't read client stdout (n Bytes=%d): %s\n", numBytes,2250 ERROR("can't read client stdout (numBytes=%d): %s\n", numBytes, 2137 2251 strerror(errno)); 2138 2252 goto done; … … 2250 2364 return NULL; 2251 2365 } 2252 stats.n Frames++;2253 stats.n Bytes += numBytes;2366 stats.numFrames++; 2367 stats.numBytes += numBytes; 2254 2368 { 2255 2369 struct timeval tv;
Note: See TracChangeset
for help on using the changeset viewer.