unix_lat.c

/*
Measure latency of IPC using unix domain sockets
Copyright (c) 2010 Erik Rigtorp <erik@rigtorp.com>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <time.h>
#include <stdint.h>
int main(int argc, char *argv[])
{
  int sv[2]; /* the pair of socket descriptors */
  int size;
  char *buf;
  int64_t count, i, delta;
  struct timeval start, stop;
  if (argc != 3) {
    printf ("usage: unix_lat <message-size> <roundtrip-count>\n");
    return 1;
  }
  size = atoi(argv[1]);
  count = atol(argv[2]);
  buf = malloc(size);
  if (buf == NULL) {
    perror("malloc");
    return 1;
  }
  printf("message size: %i octets\n", size);
  printf("roundtrip count: %lli\n", count);
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) {
    perror("socketpair");
    exit(1);
  }
  if (!fork()) { /* child */
    for (i = 0; i < count; i++) {
      
      if (read(sv[1], buf, size) != size) {
        perror("read");
        return 1;
      }
      
      if (write(sv[1], buf, size) != size) {
        perror("write");
        return 1;
      }
    }
  } else { /* parent */
    gettimeofday(&start, NULL);
    for (i = 0; i < count; i++) {
      if (write(sv[0], buf, size) != size) {
        perror("write");
        return 1;
      }
      if (read(sv[0], buf, size) != size) {
        perror("read");
        return 1;
      }
      
    }
    gettimeofday(&stop, NULL);
    delta = ((stop.tv_sec - start.tv_sec) * (int64_t) 1e6 +
stop.tv_usec - start.tv_usec);
    
    printf("average latency: %lli us\n", delta / (count * 2));
  }
  
  return 0;
}
@echo off :: 确保 Python 已安装 where python >nul 2>nul if %errorlevel% neq 0 ( echo Python 未安装或未配置到环境变量中! pause exit /b ) :: 运行 Python 脚本 python - <<END import rioxarray as rxr import geopandas as gpd import matplotlib.pyplot as plt import numpy as np import cartopy.crs as ccrs from matplotlib.colors import BoundaryNorm # 读取高程数据 fili = "D:\测试\GMTED2010_land.tif" f = rxr.open_rasterio(fili) f = f.isel(band=0) # 读取山西地图底图数据 mapurl = "https://geo.datav.aliyun.com/areas_v3/bound/140000.json" smap = gpd.read_file(mapurl) # 数据裁剪处理 xmin = smap.bounds['minx'][0] - 0.1 xmax = smap.bounds['maxx'][0] + 0.1 ymin = smap.bounds['miny'][0] - 0.1 ymax = smap.bounds['maxy'][0] + 0.1 lon = f.coords["x"] lat = f.coords["y"] da = f.loc[dict( x=lon[(lon >= xmin) & (lon <= xmax)], y=lat[(lat >= ymin) & (lat <= ymax)] )] lon = da.coords["x"] lat = da.coords["y"] Lon, Lat = np.meshgrid(lon, lat) # 基础绘图 mapcrs = ccrs.PlateCarree() fig = plt.figure(figsize=(8, 8)) ax = plt.axes(projection=mapcrs) ax.add_geometries(smap['geometry'], crs=mapcrs, fc="none", edgecolor="black", linewidth=0.6) pm = ax.pcolormesh(Lon, Lat, da, cmap='terrain', transform=mapcrs) cb = fig.colorbar(pm, ax=ax, shrink=0.9, location="right") plt.savefig("C:/pyMet/figures/shanxi1.png", dpi=600) plt.show() # 进阶绘图 plt.rcParams['font.family'] = 'SimHei' fig = plt.figure(figsize=(8, 8)) ax = plt.axes(projection=mapcrs) ax.add_geometries(smap['geometry'], crs=mapcrs, fc="none", edgecolor="black", linewidth=0.8) levels = np.arange(50, 2501, 100) colorMap = plt.colormaps['terrain'] colorNorm = BoundaryNorm(levels, ncolors=colorMap.N, extend='both') pm = ax.pcolormesh(Lon, Lat, da, cmap=colorMap, norm=colorNorm, transform=mapcrs) cb = fig.colorbar(pm, ax=ax, shrink=0.9, location="right", pad=0.06) # 添加太原位置 pts_lon = 112.55 pts_lat = 37.87 ax.scatter(pts_lon, pts_lat, color='red', linewidth=2, marker='^', transform=mapcrs) ax.text(pts_lon, pts_lat + 0.15, '太原', horizontalalignment='center', color="red", transform=mapcrs) # 添加网格线 ax.gridlines(draw_labels={"bottom": "x", "left": "y", "right": "y"}, linewidth=0.5, linestyle='--', color='black') ax.set_title("山西省高程图") plt.tight_layout() plt.savefig("C:/pyMet/figures/shanxi2.png", dpi=600) plt.show() END 为什么在windosw上使用bat运行不了,没有反应
06-19
处理 2000 年时出错: [Errno 13] Permission denied: b'D:\\Research\\\xe5\x8f\xb0\xe9\xa3\x8e\xe9\xab\x98\xe6\xb8\xa9\\\xe6\xb9\xbf\xe5\xba\xa6\xe6\x95\xb0\xe6\x8d\xae\\moisture_flux_2000.nc' Traceback (most recent call last): File "D:\anaconda\Lib\site-packages\xarray\backends\file_manager.py", line 211, in _acquire_with_cache_info file = self._cache[self._key] ~~~~~~~~~~~^^^^^^^^^^^ File "D:\anaconda\Lib\site-packages\xarray\backends\lru_cache.py", line 56, in __getitem__ value = self._cache[key] ~~~~~~~~~~~^^^^^ KeyError: [<class 'netCDF4._netCDF4.Dataset'>, ('D:\\Research\\台风高温\\湿度数据\\moisture_flux_2000.nc',), 'a', (('clobber', True), ('diskless', False), ('format', 'NETCDF4'), ('persist', False)), '61de2c3c-dd59-4fd4-be98-0ecaa34b1b26'] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\邓载昀\AppData\Local\Temp\ipykernel_19388\2883981162.py", line 105, in process_daily_moisture_flux result_path = save_daily_moisture_flux(year, moisture_flux_ds) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\邓载昀\AppData\Local\Temp\ipykernel_19388\1636070326.py", line 15, in save_daily_moisture_flux moisture_flux_ds.to_netcdf(save_path) File "D:\anaconda\Lib\site-packages\xarray\core\dataset.py", line 2346, in to_netcdf return to_netcdf( # type: ignore[return-value] # mypy cannot resolve the overloads:( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda\Lib\site-packages\xarray\backends\api.py", line 1855, in to_netcdf store = store_open(target, mode, format, group, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda\Lib\site-packages\xarray\backends\netCDF4_.py", line 453, in open return cls(manager, group=group, mode=mode, lock=lock, autoclose=autoclose) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
最新发布
07-16
shell语句#!/bin/bash filename="./lmbench_logs/log_$(date +%s).txt" # 使用Unix时间戳命名文件 mkdir -p "./lmbench_logs" command_to_run="./lat_mem_rd -P 1 -N 5 -t 1024m 1024" # 替换为实际需要运行的命令 for ((i=1; i<=3; i++)); do echo "==== 第$i次运行 ====" >> "$filename" $command_to_run >> "$filename" 2>&1 echo "" >> "$filename" # 添加空行分隔结果 done echo "success: $PWD/$filename"结合Pythonimport matplotlib.pyplot as plt def parse_data(filename): groups = [] current_group = [] capture = False with open(filename, 'r') as f: for line in f: line = line.strip() # 检测数据块起始标志 if line.startswith('depth(MB)') and 'latency(ns)' in line: capture = True current_group = [] continue # 遇到空行结束当前数据块 if not line and capture: groups.append(current_group) capture = False continue # 数据行处理 if capture and line: try: depth, latency = map(float, line.split()) current_group.append((depth, latency)) except ValueError: print(f"忽略格式错误行: {line}") return groups # 读取数据文件 data_groups = parse_data('D:/logs/1x_1.txt') # 创建画布 plt.figure(figsize=(10, 6)) colors = ['red', 'blue', 'green'] markers = ['o', 's', '^'] # 绘制各组数据 for i, group in enumerate(data_groups): if not group: continue depths, latencies = zip(*group) plt.scatter(depths, latencies, c=colors[i % 3], marker=markers[i % 3], label=f'Group {i + 1}', alpha=0.7) # 添加标注 plt.title('Memory Depth vs Access Latency') plt.xlabel('Depth (MB)') plt.ylabel('Latency (ns)') plt.grid(True) plt.legend() # 显示图表 plt.show()要求:Python里需要使用的文件名是上面shell生成的
05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值