Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: src/platform-linux.cc

Issue 53045: Move time related functions to POSIX platform file (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform-freebsd.cc ('k') | src/platform-macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // Seed the random number generator. 74 // Seed the random number generator.
75 // Convert the current time to a 64-bit integer first, before converting it 75 // Convert the current time to a 64-bit integer first, before converting it
76 // to an unsigned. Going directly can cause an overflow and the seed to be 76 // to an unsigned. Going directly can cause an overflow and the seed to be
77 // set to all ones. The seed will be identical for different instances that 77 // set to all ones. The seed will be identical for different instances that
78 // call this setup code within the same millisecond. 78 // call this setup code within the same millisecond.
79 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); 79 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
80 srandom(static_cast<unsigned int>(seed)); 80 srandom(static_cast<unsigned int>(seed));
81 } 81 }
82 82
83 83
84 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) {
85 struct rusage usage;
86
87 if (getrusage(RUSAGE_SELF, &usage) < 0) return -1;
88 *secs = usage.ru_utime.tv_sec;
89 *usecs = usage.ru_utime.tv_usec;
90 return 0;
91 }
92
93
94 double OS::TimeCurrentMillis() {
95 struct timeval tv;
96 if (gettimeofday(&tv, NULL) < 0) return 0.0;
97 return (static_cast<double>(tv.tv_sec) * 1000) +
98 (static_cast<double>(tv.tv_usec) / 1000);
99 }
100
101
102 int64_t OS::Ticks() {
103 // Linux's gettimeofday has microsecond resolution.
104 struct timeval tv;
105 if (gettimeofday(&tv, NULL) < 0)
106 return 0;
107 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec;
108 }
109
110
111 char* OS::LocalTimezone(double time) {
112 time_t tv = static_cast<time_t>(floor(time/msPerSecond));
113 struct tm* t = localtime(&tv);
114 return const_cast<char*>(t->tm_zone);
115 }
116
117
118 double OS::DaylightSavingsOffset(double time) {
119 time_t tv = static_cast<time_t>(floor(time/msPerSecond));
120 struct tm* t = localtime(&tv);
121 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0;
122 }
123
124
125 double OS::LocalTimeOffset() {
126 time_t tv = time(NULL);
127 struct tm* t = localtime(&tv);
128 // tm_gmtoff includes any daylight savings offset, so subtract it.
129 return static_cast<double>(t->tm_gmtoff * msPerSecond -
130 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
131 }
132
133
134 FILE* OS::FOpen(const char* path, const char* mode) { 84 FILE* OS::FOpen(const char* path, const char* mode) {
135 return fopen(path, mode); 85 return fopen(path, mode);
136 } 86 }
137 87
138 88
139 void OS::Print(const char* format, ...) { 89 void OS::Print(const char* format, ...) {
140 va_list args; 90 va_list args;
141 va_start(args, format); 91 va_start(args, format);
142 VPrint(format, args); 92 VPrint(format, args);
143 va_end(args); 93 va_end(args);
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 } 689 }
740 690
741 // This sampler is no longer the active sampler. 691 // This sampler is no longer the active sampler.
742 active_sampler_ = NULL; 692 active_sampler_ = NULL;
743 active_ = false; 693 active_ = false;
744 } 694 }
745 695
746 #endif // ENABLE_LOGGING_AND_PROFILING 696 #endif // ENABLE_LOGGING_AND_PROFILING
747 697
748 } } // namespace v8::internal 698 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-freebsd.cc ('k') | src/platform-macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698