1 /* 2 * Copyright 2008-2009, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "DataSource.h" 8 9 #include <stdio.h> 10 #include <stdint.h> 11 12 #include <Catalog.h> 13 #include <OS.h> 14 #include <String.h> 15 #include <StringForRate.h> 16 17 #include "SystemInfo.h" 18 19 #undef B_TRANSLATION_CONTEXT 20 #define B_TRANSLATION_CONTEXT "DataSource" 21 22 23 const DataSource* kSources[] = { 24 new UsedMemoryDataSource(), 25 new CachedMemoryDataSource(), 26 new SwapSpaceDataSource(), 27 new PageFaultsDataSource(), 28 new CPUUsageDataSource(), 29 new CPUCombinedUsageDataSource(), 30 new NetworkUsageDataSource(true), 31 new NetworkUsageDataSource(false), 32 new BlockCacheDataSource(), 33 new SemaphoresDataSource(), 34 new PortsDataSource(), 35 new ThreadsDataSource(), 36 new TeamsDataSource(), 37 new RunningAppsDataSource(), 38 new ClipboardSizeDataSource(false), 39 new ClipboardSizeDataSource(true), 40 new MediaNodesDataSource() 41 }; 42 const size_t kSourcesCount = sizeof(kSources) / sizeof(kSources[0]); 43 44 45 DataSource::DataSource(int64 initialMin, int64 initialMax) 46 : 47 fMinimum(initialMin), 48 fMaximum(initialMax), 49 fInterval(1000000LL), 50 fColor((rgb_color){200, 0, 0}) 51 { 52 } 53 54 55 DataSource::DataSource() 56 : 57 fMinimum(0), 58 fMaximum(100), 59 fInterval(1000000LL), 60 fColor((rgb_color){200, 0, 0}) 61 { 62 } 63 64 65 DataSource::DataSource(const DataSource& other) 66 { 67 fMinimum = other.fMinimum; 68 fMaximum = other.fMaximum; 69 fInterval = other.fInterval; 70 fColor = other.fColor; 71 } 72 73 74 DataSource::~DataSource() 75 { 76 } 77 78 79 DataSource* 80 DataSource::Copy() const 81 { 82 return NULL; 83 // this class cannot be copied 84 } 85 86 87 DataSource* 88 DataSource::CopyForCPU(int32 cpu) const 89 { 90 return Copy(); 91 } 92 93 94 int64 95 DataSource::Minimum() const 96 { 97 return fMinimum; 98 } 99 100 101 int64 102 DataSource::Maximum() const 103 { 104 return fMaximum; 105 } 106 107 108 bigtime_t 109 DataSource::RefreshInterval() const 110 { 111 return fInterval; 112 } 113 114 115 void 116 DataSource::SetLimits(int64 min, int64 max) 117 { 118 fMinimum = min; 119 fMaximum = max; 120 } 121 122 123 void 124 DataSource::SetRefreshInterval(bigtime_t interval) 125 { 126 fInterval = interval; 127 } 128 129 130 void 131 DataSource::SetColor(rgb_color color) 132 { 133 fColor = color; 134 } 135 136 137 int64 138 DataSource::NextValue(SystemInfo& info) 139 { 140 return 0; 141 } 142 143 144 void 145 DataSource::Print(BString& text, int64 value) const 146 { 147 text = ""; 148 text << value; 149 } 150 151 152 const char* 153 DataSource::ShortLabel() const 154 { 155 return Label(); 156 } 157 158 159 const char* 160 DataSource::Name() const 161 { 162 return Label(); 163 } 164 165 166 const char* 167 DataSource::Label() const 168 { 169 return ""; 170 } 171 172 173 const char* 174 DataSource::Unit() const 175 { 176 return ""; 177 } 178 179 180 rgb_color 181 DataSource::Color() const 182 { 183 return fColor; 184 } 185 186 187 bool 188 DataSource::AdaptiveScale() const 189 { 190 return false; 191 } 192 193 194 scale_type 195 DataSource::ScaleType() const 196 { 197 return kNoScale; 198 } 199 200 201 int32 202 DataSource::CPU() const 203 { 204 return 0; 205 } 206 207 208 bool 209 DataSource::PerCPU() const 210 { 211 return false; 212 } 213 214 215 bool 216 DataSource::MultiCPUOnly() const 217 { 218 return false; 219 } 220 221 222 bool 223 DataSource::Primary() const 224 { 225 return false; 226 } 227 228 229 /*static*/ int32 230 DataSource::CountSources() 231 { 232 return kSourcesCount; 233 } 234 235 236 /*static*/ const DataSource* 237 DataSource::SourceAt(int32 index) 238 { 239 if (index >= (int32)kSourcesCount || index < 0) 240 return NULL; 241 242 return kSources[index]; 243 } 244 245 246 /*static*/ const DataSource* 247 DataSource::FindSource(const char* internalName) 248 { 249 for (uint32 i = 0; i < kSourcesCount; i++) { 250 const DataSource* source = kSources[i]; 251 if (!strcmp(source->InternalName(), internalName)) 252 return source; 253 } 254 255 return NULL; 256 } 257 258 259 /*static*/ int32 260 DataSource::IndexOf(const DataSource* source) 261 { 262 const char* name = source->Name(); 263 264 for (uint32 i = 0; i < kSourcesCount; i++) { 265 if (!strcmp(kSources[i]->Name(), name)) 266 return i; 267 } 268 269 return -1; 270 } 271 272 273 // #pragma mark - 274 275 276 MemoryDataSource::MemoryDataSource() 277 { 278 SystemInfo info; 279 280 fMinimum = 0; 281 fMaximum = info.MaxMemory(); 282 } 283 284 285 MemoryDataSource::~MemoryDataSource() 286 { 287 } 288 289 290 void 291 MemoryDataSource::Print(BString& text, int64 value) const 292 { 293 char buffer[32]; 294 snprintf(buffer, sizeof(buffer), B_TRANSLATE("%.1f MiB"), value / 1048576.0); 295 296 text = buffer; 297 } 298 299 300 const char* 301 MemoryDataSource::Unit() const 302 { 303 return B_TRANSLATE("MiB"); 304 } 305 306 307 // #pragma mark - 308 309 310 UsedMemoryDataSource::UsedMemoryDataSource() 311 { 312 } 313 314 315 UsedMemoryDataSource::~UsedMemoryDataSource() 316 { 317 } 318 319 320 DataSource* 321 UsedMemoryDataSource::Copy() const 322 { 323 return new UsedMemoryDataSource(*this); 324 } 325 326 327 int64 328 UsedMemoryDataSource::NextValue(SystemInfo& info) 329 { 330 return info.UsedMemory(); 331 } 332 333 334 const char* 335 UsedMemoryDataSource::InternalName() const 336 { 337 return "Used memory"; 338 } 339 340 341 const char* 342 UsedMemoryDataSource::Label() const 343 { 344 return B_TRANSLATE("Used memory"); 345 } 346 347 348 const char* 349 UsedMemoryDataSource::ShortLabel() const 350 { 351 return B_TRANSLATE("Memory"); 352 } 353 354 355 bool 356 UsedMemoryDataSource::Primary() const 357 { 358 return true; 359 } 360 361 362 // #pragma mark - 363 364 365 CachedMemoryDataSource::CachedMemoryDataSource() 366 { 367 fColor = (rgb_color){0, 200, 0}; 368 } 369 370 371 CachedMemoryDataSource::~CachedMemoryDataSource() 372 { 373 } 374 375 376 DataSource* 377 CachedMemoryDataSource::Copy() const 378 { 379 return new CachedMemoryDataSource(*this); 380 } 381 382 383 int64 384 CachedMemoryDataSource::NextValue(SystemInfo& info) 385 { 386 return info.CachedMemory(); 387 } 388 389 390 const char* 391 CachedMemoryDataSource::InternalName() const 392 { 393 return "Cached memory"; 394 } 395 396 397 const char* 398 CachedMemoryDataSource::Label() const 399 { 400 return B_TRANSLATE("Cached memory"); 401 } 402 403 404 const char* 405 CachedMemoryDataSource::ShortLabel() const 406 { 407 return B_TRANSLATE("Cache"); 408 } 409 410 411 bool 412 CachedMemoryDataSource::Primary() const 413 { 414 return true; 415 } 416 417 418 // #pragma mark - 419 420 421 SwapSpaceDataSource::SwapSpaceDataSource() 422 { 423 SystemInfo info; 424 425 fColor = (rgb_color){0, 120, 0}; 426 fMaximum = info.MaxSwapSpace(); 427 } 428 429 430 SwapSpaceDataSource::~SwapSpaceDataSource() 431 { 432 } 433 434 435 DataSource* 436 SwapSpaceDataSource::Copy() const 437 { 438 return new SwapSpaceDataSource(*this); 439 } 440 441 442 int64 443 SwapSpaceDataSource::NextValue(SystemInfo& info) 444 { 445 return info.UsedSwapSpace(); 446 } 447 448 449 const char* 450 SwapSpaceDataSource::InternalName() const 451 { 452 return "Swap space"; 453 } 454 455 456 const char* 457 SwapSpaceDataSource::Label() const 458 { 459 return B_TRANSLATE("Swap space"); 460 } 461 462 463 const char* 464 SwapSpaceDataSource::ShortLabel() const 465 { 466 return B_TRANSLATE("Swap"); 467 } 468 469 470 bool 471 SwapSpaceDataSource::Primary() const 472 { 473 return true; 474 } 475 476 477 // #pragma mark - 478 479 480 BlockCacheDataSource::BlockCacheDataSource() 481 { 482 fColor = (rgb_color){0, 0, 120}; 483 } 484 485 486 BlockCacheDataSource::~BlockCacheDataSource() 487 { 488 } 489 490 491 DataSource* 492 BlockCacheDataSource::Copy() const 493 { 494 return new BlockCacheDataSource(*this); 495 } 496 497 498 int64 499 BlockCacheDataSource::NextValue(SystemInfo& info) 500 { 501 return info.BlockCacheMemory(); 502 } 503 504 505 const char* 506 BlockCacheDataSource::InternalName() const 507 { 508 return "Block cache memory"; 509 } 510 511 512 const char* 513 BlockCacheDataSource::Label() const 514 { 515 return B_TRANSLATE("Block cache memory"); 516 } 517 518 519 const char* 520 BlockCacheDataSource::ShortLabel() const 521 { 522 return B_TRANSLATE("Block cache"); 523 } 524 525 526 // #pragma mark - 527 528 529 SemaphoresDataSource::SemaphoresDataSource() 530 { 531 SystemInfo info; 532 533 fMinimum = 0; 534 fMaximum = info.MaxSemaphores(); 535 536 fColor = (rgb_color){100, 200, 100}; 537 } 538 539 540 SemaphoresDataSource::~SemaphoresDataSource() 541 { 542 } 543 544 545 DataSource* 546 SemaphoresDataSource::Copy() const 547 { 548 return new SemaphoresDataSource(*this); 549 } 550 551 552 int64 553 SemaphoresDataSource::NextValue(SystemInfo& info) 554 { 555 return info.UsedSemaphores(); 556 } 557 558 559 const char* 560 SemaphoresDataSource::InternalName() const 561 { 562 return "Semaphores"; 563 } 564 565 566 const char* 567 SemaphoresDataSource::Label() const 568 { 569 return B_TRANSLATE("Semaphores"); 570 } 571 572 573 const char* 574 SemaphoresDataSource::ShortLabel() const 575 { 576 return B_TRANSLATE("Sems"); 577 } 578 579 580 bool 581 SemaphoresDataSource::AdaptiveScale() const 582 { 583 return true; 584 } 585 586 587 // #pragma mark - 588 589 590 PortsDataSource::PortsDataSource() 591 { 592 SystemInfo info; 593 594 fMinimum = 0; 595 fMaximum = info.MaxPorts(); 596 597 fColor = (rgb_color){180, 200, 180}; 598 } 599 600 601 PortsDataSource::~PortsDataSource() 602 { 603 } 604 605 606 DataSource* 607 PortsDataSource::Copy() const 608 { 609 return new PortsDataSource(*this); 610 } 611 612 613 int64 614 PortsDataSource::NextValue(SystemInfo& info) 615 { 616 return info.UsedPorts(); 617 } 618 619 620 const char* 621 PortsDataSource::InternalName() const 622 { 623 return "Ports"; 624 } 625 626 627 const char* 628 PortsDataSource::Label() const 629 { 630 return B_TRANSLATE("Ports"); 631 } 632 633 634 bool 635 PortsDataSource::AdaptiveScale() const 636 { 637 return true; 638 } 639 640 641 // #pragma mark - 642 643 644 ThreadsDataSource::ThreadsDataSource() 645 { 646 SystemInfo info; 647 648 fMinimum = 0; 649 fMaximum = info.MaxThreads(); 650 651 fColor = (rgb_color){0, 0, 200}; 652 } 653 654 655 ThreadsDataSource::~ThreadsDataSource() 656 { 657 } 658 659 660 DataSource* 661 ThreadsDataSource::Copy() const 662 { 663 return new ThreadsDataSource(*this); 664 } 665 666 667 int64 668 ThreadsDataSource::NextValue(SystemInfo& info) 669 { 670 return info.UsedThreads(); 671 } 672 673 674 const char* 675 ThreadsDataSource::InternalName() const 676 { 677 return "Threads"; 678 } 679 680 681 const char* 682 ThreadsDataSource::Label() const 683 { 684 return B_TRANSLATE("Threads"); 685 } 686 687 688 bool 689 ThreadsDataSource::AdaptiveScale() const 690 { 691 return true; 692 } 693 694 695 // #pragma mark - 696 697 698 TeamsDataSource::TeamsDataSource() 699 { 700 SystemInfo info; 701 702 fMinimum = 0; 703 fMaximum = info.MaxTeams(); 704 705 fColor = (rgb_color){0, 150, 255}; 706 } 707 708 709 TeamsDataSource::~TeamsDataSource() 710 { 711 } 712 713 714 DataSource* 715 TeamsDataSource::Copy() const 716 { 717 return new TeamsDataSource(*this); 718 } 719 720 721 int64 722 TeamsDataSource::NextValue(SystemInfo& info) 723 { 724 return info.UsedTeams(); 725 } 726 727 728 const char* 729 TeamsDataSource::InternalName() const 730 { 731 return "Teams"; 732 } 733 734 735 const char* 736 TeamsDataSource::Label() const 737 { 738 return B_TRANSLATE("Teams"); 739 } 740 741 742 bool 743 TeamsDataSource::AdaptiveScale() const 744 { 745 return true; 746 } 747 748 749 // #pragma mark - 750 751 752 RunningAppsDataSource::RunningAppsDataSource() 753 { 754 SystemInfo info; 755 756 fMinimum = 0; 757 fMaximum = info.MaxRunningApps(); 758 759 fColor = (rgb_color){100, 150, 255}; 760 } 761 762 763 RunningAppsDataSource::~RunningAppsDataSource() 764 { 765 } 766 767 768 DataSource* 769 RunningAppsDataSource::Copy() const 770 { 771 return new RunningAppsDataSource(*this); 772 } 773 774 775 int64 776 RunningAppsDataSource::NextValue(SystemInfo& info) 777 { 778 return info.UsedRunningApps(); 779 } 780 781 782 const char* 783 RunningAppsDataSource::InternalName() const 784 { 785 return "Running applications"; 786 } 787 788 789 const char* 790 RunningAppsDataSource::Label() const 791 { 792 return B_TRANSLATE("Running applications"); 793 } 794 795 796 const char* 797 RunningAppsDataSource::ShortLabel() const 798 { 799 return B_TRANSLATE("Apps"); 800 } 801 802 803 bool 804 RunningAppsDataSource::AdaptiveScale() const 805 { 806 return true; 807 } 808 809 810 // #pragma mark - 811 812 813 CPUUsageDataSource::CPUUsageDataSource(int32 cpu) 814 : 815 fPreviousActive(0), 816 fPreviousTime(0) 817 { 818 fMinimum = 0; 819 fMaximum = 1000; 820 821 _SetCPU(cpu); 822 } 823 824 825 CPUUsageDataSource::CPUUsageDataSource(const CPUUsageDataSource& other) 826 : DataSource(other) 827 { 828 fPreviousActive = other.fPreviousActive; 829 fPreviousTime = other.fPreviousTime; 830 fCPU = other.fCPU; 831 fLabel = other.fLabel; 832 fShortLabel = other.fShortLabel; 833 } 834 835 836 CPUUsageDataSource::~CPUUsageDataSource() 837 { 838 } 839 840 841 DataSource* 842 CPUUsageDataSource::Copy() const 843 { 844 return new CPUUsageDataSource(*this); 845 } 846 847 848 DataSource* 849 CPUUsageDataSource::CopyForCPU(int32 cpu) const 850 { 851 CPUUsageDataSource* copy = new CPUUsageDataSource(*this); 852 copy->_SetCPU(cpu); 853 854 return copy; 855 } 856 857 858 void 859 CPUUsageDataSource::Print(BString& text, int64 value) const 860 { 861 char buffer[32]; 862 snprintf(buffer, sizeof(buffer), "%.1f%%", value / 10.0); 863 864 text = buffer; 865 } 866 867 868 int64 869 CPUUsageDataSource::NextValue(SystemInfo& info) 870 { 871 bigtime_t active = info.CPUActiveTime(fCPU); 872 873 int64 percent = int64(1000.0 * (active - fPreviousActive) 874 / (info.Time() - fPreviousTime)); 875 if (percent < 0) 876 percent = 0; 877 if (percent > 1000) 878 percent = 1000; 879 880 fPreviousActive = active; 881 fPreviousTime = info.Time(); 882 883 return percent; 884 } 885 886 887 const char* 888 CPUUsageDataSource::Label() const 889 { 890 return fLabel.String(); 891 } 892 893 894 const char* 895 CPUUsageDataSource::ShortLabel() const 896 { 897 return fShortLabel.String(); 898 } 899 900 901 const char* 902 CPUUsageDataSource::InternalName() const 903 { 904 return "CPU usage"; 905 } 906 907 908 const char* 909 CPUUsageDataSource::Name() const 910 { 911 return B_TRANSLATE("CPU usage"); 912 } 913 914 915 int32 916 CPUUsageDataSource::CPU() const 917 { 918 return fCPU; 919 } 920 921 922 bool 923 CPUUsageDataSource::PerCPU() const 924 { 925 return true; 926 } 927 928 929 bool 930 CPUUsageDataSource::Primary() const 931 { 932 return true; 933 } 934 935 936 void 937 CPUUsageDataSource::_SetCPU(int32 cpu) 938 { 939 fCPU = cpu; 940 941 if (SystemInfo().CPUCount() > 1) { 942 fLabel.SetToFormat(B_TRANSLATE("CPU %d usage"), cpu + 1); 943 fShortLabel.SetToFormat(B_TRANSLATE("CPU %d"), cpu + 1); 944 945 } else { 946 fLabel = B_TRANSLATE("CPU usage"); 947 fShortLabel = B_TRANSLATE("CPU"); 948 } 949 950 const rgb_color kColors[] = { 951 // TODO: find some better defaults... 952 {200, 0, 200}, 953 {0, 200, 200}, 954 {80, 80, 80}, 955 {230, 150, 50}, 956 {255, 0, 0}, 957 {0, 255, 0}, 958 {0, 0, 255}, 959 {0, 150, 230} 960 }; 961 const uint32 kNumColors = sizeof(kColors) / sizeof(kColors[0]); 962 963 fColor = kColors[cpu % kNumColors]; 964 } 965 966 967 // #pragma mark - 968 969 970 CPUCombinedUsageDataSource::CPUCombinedUsageDataSource() 971 : 972 fPreviousActive(0), 973 fPreviousTime(0) 974 { 975 fMinimum = 0; 976 fMaximum = 1000; 977 978 fColor = (rgb_color){200, 200, 0}; 979 } 980 981 982 CPUCombinedUsageDataSource::CPUCombinedUsageDataSource( 983 const CPUCombinedUsageDataSource& other) 984 : DataSource(other) 985 { 986 fPreviousActive = other.fPreviousActive; 987 fPreviousTime = other.fPreviousTime; 988 } 989 990 991 CPUCombinedUsageDataSource::~CPUCombinedUsageDataSource() 992 { 993 } 994 995 996 DataSource* 997 CPUCombinedUsageDataSource::Copy() const 998 { 999 return new CPUCombinedUsageDataSource(*this); 1000 } 1001 1002 1003 void 1004 CPUCombinedUsageDataSource::Print(BString& text, int64 value) const 1005 { 1006 char buffer[32]; 1007 snprintf(buffer, sizeof(buffer), "%.1f%%", value / 10.0); 1008 1009 text = buffer; 1010 } 1011 1012 1013 int64 1014 CPUCombinedUsageDataSource::NextValue(SystemInfo& info) 1015 { 1016 int32 running = 0; 1017 bigtime_t active = 0; 1018 1019 for (uint32 cpu = 0; cpu < info.CPUCount(); cpu++) { 1020 active += info.CPUActiveTime(cpu); 1021 running++; 1022 // TODO: take disabled CPUs into account 1023 } 1024 1025 int64 percent = int64(1000.0 * (active - fPreviousActive) 1026 / (running * (info.Time() - fPreviousTime))); 1027 if (percent < 0) 1028 percent = 0; 1029 if (percent > 1000) 1030 percent = 1000; 1031 1032 fPreviousActive = active; 1033 fPreviousTime = info.Time(); 1034 1035 return percent; 1036 } 1037 1038 1039 const char* 1040 CPUCombinedUsageDataSource::Label() const 1041 { 1042 return B_TRANSLATE("CPU usage"); 1043 } 1044 1045 1046 const char* 1047 CPUCombinedUsageDataSource::ShortLabel() const 1048 { 1049 return B_TRANSLATE("CPU"); 1050 } 1051 1052 1053 const char* 1054 CPUCombinedUsageDataSource::InternalName() const 1055 { 1056 return "CPU usage (combined)"; 1057 } 1058 1059 1060 const char* 1061 CPUCombinedUsageDataSource::Name() const 1062 { 1063 return B_TRANSLATE("CPU usage (combined)"); 1064 } 1065 1066 1067 bool 1068 CPUCombinedUsageDataSource::MultiCPUOnly() const 1069 { 1070 return true; 1071 } 1072 1073 1074 bool 1075 CPUCombinedUsageDataSource::Primary() const 1076 { 1077 return true; 1078 } 1079 1080 1081 // #pragma mark - 1082 1083 1084 PageFaultsDataSource::PageFaultsDataSource() 1085 : 1086 fPreviousFaults(0), 1087 fPreviousTime(0) 1088 { 1089 SystemInfo info; 1090 NextValue(info); 1091 1092 fMinimum = 0; 1093 fMaximum = 1000000000LL; 1094 1095 fColor = (rgb_color){200, 0, 150, 0}; 1096 } 1097 1098 1099 PageFaultsDataSource::PageFaultsDataSource(const PageFaultsDataSource& other) 1100 : DataSource(other) 1101 { 1102 fPreviousFaults = other.fPreviousFaults; 1103 fPreviousTime = other.fPreviousTime; 1104 } 1105 1106 1107 PageFaultsDataSource::~PageFaultsDataSource() 1108 { 1109 } 1110 1111 1112 DataSource* 1113 PageFaultsDataSource::Copy() const 1114 { 1115 return new PageFaultsDataSource(*this); 1116 } 1117 1118 1119 void 1120 PageFaultsDataSource::Print(BString& text, int64 value) const 1121 { 1122 char buffer[32]; 1123 snprintf(buffer, sizeof(buffer), B_TRANSLATE("%.1f faults/s"), 1124 value / 1024.0); 1125 1126 text = buffer; 1127 } 1128 1129 1130 int64 1131 PageFaultsDataSource::NextValue(SystemInfo& info) 1132 { 1133 uint64 faults = info.PageFaults(); 1134 1135 int64 faultsPerSecond = uint64(1024 * double(faults - fPreviousFaults) 1136 / (info.Time() - fPreviousTime) * 1000000.0); 1137 1138 fPreviousFaults = faults; 1139 fPreviousTime = info.Time(); 1140 1141 return faultsPerSecond; 1142 } 1143 1144 1145 const char* 1146 PageFaultsDataSource::Label() const 1147 { 1148 return B_TRANSLATE("Page faults"); 1149 } 1150 1151 1152 const char* 1153 PageFaultsDataSource::ShortLabel() const 1154 { 1155 return B_TRANSLATE("P-faults"); 1156 } 1157 1158 1159 const char* 1160 PageFaultsDataSource::InternalName() const 1161 { 1162 return "Page faults"; 1163 } 1164 1165 1166 const char* 1167 PageFaultsDataSource::Name() const 1168 { 1169 return B_TRANSLATE("Page faults"); 1170 } 1171 1172 1173 bool 1174 PageFaultsDataSource::AdaptiveScale() const 1175 { 1176 return true; 1177 } 1178 1179 1180 bool 1181 PageFaultsDataSource::Primary() const 1182 { 1183 return false; 1184 } 1185 1186 1187 // #pragma mark - 1188 1189 1190 NetworkUsageDataSource::NetworkUsageDataSource(bool in) 1191 : 1192 fIn(in), 1193 fPreviousBytes(0), 1194 fPreviousTime(0) 1195 { 1196 SystemInfo info; 1197 NextValue(info); 1198 1199 fMinimum = 0; 1200 fMaximum = 1000000000LL; 1201 1202 fColor = fIn ? (rgb_color){200, 150, 0} : (rgb_color){200, 220, 0}; 1203 } 1204 1205 1206 NetworkUsageDataSource::NetworkUsageDataSource( 1207 const NetworkUsageDataSource& other) 1208 : DataSource(other) 1209 { 1210 fIn = other.fIn; 1211 fPreviousBytes = other.fPreviousBytes; 1212 fPreviousTime = other.fPreviousTime; 1213 } 1214 1215 1216 NetworkUsageDataSource::~NetworkUsageDataSource() 1217 { 1218 } 1219 1220 1221 DataSource* 1222 NetworkUsageDataSource::Copy() const 1223 { 1224 return new NetworkUsageDataSource(*this); 1225 } 1226 1227 1228 void 1229 NetworkUsageDataSource::Print(BString& text, int64 value) const 1230 { 1231 char buffer[32]; 1232 string_for_rate(value, buffer, sizeof(buffer)); 1233 1234 text = buffer; 1235 } 1236 1237 1238 int64 1239 NetworkUsageDataSource::NextValue(SystemInfo& info) 1240 { 1241 uint64 transferred = fIn ? info.NetworkReceived() : info.NetworkSent(); 1242 1243 int64 bytesPerSecond = uint64(double(transferred - fPreviousBytes) 1244 / (info.Time() - fPreviousTime) * 1000000.0); 1245 1246 fPreviousBytes = transferred; 1247 fPreviousTime = info.Time(); 1248 1249 return bytesPerSecond; 1250 } 1251 1252 1253 const char* 1254 NetworkUsageDataSource::Label() const 1255 { 1256 return fIn ? B_TRANSLATE("Receiving") : B_TRANSLATE("Sending"); 1257 } 1258 1259 1260 const char* 1261 NetworkUsageDataSource::ShortLabel() const 1262 { 1263 return fIn ? B_TRANSLATE_COMMENT("RX", "Shorter version for Receiving.") : 1264 B_TRANSLATE_COMMENT("TX", "Shorter version for Sending"); 1265 } 1266 1267 1268 const char* 1269 NetworkUsageDataSource::InternalName() const 1270 { 1271 return fIn ? "Network receive" : "Network send"; 1272 } 1273 1274 1275 const char* 1276 NetworkUsageDataSource::Name() const 1277 { 1278 return fIn ? B_TRANSLATE("Network receive") : B_TRANSLATE("Network send"); 1279 } 1280 1281 1282 bool 1283 NetworkUsageDataSource::AdaptiveScale() const 1284 { 1285 return true; 1286 } 1287 1288 1289 scale_type 1290 NetworkUsageDataSource::ScaleType() const 1291 { 1292 return kBytePerSecondScale; 1293 } 1294 1295 1296 bool 1297 NetworkUsageDataSource::Primary() const 1298 { 1299 return true; 1300 } 1301 1302 1303 // #pragma mark - 1304 1305 1306 ClipboardSizeDataSource::ClipboardSizeDataSource(bool text) 1307 { 1308 fMinimum = 0; 1309 fMaximum = UINT32_MAX; 1310 fText = text; 1311 1312 fColor = (rgb_color){0, 150, 255}; 1313 } 1314 1315 1316 ClipboardSizeDataSource::ClipboardSizeDataSource( 1317 const ClipboardSizeDataSource& other) 1318 : DataSource(other) 1319 { 1320 fText = other.fText; 1321 } 1322 1323 1324 ClipboardSizeDataSource::~ClipboardSizeDataSource() 1325 { 1326 } 1327 1328 1329 DataSource* 1330 ClipboardSizeDataSource::Copy() const 1331 { 1332 return new ClipboardSizeDataSource(*this); 1333 } 1334 1335 1336 int64 1337 ClipboardSizeDataSource::NextValue(SystemInfo& info) 1338 { 1339 if (fText) 1340 return info.ClipboardTextSize()/* / 1024*/; 1341 return info.ClipboardSize()/* / 1024*/; 1342 } 1343 1344 1345 const char* 1346 ClipboardSizeDataSource::InternalName() const 1347 { 1348 return fText ? "Text clipboard size" : "Raw clipboard size"; 1349 } 1350 1351 1352 const char* 1353 ClipboardSizeDataSource::Label() const 1354 { 1355 return fText ? B_TRANSLATE("Text clipboard") 1356 : B_TRANSLATE("Raw clipboard"); 1357 } 1358 1359 1360 const char* 1361 ClipboardSizeDataSource::Unit() const 1362 { 1363 return "bytes"/*"KB"*/; 1364 } 1365 1366 1367 bool 1368 ClipboardSizeDataSource::AdaptiveScale() const 1369 { 1370 return true; 1371 } 1372 1373 1374 // #pragma mark - 1375 1376 1377 MediaNodesDataSource::MediaNodesDataSource() 1378 { 1379 SystemInfo info; 1380 1381 fMinimum = 0; 1382 fMaximum = INT32_MAX; 1383 1384 fColor = (rgb_color){255, 150, 225}; 1385 } 1386 1387 1388 MediaNodesDataSource::~MediaNodesDataSource() 1389 { 1390 } 1391 1392 1393 DataSource* 1394 MediaNodesDataSource::Copy() const 1395 { 1396 return new MediaNodesDataSource(*this); 1397 } 1398 1399 1400 int64 1401 MediaNodesDataSource::NextValue(SystemInfo& info) 1402 { 1403 return info.MediaNodes(); 1404 } 1405 1406 1407 const char* 1408 MediaNodesDataSource::InternalName() const 1409 { 1410 return "Media nodes"; 1411 } 1412 1413 1414 const char* 1415 MediaNodesDataSource::Label() const 1416 { 1417 return B_TRANSLATE("Media nodes"); 1418 } 1419 1420 1421 bool 1422 MediaNodesDataSource::AdaptiveScale() const 1423 { 1424 return true; 1425 } 1426 1427 1428