29 ms·
The worst API ever made (2014)
- vietthan 3y agoBravo. I know nothing about this technically but it was succinct and conveyed the frustration superbly.
- thefourthchime 3y agoI used to be a Windows programmer and dealt with APIs like this all the time. Honestly, the Event Tracing API is consistent with all of the Win32 APIs. They're pretty freaking horrible. It's like filling out a bunch of tax documents to do anything.
- bentcorner 3y agoI think this explains ETW's horribleness pretty well: > Now, normally, a game developer would have no reason to use the Event Tracing for Windows API directly. You can use tools like PerfMon to view logged information about your game, like how much working set it was using or how much disk I/O it did. But there is one specific thing that directly accessing Event Tracing gives you that you can’t get anywhere else: context switch timing. It's been awhile since I've run wpa and wpr but I thought you got context switch timing these days with the built in tools such that there's no need to do it yourself. IMO having a good ETW API is probably low ROI.
- schemescape 3y agoThere's also been xperf and Process Monitor for a long time. It's not clear to me from the article why they needed to use the underlying API instead of the tooling built on top.
- erulabs 3y ago> I don’t think people who make APIs really appreciate how important it is to get them right, and how much unnecessary work their mistakes can cause for hundreds, thousands, sometimes even millions of other programmers. When I was a kid I tried to build a windows app. Getting a notepad clone even kind of close was a triumph for me, but I decided I wasn’t smart enough to be a programmer, and it set me back about 8 years at least. I was about 19 and a jr sysadmin changing air conditioning units when I finally sorted out the vast majority of coding is vastly simpler and vastly more fun than win32. Those windows APIs cost me a lot of time!
- lockhouse 3y agoAs a kid, I noped right out of raw Win32 API and reached for MFC instead. It made writing Windows applications so much easier.
- paulryanrogers 3y agoMFC felt pretty awkward to me, though I was introduced to it after Swing and C. I suppose it's all matter of perspectives and preferences.
- user3939382 3y agoI looked at WPF a few users ago and my impression was, I could spend 2 hours doing something I could easily do in the browser in 15 minutes. Maybe it's not that bad once you get the hang of it, but it looked so arduous I immediately decided I didn't have the will to go farther.
- eternityforest 3y agoAs far as I'm concerned the only easy UI is a declarative reactive UI. Vue and to a degree Flutter make everything look hard
- worthless-trash 3y agoWhat is an example of this? (non ui programmer here).
- eternityforest 3y agohttps://vuejs.org/guide/quick-start.html https://vuejs.org/guide/quick-start.html The "Global build" section shows off how easy it can be the best. More complicated stuff with modules might be harder especially when dealing with NPM build stuff, but it's generally pretty nice.
- deaddodo 3y ago
- alpb 3y agoI worked at Microsoft early-career and one of the projects I worked on was to integrate with ETW from a Go program to plumb events from Go code into ETW. I would also agree that this is one of the APIs that take a really long time to reason about it and some parts just feel like this API should not've been exposed to anyone who's not on the Windows team at all.
- ghosty141 3y agoDid you ask why that API is so bad? My guess is "well for historical reason [...]".
- masfuerte 3y agoAlthough it's a single API, the application event tracing doesn't seem to have much in common with the kernel event tracing. I got the impression that they were separate projects, someone made the decision to jam them together, and it's just a mess. But I have no inside knowledge.
- cortesoft 3y agoIs the JDSL not the worst API ever made? https://thedailywtf.com/articles/the-inner-json-effect https://thedailywtf.com/articles/the-inner-json-effect
- sublinear 3y agoI've read this one a few times and first heard it paraphrased in conversation years ago. I'm convinced it's a myth, but an entertaining one.
- Tainnor 3y agoI'm convinced at least 50% of thedailywtf is made up. But maybe that's just something I tell myself so I can sleep better.
- Ygg2 3y agoI'm convinced 75% of it is real. I don't sleep at night.
- moffkalast 3y agoYou sleep during the day?
- Ygg2 3y agoNo :P
- formerly_proven 3y agoI think most of it is made up but I’ve also seen a database schema and usage pattern (in an enterprise / MSSQL application) that’s far worse than anything I’ve read on that site so maybe it isn’t. But a lot of the stories have this ring of made-upness to it.
- 3y ago
- openthc 3y agoFor many years (since 2014) the API for Metrc (the cannabis reporting engine in Colorado and other states) would NEVER return any useful data at all, simply an empty JSON array. So after each operation, one would have to query the search endpoint for plants or inventory to discover the new items -- and hope you could positively identify which one was the new one you were looking for. That and not supporting B2B transactions via their API. They would alternately claim it's for security or that the States were not asking for it. States would tell other software vendors that Metrc coludn't do it. Neither party could move the ball. Only now, in 2023, have they started responding with the ID of the newly created items (why not a fully inflated record of what was just created) and working to support B2B. These state run APIs, from a for-profit corporation, are not good for the public (they hide, or cannot handle important laboratory testing data) and they are not good for the licensees, especially the small businesses. And there is no accountability -- agency points to vendor & vendor points to agency. Sadly, getting these State agencies to understand the beauty of distributed/federated systems -- and the difficutly for small businesses to respond to RFPs -- keep us from having nice things. End of rant.
- mfrisbie 3y agoMy favorite Metrc API wart was submitting harvests when their API servers were bogged down. Sometimes, your "create harvest" request would get stuck in a transaction pool that wouldn't timeout for 10 minutes. You'd have to wait the full 10 minutes to see if it succeeded or not because setting a shorter timeout would risk double-submitting the harvest, thereby completely screwing up that cannabis business's compliance data.
- eyelidlessness 3y agoOh, if only it were that simple across the board! One of my favorites was getting any number of errors (timeouts, various internal errors) only to discover later that the reporting did sometimes, eventually, unpredictably succeed despite whatever error had been returned and regardless of how fatal the error message might have seemed to be. And often this occurred during waves of intermittent outages, where determining any given success might take hours. And in any case, correlating success for some resources was partly guesswork, matching data to the timestamps we reported, which of course lost fidelity in their system because… SQL Server stores it that way, I guess.
- kazinator 3y agoAn importunately verbose and complicated API that I've recently come across is that of LMDB. https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Databa... Here is a long page explaining how to initialize things. (Warning: HTTP only!) http://www.lmdb.tech/doc/starting.html http://www.lmdb.tech/doc/starting.html Ya gotta create an environment with mdb_env_create. So okay, that is ready to use, right? Constructor has been called, we have an object, right? Nope! You have to open it now, with mdb_env_open. But what the above page doesn't tell you is that mdb_env_create has flags. Oooh yeah. MDB_FIXEDMAP, MDB_NOSUBDIR, MDB_RDONLY, MDB_WRITEMAP, MDB_NOMETASYNC, MDB_NOSYNC, MDB_NOTLS, MDB_NOLOCK, MDB_NORDAHEAD, MDB_NOMEMINIT, ... What are all these for? Should you be using any of them? Are the defaults good? So, once we have an env with the right flags, we can mdb_txn_begin. This takes flags again. Luckily, only MDB_RDONLY applies. Probably .... So we are ready to transact now, right? Nope. "Once a transaction has been created, a database can be opened within it using mdb_dbi_open()." [Which has seven flags!] But wait, the documentation hastens to add: "[a]lso, mdb_env_set_maxdbs() must be called after mdb_env_create() and before mdb_env_open() to set the maximum number of named databases you want to support." Finally, "[w]ithin a transaction, mdb_get() and mdb_put() can store single key/value pairs if that is all you need to do (but see Cursors below if you want to do more)." Ah cursors. Here, mdb_cursor_create doesn't have flags, phew! But there is an integer op code. mdb_cursor_get is basically the ioctl of database access. MDB_FIRST, MDB_FIRST_DUP, MDB_GET_BOTH, MDB_GET_BOTH_RANGE, MDB_GET_CURRENT, MDB_GET_MULTIPLE, MDB_LAST, MDB_LAST_DUP, MDB_NEXT, MDB_NEXT_DUP, MDB_NEXT_MULTIPLE, MDB_NEXT_NODUP, MDB_PREV, MDB_PREV_DUP, MDB_PREV_NODUP, MDB_SET, MDB_SET_KEY, MDB_SET_RANGE.
- malkia 3y agoI disagree, lmdb is exactly what you need to run exactly where you want. No more, no less.
- kazinator 3y agoEvery flag you don't use is more than what you need or want and could be a compile-time configuration option to remove the associated code which implements the flag. Functions represented as integer codes that go through a common dispatch function similar to ioctl lead to compiled code from which the linker cannot remove unused functions. If instead of a MDB_GET_BOTH_RANGE opcode to mdb_cursor_get there was a mdb_cursor_get_both_range function, then if you don't use that function, it could be removed out of the executable. (If it's put into its own object file, and the database library is statically linked.)
- bitwize 3y agoIt's really on-brand for Microsoft Windows APIs. They're all about making you fill out a giant tax form of a struct and passing the OS a callback. It's kind of a house style that Microsoft adopted back in the Windows 3.x or before days and it stuck. My favorite is the Dir() function in Visual Basic which is used for directory walking. Only it's non-reentrant, so you can't walk subdirectories with it! Near as I can tell it's traceable back to DIR$ in GW-BASIC, which in turn was an exposure of DOS's broken, non-reentrant GetDirectoryEntry and NextDirectoryEntry system calls! DOS will just never die!
- pjmlp 3y agoWhich is why they can keep the OS ABI compatible, while at the same time evolving that struct. By having a size field, the OS can know for which version of the struct the application was compiled for, and what fields it expects to have in that struct.
- formerly_proven 3y agoI don’t think that’s a common complaint in itself. Sure, new people wonder why that sizeof line is needed, but once you learn about ABI compatibility that makes perfect sense. It’s about the other parts.
- _glass 3y agoPeople here complaining about Microsoft. I fully expected SAP. I think every API is reflecting the organization it was developed in. Everything is based on top of something older, bureaucratically refined.
- nimbius 3y ago0. Thanks I hate it 1. You haven't lived until you've tried to extract any reasonable data at all from NOAA.gov.
- deleted 3y ago[deleted]
- woodruffw 3y agoETW is pretty bad but, for Windows APIs, it feels pretty middle-of-the-pack to me. OpenSSL, on the other hand, is an endless nightmare to work with: clusters of APIs that are behaviorally similar (retrieving the attributes within an X.509 certificate, for example) have wildly different function signatures. Even when function signatures for similar APIs resemble each other, their interior behaviors vary widely (around assuming that lengths include NULs, maintaining or not maintaining interior reference counts, etc.). Seemingly basic functionalities ("turn a buffer of PEM-encoded certificates into a `STACK_OF(X509)`") have no APIs at all; other APIs solve simple tasks through obscenely overpowered (and dangerous) primitives (such as `X509V3_EXT_conf`). And so on.
- sph 3y agoI'm building an app that uses the Web Crypto API and the annoying thing about cryptography is that in practice you're calling a ton of different algorithms with slightly varied argument, which of course you have to name, and makes code reuse practically impossible. You can have an `encrypt` function, that takes an RSA key, but wait, if you're encrypting with AES-GCM you also need a salt and an IV, that other times is called a nonce (which is similar to an IV but not exactly). But wait, if you're encrypting a key, you're actually "wrapping" a key, so your API should clarify all these little variations in process, which is a pain. Given that the error conditions are very opaque, to avoid mistakes you need a very clear and verbose API on top of the bare crypto functions to stay sane. Literally my morning plan for today is refactor the cryptography functions in my project because they're an unwieldy mess.
- adammarples 3y agoWould be pretty cool to use multiple dispatch, a la Julia. The encryption function knows which one you're using based on the types you pass as arguments.
- dan-robertson 3y agoI would not find that cool. I think for a typical crypto use case: (A) you want to use exactly one encryption method (eg no algorithm negotiation) (B) you want to be very careful about calling the right functions with the right arguments Relying on compiler magic doesn’t sound good for that to me. Though the grandparent comment does seem to go against (A) so maybe the situation is different.
- malkia 3y agoOMG, Just use https://github.com/microsoft/krabsetw https://github.com/microsoft/krabsetw and be done with it...
- db48x 3y agoThat package dates from 2016, and this article was written in 2014. In those ancient days, you had no choice except to use the ETW api directly. Worse, the existence of a nice wrapper that smooths out the API doesn’t actually make the API itself any better. The existence of the wrapper is itself rather damning.
- thyrox 3y ago> Whenever you evaluate an API, or create a new one, you must always, always, ALWAYS start by writing some code as if you were a user trying to do the thing that the API is supposed to do. This is the only way to get a nice, clean perspective on how the API would work if it had no constraints on it whatsoever. If it was “magical”, as it were. And then, once you have that, you can move forward and start thinking about the practical problems, and what the best way is for you to get to something implementable. Such good advice. It's so obvious but so easy to miss when you're excited to get things done. I think it's like writing a unit test before writing the code. It changes your POV from an "API creator" to an "API consumer" - for whom this whole thing will be all about eventually.
- smarkov 3y agoI'd go a step further and say this is how you should write all of your code because realistically every single function/class is its own little API.
- imiric 3y agoMaybe we should invent a paradigm and write a manifesto about it. We can call it... test-driven development.
- TylerE 3y agoI find TDD antethetical to this... you really need to actually understand the problem space - that requires large scale experimentation, not the micro-structuring TDD preaches.
- MoreQARespect 3y agoUnit test driven development is antithetical to this. Integration test driven development is very amenable though. The problem isn't so much TDD as the cloud of dogma surrounding unit tests from people like Uncle Bob.
- lelanthran 3y ago
- wredue 3y agoI had to build and edit spreadsheets with the OpenXML SDK. I have absolutely zero clue what the hell microsoft was thinking with this. Most of the use cases don’t give two rats shits about the different “parts”, but the api forces you to manually create them anyway. Why? Presumably so you know the parts exist? Never mind that some, but not all (of course) formatting parts of the api require undocumented magic values in magic slots. I don’t know if it’s as bad as this event tracing, but I do know that OpenXML is by far the worst api I’ve ever personally been abused by.
- toyg 3y agoOpenXML in MS products was a "tickbox feature" to fight the spread of OpenOffice formats. They didn't expect people to use it for real; in fact they'd probably prefer that you didn't.
- rootw0rm 3y agoCame here expecting Windows, found Windows. I think I nominate WMI though
- masfuerte 3y agoYes. I've used both and WMI is worse than ETW. The article about ETW made me laugh. Your comment reminding me of WMI made me feel slightly ill.
- j16sdiz 3y agoETW is not easy because they get literally into the most performance sensitive codepath. I think I can forgive any usibility quirk for performance reason.
- beachy 3y agoYeah, gloves are off for something so performance sensitive, and that also has to be backwards compatible with eons of older Windows versions. Who cares if it's not more intuitive. That said, certainly there should be some decent documentation with working examples. I assume there are not hence the author's arduous trip down shonky lane.
- dang 3y agoRelated: The Worst API Ever Made (2014) - https://news.ycombinator.com/item?id=23496194 https://news.ycombinator.com/item?id=23496194 - June 2020 (9 comments) Event Tracing for Windows: The Worst API Ever Made (2014) - https://news.ycombinator.com/item?id=17273000 https://news.ycombinator.com/item?id=17273000 - June 2018 (1 comment) The Worst API Ever Made? - https://news.ycombinator.com/item?id=8146124 https://news.ycombinator.com/item?id=8146124 - Aug 2014 (80 comments)
- zogrodea 3y agoThank you for always bringing previous discussions up. It's nice to get a broader view of what people think, especially when there's little activity in the current thread (which isn't the case here but sometimes is).
- RantyDave 3y agoOriginal QuickTime. We're talking PTSD, here.
- aledalgrande 3y ago> CSS, for example, can probably claim half the spots on the top 10 for any year in which there’s a new version. Yes. But also, try dealing with any Meta API. Godspeed
- gordian-not 3y agothis is the lecture about api design he referred to https://m.youtube.com/watch?v=ZQ5_u8Lgvyk https://m.youtube.com/watch?v=ZQ5_u8Lgvyk if anyone else was looking
- Sparkyte 3y agoChallenge accepted.
- ComodoHacker 3y ago> If you simply want to receive a list of the context switches, even if only for your process, it must be running with full administrator privileges That's actually a reasonable security requirement, greatly narrowing attack surface. Note that ETW API was designed before CPU timing side channels like Spectre were a thing.
- sharts 3y agoThat just shows that the vast amount of developers are morons that have an inability to empathize. Doubly so at larger companies.
- unnouinceput 3y agoQuote: "Variety is the spice of life, I am told. Microsoft wants your life to be spicy." I'm stealing this, this is gold.
- noen 3y agoAbout 7 years ago I was in a meeting with a former Windows core graphics engineer. My team was attempting to figure out some extremely obtuse workflows with MediaFountain and DirectX. We had a meeting with this guy and a couple of the other engineers that wrote the APIs and the implementation underneath. This particular guy literally chuckled as we aired our frustrations and this was his response: “Yeah you won’t figure those APIs out from the documentation. It was on purpose. You have to go buy the book.” Proceeded to explain to me that this was how he, and many other core Windows engineers lined their pockets for years - write complex implementations, do the absolute bare minimum documentation, then take a 6 month sabbatical and publish a reference book that was absolutely required to actually use the API. Apparently many of these guys made 10-20x their salaries on this grift and it didn’t really stop until the mid 2000’s.
- fouc 3y agoThat's a rather profitable twist on the classic "job security" strategy.
- golergka 3y agoWhy wouldn't Microsoft sue them for this?
- robertlagrant 3y agoCan they? On what grounds?
- golergka 3y agoThat's a direct action against the interest of their employer, and an attempt to enrich themselves at the benefit of Microsoft. They are purposefully writing bad software which drives ME market share and reputation among developers down only to sell some books.
- Sharlin 3y agoExcept if MS gets a share of the profits… which it did in many cases, being the publisher. They had no competitors, there weren't any concerns about market share or reputation!
- Marazan 3y agoThere was an old java image manipulation API that I remember that had an API that looked like apply(Object o1) apply(Object o1, Object o2) apply(Object o1, Object o2, Object o3) Etc All the way out to 7 or 8 parameters. Magnificent work.
- ptx 3y agoJava didn't support varargs until version 5, so it might have been a workaround for that particular deficiency.
- ghosty141 3y agoReminds me of this "gem" in C#: https://learn.microsoft.com/en-us/dotnet/api/system.func-2?view=net-7.0 https://learn.microsoft.com/en-us/dotnet/api/system.func-2?v... You better not have more than 16 parameters with Func (which is kind of a good thing? Functions who take 16 parameters are pure evil).
- PaulHoule 3y agoIt is also a little faster to have a fixed number of parameters than to use varargs so it is not unusual for many libraries to have X(a) X(a, b) X(a, b, c) ... X(a, b, c, ..., ...rest) functions.
- Marazan 3y agoGood guess but it wasn't varargs, those were default value overrides IIRC. Thing that was objectionable it was that each an every argument was Object type. Absolutely no affordable whatsoever
- rjh29 3y agoStill exists in Rust, e.g. https://doc.rust-lang.org/std/primitive.tuple.html#impl-From%3C(T,+T)%3E-for-%5BT;+2%5D https://doc.rust-lang.org/std/primitive.tuple.html#impl-From... or https://docs.rs/itertools/latest/itertools/structs/struct.Tuples.html#impl-MultiUnzip%3C()%3E-for-Tuples%3CI,+T%3E https://docs.rs/itertools/latest/itertools/structs/struct.Tu...
- efitz 3y ago> Whenever you evaluate an API, or create a new one, you must always, always, ALWAYS start by writing some code as if you were a user trying to do the thing that the API is supposed to do. I’ve been telling this to the developers I have worked with for the last 15 years. Similar to Amazon’s “working backwards” concept, the only way you can reliably get a good API is to engineer it from the customer’s point of view. That means write the code that you want your customers to write (or that you would want to write, if you were the customer) and then engineer backwards from that. One of the biggest problems with API design is that often the developers of the API have a vastly different mental model of the functionality that they’re encapsulating in an API, than their customers. Often, customers can’t even develop that mental model because the encapsulated code is a black box. Another common API design problem is that you’ll just write a simple CRUD API around your object model. This often causes customers to have a bad experience if they use objects in conjunction with each other, and have to do a lot of housekeeping to associate objects with each other and keep track of multiple objects to perform simple tasks. My example here is AWS Route 53; the API is a real pain to use if you just want to do something simple.
- darkerside 3y agoI agree with you, but I will say, worse than no abstraction is a poor one. Give me CRUD any day over something that doesn't expose things I need or makes me jump through too many hoops to get something simple done. At least then I can build what I need.
- ryukoposting 3y agoThanks for the chuckle. Last week I tried using the Win32 APIs to make a little ssh/sftp file browser, gave up, and started rewriting all my work in Rust. A half-baked fledgling Rust GUI library with a short gitbook's worth of documentation is more usable than the API Microsoft has been shipping for... decades?
- forrestthewoods 3y ago> is more usable than the API Microsoft has been shipping for... decades? Those things are directly related. The Win32 API is the result of decades of accumulated cruft. Mistakes made 20 years ago must be supported forever. Rust APIs are the result of learning from those decades of experience and doing to better.
- ryukoposting 3y agoIt's amazing what can be done when there's basically no technical debt to grapple with (the Rust GUI library I'm using is called dioxus, by the way, and it's brilliant). At the same time, I'm often perplexed by the nonsense that gets pushed as "modern software design."
- _gabe_ 3y agoWin32 definitely has some stinkers. But, video encoding APIs definitely take the cake for me. I've only tried a couple of FFmpeg's APIs and AV1's API, but my God, these are the worst API's I've ever had to deal with. Just as an example, all I wanted was an API like this[0] for FFmpeg. In order to implement that API (which in my opinion is reasonable), I had to write this monstrosity[1]. It took me a solid week to find an example of how to do this, then another few days of fiddling until I finally just barely got something working. Then I threw in the towel even though the performance was horrible. I tried again a year later and spent another month wrestling with AV1 :/ The amount of leakage going on in these APIs is absolutely insane. I shouldn't have to know the intimate details of how video encoding works to use your library. If I do, then I may as well write my own encoder at that point. [0]: https://github.com/ambrosiogabe/MathAnimation/blob/18c004bca0167dd18c027139897635de0030be7f/Animations/include/renderer/VideoWriter.h#L5 https://github.com/ambrosiogabe/MathAnimation/blob/18c004bca... [1]: https://github.com/ambrosiogabe/MathAnimation/blob/18c004bca0167dd18c027139897635de0030be7f/Animations/src/renderer/VideoWriter.cpp https://github.com/ambrosiogabe/MathAnimation/blob/18c004bca...
- bob1029 3y ago> If I do, then I may as well write my own encoder at that point. I've actually done this with jpeg & mpeg1. I spent maybe a hundred hours trying to get existing libraries to play by my rules. When you completely own the implementation everything gets out of the way. I don't like that I had to do this, but it was the only way to wrap my head around the problem and bend it to my will.
- coldpie 3y agoHaha, yeah. In ffmpeg's sort-of defense, the libav* APIs are supposed to be semi-private, which is how they try to get away with them being terrible & unstable. But in practice they're public, and everyone uses them, because the only alternative is gstreamer and oh boy do you ever not want to dive into that mess. FWIW if you just want to en/decode AV1 and don't care about anything else like container formats, you can just use the codec directly. Dav1d is the current gold standard, I believe. Even some container APIs aren't too hard to deal with, if you do need that.
- 3y ago
- JohnCClarke 3y agoDealing with the EventLog API was when I realized how awesome Golang is. As a new golang developer it took minutes to hack the Elastic Beats code to develop a PoC. That's when it ocurred to me that if it were written in C I'd still be fighting with header files for days...
- hardware2win 3y agoThis is why tdd is accidentally successful Cuz it forces to start with api design
- bwb 3y agoWhen I read the title I thought OMG, someone else is trying to use Ingram's book API :)
- dirtybirdnj 3y agoThe worst API I ever interacted with was the RingCentral Fax API circa mid 2000s It was just a URL, you could POST a document at it and it would respond with 1 or 0 There was no debug information, no status indicators. Just 1 or 0 In retrospect maybe it wasn't the worst, at the time I was used to status messages and more rich APIs. It actually did function, and it did what it was supposed to so maybe I should take back my comment. Worst status messages maybe? Things like this matter and can't just be an afterthought.
- AtNightWeCode 3y agoMicrosoft have created more bad API:s. Open XML Graph API Large parts of the C# Azure SDKs MFC - perhaps not bad just very difficult
- c-linkage 3y agoAs Raymond Chen would say, this API was designed with "kernel-colored glasses". The StartTrace() is designed to notify the kernel that it should hook different locations to begin recording events. Since all kernel objects have to be installed in the namespace (just like creating a file in Linux for your terminal or in plan9 for network sockets) you must specify a name; tracing cannot be anonymous. As with processes having the CreateProcess() and OpenProcessHandle() function pair, there is -- consistently -- a StartTrace() and OpenTrace() function pair. The OpenTrace() takes a name so it can look up the trace in the namespace. StartTrace() could -- and should have the ability to -- fail. Kernel tracing is a privileged function, which is why it requires Admin privileges to start. By having OpenTrace() separate from StartTrace() you can have the StartTrace() function called from a Windows Service running with elevated privileges on behalf of a user-mode process, and then the user-mode process can call OpenTrace() and still be able to read the events. In fact, if the user-mode process knows that a trace is already running it doesn't even need to call StartTrace(). This applies to non-kernel traces as well as kernel traces (remember -- the name of the trace can be looked up in the namespace). Requiring a callback -- from a kernel perspective -- also makes sense. Imagine what would happen if the user-mode process was responsible for reading events. The kernel is busy pumping events out into the buffer and, just then, the user-mode program gets hung waiting for network I/O. What happens? If the buffer never drains, maybe the kernel gets hung waiting for space (system deadlock). Or maybe the processes "misses" events, and the developer thinks the API is broken. Or better yet, what happens when multiple processes A and B are reading from the buffer and one of them (process A) pauses for a GC? Does this mean that process B gets blocked waiting for A to read events? Or does the process B "lose" events because A doesn't consume them? The intent for having a callback on a dedicated read-thread is supposed to be like the OS handling a processor interrupt: do the minimum amount of work to record the interrupt details and then return to the kernel. In this case, the callback should copy the data into a process-specific buffer and notify a different thread that data is reading (classic producer-consumer / publish-subscribe behavior). Anything more than that and you threaten the stability of the system. The overall architecture is both a workable design and consistent with all other Windows APIs. The problem is that the API is not user-friendly (the packed structure is required so that all required data can be passed to the kernel, and the kernel does not need to reference user-mode memory -- but still, packed structures are no fun!) and there are too many fields in the ETW structures such that users will be easily confused. Fortunately, however, most of the fields are zero.
- sitzkrieg 3y agoi think the credential provider and LSA interfaces of windows internals (3+ string types why not) are a lot more gnarly than etw because of several opaque datatypes and generic handlers etc
- therein 3y agoThis was a great read, I really enjoyed it. And I tried to use the ETW API in the past and had a similar kind of wtf, I am not touching this feeling and decided to just not profile what I was profiling. At that time no MSDN documentation made sense and there weren't any blog posts explaining the proper usage. I suspect this post has just become the definitive documentation for ETW.
- Krzyckumw 3y agoThis goes back to the millennials with the .com bubble