Skip to content

Commit 40e83e8

Browse files
fix the compilation errors for latest PG build (#9)
Co-authored-by: Kritika Agarwal <[email protected]>
1 parent fe36f4e commit 40e83e8

7 files changed

+57
-50
lines changed

darwin/cpu_info.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void ReadCPUInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
111111
values[Anum_cpu_type] = CStringGetTextDatum(s_cpu_type);
112112
values[Anum_logical_processor] = Int32GetDatum(logical_cpu);
113113
values[Anum_physical_processor] = Int32GetDatum(physical_cpu);
114-
values[Anum_cpu_clock_speed] = Int64GetDatumFast(cpu_frequency);
114+
values[Anum_cpu_clock_speed] = UInt64GetDatum(cpu_frequency);
115115
values[Anum_l1dcache_size] = Int32GetDatum((int)(l1d_cache_bytes/1024));
116116
values[Anum_l1icache_size] = Int32GetDatum((int)(l1i_cache_bytes/1024));
117117
values[Anum_l2cache_size] = Int32GetDatum((int)(l2_cache_bytes/1024));

darwin/cpu_memory_by_process.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void ReadCPUMemoryByProcess(Tuplestorestate *tupstore, TupleDesc tupdesc)
183183
memory_usage = (float)((int)(memory_usage * 100 + 0.5))/100;
184184
values[Anum_percent_cpu_usage] = Float4GetDatum(cpu_usage);
185185
values[Anum_percent_memory_usage] = Float4GetDatum(memory_usage);
186-
values[Anum_process_memory_bytes] = Int64GetDatumFast((uint64)rss_memory);
186+
values[Anum_process_memory_bytes] = UInt64GetDatum((uint64)rss_memory);
187187
}
188188
else
189189
{

darwin/cpu_usage_info.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void ReadCPUUsageStatistics(Tuplestorestate *tupstore, TupleDesc tupdesc)
5252
Datum values[Natts_cpu_usage_stats];
5353
bool nulls[Natts_cpu_usage_stats];
5454
struct cpu_stat first_sample, second_sample;
55+
float4 total, user, system, idle, nice;
5556

5657
memset(nulls, 0, sizeof(nulls));
5758

@@ -71,11 +72,11 @@ void ReadCPUUsageStatistics(Tuplestorestate *tupstore, TupleDesc tupdesc)
7172
return;
7273
}
7374

74-
float4 total = (float4)(second_sample.total - first_sample.total);
75-
float4 user = (float4)(second_sample.user - first_sample.user) / total * 100;
76-
float4 system = (float4)(second_sample.system - first_sample.system) / total * 100;
77-
float4 idle = (float4)(second_sample.idle - first_sample.idle) / total * 100;
78-
float4 nice = (float4)(second_sample.nice - first_sample.nice) / total * 100;
75+
total = (float4)(second_sample.total - first_sample.total);
76+
user = (float4)(second_sample.user - first_sample.user) / total * 100;
77+
system = (float4)(second_sample.system - first_sample.system) / total * 100;
78+
idle = (float4)(second_sample.idle - first_sample.idle) / total * 100;
79+
nice = (float4)(second_sample.nice - first_sample.nice) / total * 100;
7980

8081
values[Anum_usermode_normal_process] = Float4GetDatum(user);
8182
values[Anum_usermode_niced_process] = Float4GetDatum(nice);

darwin/disk_info.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ void ReadDiskInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
9999
uint64 total_inodes = 0;
100100
uint64 used_inodes = 0;
101101
uint64 free_inodes = 0;
102+
struct statfs *buf;
103+
int total_count = 0;
104+
int i = 0;
102105

103106
memset(nulls, 0, sizeof(nulls));
104107
memset(file_system, 0, MAXPGPATH);
105108
memset(mount_point, 0, MAXPGPATH);
106109
memset(file_system_type, 0, MAXPGPATH);
107110

