| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // Seed the random number generator. | 76 // Seed the random number generator. |
| 77 // Convert the current time to a 64-bit integer first, before converting it | 77 // Convert the current time to a 64-bit integer first, before converting it |
| 78 // to an unsigned. Going directly can cause an overflow and the seed to be | 78 // to an unsigned. Going directly can cause an overflow and the seed to be |
| 79 // set to all ones. The seed will be identical for different instances that | 79 // set to all ones. The seed will be identical for different instances that |
| 80 // call this setup code within the same millisecond. | 80 // call this setup code within the same millisecond. |
| 81 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); | 81 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); |
| 82 srandom(static_cast<unsigned int>(seed)); | 82 srandom(static_cast<unsigned int>(seed)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 | 85 |
| 86 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { | |
| 87 struct rusage usage; | |
| 88 | |
| 89 if (getrusage(RUSAGE_SELF, &usage) < 0) return -1; | |
| 90 *secs = usage.ru_utime.tv_sec; | |
| 91 *usecs = usage.ru_utime.tv_usec; | |
| 92 return 0; | |
| 93 } | |
| 94 | |
| 95 | |
| 96 double OS::TimeCurrentMillis() { | |
| 97 struct timeval tv; | |
| 98 if (gettimeofday(&tv, NULL) < 0) return 0.0; | |
| 99 return (static_cast<double>(tv.tv_sec) * 1000) + | |
| 100 (static_cast<double>(tv.tv_usec) / 1000); | |
| 101 } | |
| 102 | |
| 103 | |
| 104 int64_t OS::Ticks() { | |
| 105 // FreeBSD's gettimeofday has microsecond resolution. | |
| 106 struct timeval tv; | |
| 107 if (gettimeofday(&tv, NULL) < 0) | |
| 108 return 0; | |
| 109 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec; | |
| 110 } | |
| 111 | |
| 112 | |
| 113 char* OS::LocalTimezone(double time) { | |
| 114 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); | |
| 115 struct tm* t = localtime(&tv); | |
| 116 return const_cast<char*>(t->tm_zone); | |
| 117 } | |
| 118 | |
| 119 | |
| 120 double OS::DaylightSavingsOffset(double time) { | |
| 121 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); | |
| 122 struct tm* t = localtime(&tv); | |
| 123 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0; | |
| 124 } | |
| 125 | |
| 126 | |
| 127 double OS::LocalTimeOffset() { | |
| 128 time_t tv = time(NULL); | |
| 129 struct tm* t = localtime(&tv); | |
| 130 // tm_gmtoff includes any daylight savings offset, so subtract it. | |
| 131 return static_cast<double>(t->tm_gmtoff * msPerSecond - | |
| 132 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); | |
| 133 } | |
| 134 | |
| 135 | |
| 136 FILE* OS::FOpen(const char* path, const char* mode) { | 86 FILE* OS::FOpen(const char* path, const char* mode) { |
| 137 return fopen(path, mode); | 87 return fopen(path, mode); |
| 138 } | 88 } |
| 139 | 89 |
| 140 | 90 |
| 141 void OS::Print(const char* format, ...) { | 91 void OS::Print(const char* format, ...) { |
| 142 va_list args; | 92 va_list args; |
| 143 va_start(args, format); | 93 va_start(args, format); |
| 144 VPrint(format, args); | 94 VPrint(format, args); |
| 145 va_end(args); | 95 va_end(args); |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 } | 679 } |
| 730 | 680 |
| 731 // This sampler is no longer the active sampler. | 681 // This sampler is no longer the active sampler. |
| 732 active_sampler_ = NULL; | 682 active_sampler_ = NULL; |
| 733 active_ = false; | 683 active_ = false; |
| 734 } | 684 } |
| 735 | 685 |
| 736 #endif // ENABLE_LOGGING_AND_PROFILING | 686 #endif // ENABLE_LOGGING_AND_PROFILING |
| 737 | 687 |
| 738 } } // namespace v8::internal | 688 } } // namespace v8::internal |
| OLD | NEW |