comparison base/StorageAdviser.cpp @ 383:94fc0591ea43 1.2-stable

* merge from trunk (1.2 ended up being tracked from trunk, but we may want this branch for fixes later)
author Chris Cannam
date Wed, 27 Feb 2008 10:32:45 +0000
parents aa8dbac62024
children
comparison
equal deleted inserted replaced
349:f39d33b0b265 383:94fc0591ea43
20 20
21 #include "system/System.h" 21 #include "system/System.h"
22 22
23 #include <iostream> 23 #include <iostream>
24 24
25 //#define DEBUG_STORAGE_ADVISER 1
26
25 long StorageAdviser::m_discPlanned = 0; 27 long StorageAdviser::m_discPlanned = 0;
26 long StorageAdviser::m_memoryPlanned = 0; 28 long StorageAdviser::m_memoryPlanned = 0;
27 29
28 StorageAdviser::Recommendation 30 StorageAdviser::Recommendation
29 StorageAdviser::recommend(Criteria criteria, 31 StorageAdviser::recommend(Criteria criteria,
30 int minimumSize, 32 int minimumSize,
31 int maximumSize) 33 int maximumSize)
32 { 34 {
35 #ifdef DEBUG_STORAGE_ADVISER
33 std::cerr << "StorageAdviser::recommend: Criteria " << criteria 36 std::cerr << "StorageAdviser::recommend: Criteria " << criteria
34 << ", minimumSize " << minimumSize 37 << ", minimumSize " << minimumSize
35 << ", maximumSize " << maximumSize << std::endl; 38 << ", maximumSize " << maximumSize << std::endl;
39 #endif
36 40
37 QString path = TempDirectory::getInstance()->getPath(); 41 QString path = TempDirectory::getInstance()->getPath();
38 int discFree = GetDiscSpaceMBAvailable(path.toLocal8Bit()); 42 int discFree = GetDiscSpaceMBAvailable(path.toLocal8Bit());
39 int memoryFree, memoryTotal; 43 int memoryFree, memoryTotal;
40 GetRealMemoryMBAvailable(memoryFree, memoryTotal); 44 GetRealMemoryMBAvailable(memoryFree, memoryTotal);
49 memoryFree -= m_memoryPlanned / 1024 + 1; 53 memoryFree -= m_memoryPlanned / 1024 + 1;
50 } else if (memoryFree > 0) { // can also be -1 for unknown 54 } else if (memoryFree > 0) { // can also be -1 for unknown
51 memoryFree = 0; 55 memoryFree = 0;
52 } 56 }
53 57
58 #ifdef DEBUG_STORAGE_ADVISER
54 std::cerr << "Disc space: " << discFree << ", memory free: " << memoryFree << ", memory total: " << memoryTotal << ", min " << minimumSize << ", max " << maximumSize << std::endl; 59 std::cerr << "Disc space: " << discFree << ", memory free: " << memoryFree << ", memory total: " << memoryTotal << ", min " << minimumSize << ", max " << maximumSize << std::endl;
60 #endif
55 61
56 //!!! We have a potentially serious problem here if multiple 62 //!!! We have a potentially serious problem here if multiple
57 //recommendations are made in advance of any of the resulting 63 //recommendations are made in advance of any of the resulting
58 //allocations, as the allocations that have been recommended for 64 //allocations, as the allocations that have been recommended for
59 //won't be taken into account in subsequent recommendations. 65 //won't be taken into account in subsequent recommendations.
75 else if (minmb > (memoryFree * 3) / 4) memoryStatus = Insufficient; 81 else if (minmb > (memoryFree * 3) / 4) memoryStatus = Insufficient;
76 else if (maxmb > (memoryFree * 3) / 4) memoryStatus = Marginal; 82 else if (maxmb > (memoryFree * 3) / 4) memoryStatus = Marginal;
77 else if (minmb > (memoryFree / 3)) memoryStatus = Marginal; 83 else if (minmb > (memoryFree / 3)) memoryStatus = Marginal;
78 else if (memoryTotal == -1 || 84 else if (memoryTotal == -1 ||
79 minmb > (memoryTotal / 10)) memoryStatus = Marginal; 85 minmb > (memoryTotal / 10)) memoryStatus = Marginal;
86 else if (memoryFree < memoryTotal / 4) memoryStatus = Marginal;
80 else memoryStatus = Sufficient; 87 else memoryStatus = Sufficient;
81 88
82 if (discFree == -1) discStatus = Unknown; 89 if (discFree == -1) discStatus = Unknown;
83 else if (minmb > (discFree * 3) / 4) discStatus = Insufficient; 90 else if (minmb > (discFree * 3) / 4) discStatus = Insufficient;
84 else if (maxmb > (discFree / 4)) discStatus = Marginal; 91 else if (maxmb > (discFree / 4)) discStatus = Marginal;
85 else if (minmb > (discFree / 10)) discStatus = Marginal; 92 else if (minmb > (discFree / 10)) discStatus = Marginal;
86 else discStatus = Sufficient; 93 else discStatus = Sufficient;
87 94
95 #ifdef DEBUG_STORAGE_ADVISER
88 std::cerr << "Memory status: " << memoryStatus << ", disc status " 96 std::cerr << "Memory status: " << memoryStatus << ", disc status "
89 << discStatus << std::endl; 97 << discStatus << std::endl;
98 #endif
90 99
91 int recommendation = NoRecommendation; 100 int recommendation = NoRecommendation;
92 101
93 if (memoryStatus == Insufficient || memoryStatus == Unknown) { 102 if (memoryStatus == Insufficient || memoryStatus == Unknown) {
94 103