108-
struct statfs *buf;
109-
int total_count = 0;
110-
int i = 0;
111111
total_count = getmntinfo(&buf, MNT_NOWAIT);
112112
for(i = 0; i < total_count; i++)
113113
{
@@ -137,12 +137,12 @@ void ReadDiskInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
137137
values[Anum_disk_file_system] = CStringGetTextDatum(file_system);
138138
values[Anum_disk_file_system_type] = CStringGetTextDatum(file_system_type);
139139
values[Anum_disk_mount_point] = CStringGetTextDatum(mount_point);
140-
values[Anum_disk_total_space] = Int64GetDatumFast(total_space_bytes);
141-
values[Anum_disk_used_space] = Int64GetDatumFast(used_space_bytes);
142-
values[Anum_disk_free_space] = Int64GetDatumFast(available_space_bytes);
143-
values[Anum_disk_total_inodes] = Int64GetDatumFast(total_inodes);
144-
values[Anum_disk_used_inodes] = Int64GetDatumFast(used_inodes);
145-
values[Anum_disk_free_inodes] = Int64GetDatumFast(free_inodes);
140+
values[Anum_disk_total_space] = UInt64GetDatum(total_space_bytes);
141+
values[Anum_disk_used_space] = UInt64GetDatum(used_space_bytes);
142+
values[Anum_disk_free_space] = UInt64GetDatum(available_space_bytes);
143+
values[Anum_disk_total_inodes] = UInt64GetDatum(total_inodes);
144+
values[Anum_disk_used_inodes] = UInt64GetDatum(used_inodes);
145+
values[Anum_disk_free_inodes] = UInt64GetDatum(free_inodes);
146146

147147
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
148148

darwin/io_analysis.c

+23-18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#include <IOKit/ps/IOPSKeys.h>
2323
#undef Size
2424

25+
#if (MAC_OS_X_VERSION_MAX_ALLOWED < 120000) // Before macOS 12 Monterey
26+
#define kIOMainPortDefault kIOMasterPortDefault
27+
#endif
28+
2529
/* Function used to get IO statistics of block devices */
2630
void ReadIOAnalysisInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
2731
{
@@ -37,7 +41,7 @@ void ReadIOAnalysisInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
3741
memset(nulls, 0, sizeof(nulls));
3842

3943
// Get list of disks
40-
if (IOServiceGetMatchingServices(kIOMasterPortDefault,
44+
if (IOServiceGetMatchingServices(kIOMainPortDefault,
4145
IOServiceMatching(kIOMediaClass),
4246
&disk_list_iter) != kIOReturnSuccess)
4347
{
@@ -63,6 +67,17 @@ void ReadIOAnalysisInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
6367

6468
if (IOObjectConformsTo(parent_reg_ent, "IOBlockStorageDriver"))
6569
{
70+
const int kMaxDiskNameSize = 64;
71+
char device_name[kMaxDiskNameSize];
72+
CFStringRef disk_name_ref;
73+
CFNumberRef number;
74+
int64_t reads = 0;
75+
int64_t writes = 0;
76+
int64_t read_bytes = 0;
77+
int64_t write_bytes = 0;
78+
int64_t read_time_ns = 0;
79+
int64_t write_time_ns = 0;
80+
6681
if (IORegistryEntryCreateCFProperties(
6782
disk_reg_ent,
6883
(CFMutableDictionaryRef *) &disk_parent_dict,
@@ -89,9 +104,7 @@ void ReadIOAnalysisInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
89104
return;
90105
}
91106

92-
const int kMaxDiskNameSize = 64;
93-
CFStringRef disk_name_ref = (CFStringRef)CFDictionaryGetValue(disk_parent_dict, CFSTR(kIOBSDNameKey));
94-
char device_name[kMaxDiskNameSize];
107+
disk_name_ref = (CFStringRef)CFDictionaryGetValue(disk_parent_dict, CFSTR(kIOBSDNameKey));
95108

96109
CFStringGetCString(disk_name_ref,
97110
device_name,
@@ -112,14 +125,6 @@ void ReadIOAnalysisInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
112125
return;
113126
}
114127

115-
CFNumberRef number;
116-
int64_t reads = 0;
117-
int64_t writes = 0;
118-
int64_t read_bytes = 0;
119-
int64_t write_bytes = 0;
120-
int64_t read_time_ns = 0;
121-
int64_t write_time_ns = 0;
122-
123128
// Get disk reads/writes
124129
if ((number = (CFNumberRef)CFDictionaryGetValue(
125130
disk_stats_dict,
@@ -167,12 +172,12 @@ void ReadIOAnalysisInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
167172
write_time_ns = (int64_t)round(write_time_ns/1000000);
168173

169174
values[Anum_device_name] = CStringGetTextDatum(device_name);
170-
values[Anum_total_read] = Int64GetDatumFast(reads);
171-
values[Anum_total_write] = Int64GetDatumFast(writes);
172-
values[Anum_read_bytes] = Int64GetDatumFast(read_bytes);
173-
values[Anum_write_bytes] = Int64GetDatumFast(write_bytes);
174-
values[Anum_read_time_ms] = Int64GetDatumFast(read_time_ns);
175-
values[Anum_write_time_ms] = Int64GetDatumFast(write_time_ns);
175+
values[Anum_total_read] = UInt64GetDatum(reads);
176+
values[Anum_total_write] = UInt64GetDatum(writes);
177+
values[Anum_read_bytes] = UInt64GetDatum(read_bytes);
178+
values[Anum_write_bytes] = UInt64GetDatum(write_bytes);
179+
values[Anum_read_time_ms] = UInt64GetDatum(read_time_ns);
180+
values[Anum_write_time_ms] = UInt64GetDatum(write_time_ns);
176181

177182
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
178183

darwin/memory_info.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void ReadMemoryInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
3232
uint64_t total;
3333
size_t len = sizeof(total);
3434
int pagesize = getpagesize();
35+
mach_port_t mport;
3536

3637
memset(nulls, 0, sizeof(nulls));
3738

@@ -45,7 +46,7 @@ void ReadMemoryInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
4546
return;
4647
}
4748

48-
mach_port_t mport = mach_host_self();
49+
mport = mach_host_self();
4950

5051
/* Read the host memory statistics */
5152
ret = host_statistics(mport, HOST_VM_INFO, (host_info_t)&vm_stat, &count);
@@ -69,12 +70,12 @@ void ReadMemoryInformation(Tuplestorestate *tupstore, TupleDesc tupdesc)
6970
ereport(DEBUG1, (errmsg("Error while getting swap memory information")));
7071
}
7172

72-
values[Anum_total_memory] = Int64GetDatumFast(total_memory_bytes);
73-
values[Anum_used_memory] = Int64GetDatumFast(used_memory_bytes);
74-
values[Anum_free_memory] = Int64GetDatumFast(free_memory_bytes);
75-
values[Anum_swap_total_memory] = Int64GetDatumFast(swap_mem.xsu_total);
76-
values[Anum_swap_used_memory] = Int64GetDatumFast(swap_mem.xsu_used);
77-
values[Anum_swap_free_memory] = Int64GetDatumFast(swap_mem.xsu_avail);
73+
values[Anum_total_memory] = UInt64GetDatum(total_memory_bytes);
74+
values[Anum_used_memory] = UInt64GetDatum(used_memory_bytes);
75+
values[Anum_free_memory] = UInt64GetDatum(free_memory_bytes);
76+
values[Anum_swap_total_memory] = UInt64GetDatum(swap_mem.xsu_total);
77+
values[Anum_swap_used_memory] = UInt64GetDatum(swap_mem.xsu_used);
78+
values[Anum_swap_free_memory] = UInt64GetDatum(swap_mem.xsu_avail);
7879
nulls[Anum_total_cache_memory] = true;
7980
nulls[Anum_kernel_total_memory] = true;
8081
nulls[Anum_kernel_paged_memory] = true;

darwin/network_info.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,15 @@ void ReadNetworkInformations(Tuplestorestate *tupstore, TupleDesc tupdesc)
151151

152152
values[Anum_net_interface_name] = CStringGetTextDatum(interface_name);
153153
values[Anum_net_ipv4_address] = CStringGetTextDatum(ipv4_address);
154-
values[Anum_net_speed_mbps] = Int64GetDatumFast(speed_mbps);
155-
values[Anum_net_tx_bytes] = Int64GetDatumFast(tx_bytes);
156-
values[Anum_net_tx_packets] = Int64GetDatumFast(tx_packets);
157-
values[Anum_net_tx_errors] = Int64GetDatumFast(tx_errors);
158-
values[Anum_net_tx_dropped] = Int64GetDatumFast(tx_dropped);
159-
values[Anum_net_rx_bytes] = Int64GetDatumFast(rx_bytes);
160-
values[Anum_net_rx_packets] = Int64GetDatumFast(rx_packets);
161-
values[Anum_net_rx_errors] = Int64GetDatumFast(rx_errors);
162-
values[Anum_net_rx_dropped] = Int64GetDatumFast(rx_dropped);
154+
values[Anum_net_speed_mbps] = UInt64GetDatum(speed_mbps);
155+
values[Anum_net_tx_bytes] = UInt64GetDatum(tx_bytes);
156+
values[Anum_net_tx_packets] = UInt64GetDatum(tx_packets);
157+
values[Anum_net_tx_errors] = UInt64GetDatum(tx_errors);
158+
values[Anum_net_tx_dropped] = UInt64GetDatum(tx_dropped);
159+
values[Anum_net_rx_bytes] = UInt64GetDatum(rx_bytes);
160+
values[Anum_net_rx_packets] = UInt64GetDatum(rx_packets);
161+
values[Anum_net_rx_errors] = UInt64GetDatum(rx_errors);
162+
values[Anum_net_rx_dropped] = UInt64GetDatum(rx_dropped);
163163

164164
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
165165

0 commit comments

Comments
 (0)