我的服务器上运行的网站很少.
我在应用程序中有一个"诊断"页面,显示当前进程的内存量(非常有用).
现在这个应用程序"链接"到另一个应用程序,我希望我的诊断页面能够显示另一个w3wp进程的内存.
为了获得内存量,我使用了一个简单的代码:
var process = Process.GetProcessesByName("w3wp");
string memory = this.ToMemoryString(process.WorkingSet64);
Run Code Online (Sandbox Code Playgroud)
如何识别我的第二个w3wp进程,知道它的应用程序池?
我找到了一个相应的线程,但没有适当的答案: 在IIS6应用程序池上查看特定于进程的性能统计信息的可靠方法
谢谢
我使用FileVersionInfo.GetVersionInfo()得到一些严重的怪异,并希望有人可以提供帮助.
问题的基础是我正在遍历每个文件夹中调用GetVersionInfo()的所有文件.大约有300个文件.这适用于除2个文件之外的所有文件.对于这些DLL,我从GetVersionInfo()得到了完全不正确的信息.
为了消除所有其他变量,我将此调用提取到一个简单的测试应用程序中,它仍然遇到了同样的问题.但是,如果我将测试应用程序构建为Windows应用程序(最初是控制台应用程序),那么数据就会恢复正常.
只是为了澄清一下,当作为控制台应用程序运行时返回的不正确数据不仅仅是空信息,就像文件不包含版本数据一样.它包含合理的数据,但只包含错误的数据.就好像是从不同的文件中读取它一样.我找了一个包含匹配版本数据的文件,但找不到.
如果构建为控制台应用程序而不是Windows应用程序,为什么这个简单的调用功能会不同?
如果有人可以帮助我,我将非常感激.
安德,安迪
- 已添加代码
using System;
using System.Diagnostics;
namespace test
{
class Program
{
static void Main(string[] args)
{
string file = "C:\\ProblemFile.dll";
FileVersionInfo version = FileVersionInfo.GetVersionInfo(file);
string fileName = version.FileName;
string fileVersion = version.FileVersion;
Console.WriteLine(string.Format("{0} : {1}", fileName, fileVersion));
}
}
}
Run Code Online (Sandbox Code Playgroud) .net c# system.diagnostics console-application getfileversion
我编写了一个进程监视器命令行应用程序,它将参数作为参数:
该程序的作用是使用传递的名称或pid监视所有进程,如果它们的CPU使用率超过阈值%,则会杀死它们.
我有两个班:
ProcessMonitor和ProcessMonitorList
前者,包裹着System.Diagnostics.PerformanceCounter
后者是一个IEnumarable允许前者的列表式结构.
程序本身工作正常,但如果我在任务管理器上观察内存使用情况,它会以每秒约20kB的增量增长.注意:程序PerformanceCounter每秒轮询一次CPU计数器.
该程序需要在使用频繁的服务器上运行,并且正在监视大量进程.(20-30).
我使用PerfMon监视进程的私有字节数与所有堆中的字节总数,并根据下面引用的文章中提供的逻辑,我的结果表明,在波动时,值仍然在可接受的范围内,并且因此没有内存泄漏:
文章
我还使用FxCop来分析我的代码,并没有提出任何相关的内容.
不好意思只是说,哦,然后没有内存泄漏,我进一步调查,并发现(通过调试)以下代码行演示泄漏发生的位置,箭头显示确切的行.
_pc = new PerformanceCounter("Process", "% Processor Time", processName);
Run Code Online (Sandbox Code Playgroud)
以上是启动_pc的地方,并且是我ProcessMonitor班级的构造函数.
以下是导致内存泄漏的方法.这个方法每隔一秒从我的主要调用.
public float NextValue()
{
if (HasExited()) return PROCESS_ENDED;
if (_pc != null)
{
_lastSample = _pc.NextValue(); //<-----------------------
return _lastSample;
}
else return -1;
}
Run Code Online (Sandbox Code Playgroud)
这向我表明该NextValue()方法内部存在泄漏,该泄漏存在于System.Diagnostics.PerformanceCounter类中.
为什么Moq Verify失败并出现"Moq.MockException:未在模拟上执行调用"?
var mock = new Mock<TraceListener>();
var ts = new TraceSource("traceSourceName", SourceLevels.Verbose);
ts.Listeners.Add(mock.Object);
var message = "the message";
ts.TraceEvent(TraceEventType.Verbose, 0, message);
ts.Flush();
mock.Verify(x => x.WriteLine(message));
Run Code Online (Sandbox Code Playgroud) 我有一个实例PerformanceCounter,我打电话NextSample()给它并得到一个CounterSample.其中有几个与时间相关的字段:CounterFrequency,SystemFrequency,CounterTimeStamp,Timestamp和TimeStamp100nSec.
CounterSample的MSDN页面仅显示"获取原始计数器频率"和类似的无用描述,以及打印该值而不解释的示例.
DateTime.FromX()功能,但没有一个产生合理的结果.我正在使用System.Diagnostics类从我的C#应用程序执行批处理文件,在整个过程中使用输出更新我的GUI,但是只要我的批处理文件超过一定数量的行,该过程就会挂起.确切的线条数量似乎有所不同,但我已经能够使用一个简单的批处理文件重现它,打印出"Hello Kitty"316次:
@echo off
echo Hello Kitty
echo Hello Kitty
Run Code Online (Sandbox Code Playgroud)
等等
如果我删除第316行,批处理文件执行正常,表单应用程序按预期运行,但是更多行导致进程无限期挂起,甚至不生成前300个hello kitty中的一个.
这是我执行批处理文件的代码:
process = new System.Diagnostics.Process();
process.StartInfo.FileName = batchName;
process.StartInfo.Arguments = " < nul";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.Start();
Run Code Online (Sandbox Code Playgroud)
这些在其他地方宣布:
protected Process process;
protected StreamReader output;
Run Code Online (Sandbox Code Playgroud)
我的主要表单做了这样的事情(简化了一点):
string output;
while (!proc.Process.HasExited)
{
proc.Process.WaitForExit(200);
if (proc.Process.HasExited)
{
output = proc.Output.ReadToEnd();
rtbStatus.AppendText(output);
}
Application.DoEvents();
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会这样做,我在网上找到的例子都没有提到批处理文件的大小限制.请指教.
当我看到一篇文章时,我正在寻找一种解决方案,为我的最新项目提供日志记录(http://www.daveoncsharp.com/2009/09/create-a-logger-using-the-trace-listener-in- csharp /)谈到使用System.Diagnostics和App.config通过Trace方法进行记录.我能够成功实现类和App.config,但我真的希望能够动态分配日志文件的值/位置(在initializeData内),我不知道如何做到这一点.如果您有任何建议,请随时发布!
App.config中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="fileSizeThreshold=512, fileSizeUnit=kilobytes,
fileAgeThreshold=1, fileAgeUnit=months, fileNameTemplate='{0}\MyApp-{1:MMM-yy}.log'"/>
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
Run Code Online (Sandbox Code Playgroud)
记录器类:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace MyCurrentProject
{
class Logger
{
public void Error(string module, string message)
{
WriteEntry(message, "ERROR:", module);
}
public void Error(Exception ex, string module)
{
WriteEntry(ex.Message, "ERROR:", module);
}
public void Warning(string module, string message)
{
WriteEntry(message, "WARNING:", module); …Run Code Online (Sandbox Code Playgroud) 我正在尝试将监听器附加到正在运行的进程,该进程使用EventSource跟踪处理事件.我已经通过继承EventListener和(可能)需要调用EnableEvents以开始接收信息来创建我自己的监听器.
所有重载的第一个参数是EventSource配置和发送消息,但我不清楚如何在需要识别外部进程中的事件源时组成该实例.
我只是将它们作为一个概念验证,因此代码在控制台应用程序中运行,并且TestEventListener只是尝试将事件写入控制台窗口.
EventSource source = null;
using (var listener = new TestEventListener())
{
listener.EnableEvents(source, EventLevel.Verbose);
Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud) 我有这个小功能,可以省去处理可怕的System.Diagnostics.Process API的一些麻烦:
let HiddenExec (command: string, arguments: string) =
let startInfo = new System.Diagnostics.ProcessStartInfo(command)
startInfo.Arguments <- arguments
startInfo.UseShellExecute <- false
startInfo.RedirectStandardError <- true
startInfo.RedirectStandardOutput <- true
use proc = System.Diagnostics.Process.Start(startInfo)
proc.WaitForExit()
(proc.ExitCode,proc.StandardOutput.ReadToEnd(),proc.StandardError.ReadToEnd())
Run Code Online (Sandbox Code Playgroud)
这很好用,因为我得到了一个包含exitcode,stdout和stderr结果的三个元素的元组.
现在,假设我不想"隐藏"执行.也就是说,我想写一个假设的,更简单的Exec函数.然后解决方案是不重定向stdout/stderr,我们完成了:
let Exec (command: string, arguments: string) =
let startInfo = new System.Diagnostics.ProcessStartInfo(command)
startInfo.Arguments <- arguments
startInfo.UseShellExecute <- false
let proc = System.Diagnostics.Process.Start(startInfo)
proc.WaitForExit()
proc.ExitCode
Run Code Online (Sandbox Code Playgroud)
但是,如果我可以重构这两个函数将它们聚合成一个函数,并且只是向它传递一个"隐藏的"bool标志,那将是很好的:
let NewExec (command: string, arguments: string, hidden: bool) =
Run Code Online (Sandbox Code Playgroud)
这样,NewExec(_,_,false)也会返回stdout,stderr(不仅像之前一样退出exitCode).问题是,如果我不进行重定向舞蹈(startInfo.RedirectStandardError <- true),那么我以后无法从输出中读取,proc.StandardOutput.ReadToEnd()因为我得到了错误StandardOut has not …
.net f# system.diagnostics processstartinfo redirectstandardoutput
我有一个.net核心Web API项目。我只是想让我的以下跟踪语句出现在应用程序见解中:
Trace.TraceInformation("Hello World!");
Run Code Online (Sandbox Code Playgroud)
在调试时,我在输出窗口中看到日志,但是在部署后,在日志中没有看到任何跟踪语句。...为什么?
我有和Microsoft.ApplicationInsights.AspNetCore,Microsoft.ApplicationInsights.TraceListener包括包装。
我知道App洞察力已经设置好了,因为正在出现请求,并且我从未收集的性能指标中得到了一条跟踪消息(请参阅下面的跟踪消息):
AI: Error collecting 3 of the configured performance counters. Please check the configuration.
Counter \ASP.NET Applications(??APP_W3SVC_PROC??)\Requests/Sec: Failed to perform the first read for performance counter. Please make sure it exists. Category: ASP.NET Applications, counter: Requests/Sec, instance MyAPI.exe
Counter \ASP.NET Applications(??APP_W3SVC_PROC??)\Request Execution Time: Failed to perform the first read for performance counter. Please make sure it exists. Category: ASP.NET Applications, counter: Request Execution Time, instance MyAPI.exe
Counter \ASP.NET Applications(??APP_W3SVC_PROC??)\Requests In …Run Code Online (Sandbox Code Playgroud) c# trace system.diagnostics azure-application-insights .net-core
c# ×7
trace ×3
.net ×2
.net-core ×1
app-config ×1
batch-file ×1
f# ×1
iis ×1
logging ×1
memory-leaks ×1
mocking ×1
moq ×1
w3wp ×1